0

I have mutation which works on graphiQL:

mutation ADDRELEASE{
  createRelease(release: {
    title: "Release Title"
    releaseType: "Album"

  }) {
    title
    id
  }
} 

I'm tryng to use apollo client with graphql-tag and set mutation variables like this:

 const CREATE_RELEASE = gql`
  mutation($release: {
    $title: String 
    $releaseType: String
  }){
    createRelease(release: {
      title: $title 
      releaseType: $releaseType

    }){
    id
   }
  }
`

I guess it's matter of syntax. Can't figure out how to make it work.

1 Answer 1

1

There's no need to define a variable for both $release and the other two variables if you're only going to use $title and $releaseType. You can do either:

# Replace ReleaseInput with the appropriate type based on the schema
mutation($release: ReleaseInput) {
  createRelease(release: $release) {
    id
  }
}

or...

mutation(
  $title: String 
  $releaseType: String
) {
  createRelease(release: {
    title: $title 
    releaseType: $releaseType
  }) {
    id
  }
}

For what it's worth, you can also test queries with variables in GraphiQL. You can open the variable editor by clicking on QUERY VARIABLES in the bottom left corner of the page.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.