Search code examples
vue.jsgraphqlapollovue-apollo

How to make a graphql mutation without parameters? (Vue Apollo)


I have a vue app where I am toggling the width of a sidebar menu. My plan is to have a UI object in a local apollo cache where i can keep track of various UI states (ex. sidebar open vs. closed). I have a query to check the state of the sidebar and a mutation to update it. But for some reason the mutation seems to require that i give it parameters ($id: ID), even though I'm not actually passing anything to the mutation when I use it. How should i write the mutation when i'm not using any parameters? Or is a parameter required? Attempts at removing parameters and corresponding error messages below.

Code:

Removing parameters from both like so (Attempt #1):

enter image description here

Results in:

Error Message:

Removing parenthesis like so (Attempt #2):

enter image description here

Results in:

enter image description here


Solution

  • When querying a field without any arguments, you should omit parentheses. In other words, you would just do

    toggleSidebar
    

    instead of

    toggleSidebar()
    

    The latter is not valid syntax in GraphQL.