apolloClient.mutate variables not working
See original GitHub issueIntended outcome: Variable merged into the mutation
Actual outcome: Status: 400 error with variable, and the mutation works when hard-coding the value in the mutation:
sendMsgNotWork() {
apolloClient.mutate({
variables: { text: "hello" },
mutation: gql`
mutation {
addComment(text: $text) {
id
text
}
}
`,
})
.then(result => { console.log(result) })
.catch(error => { console.log(error) });
},
sendMsgWorks() {
apolloClient.mutate({
variables: { text: "hello" },
mutation: gql`
mutation {
addComment(text: "Hello") {
id
text
}
}
`,
})
.then(result => { console.log(result) })
.catch(error => { console.log(error) });
}
How to reproduce the issue: https://github.com/jarnojellesma/graphql-experiment
Version
- apollo-client@2.0.4
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Mutations in Apollo Client - Apollo GraphQL Docs
Here, we use the variables option to provide the values of any GraphQL variables that our mutation requires (specifically, the type of the...
Read more >Passing a variable to GraphQL mutation using ApolloClient ...
I'm trying to figure out how to run mutations using Apollo Client. Here's the mutation I'm trying to run: export const CREATE_POST =...
Read more >GraphQL Mutations and Caching using Apollo Client
This mutation adds new fields, and the simple caching approach will not work to update the cache. const CREATE_SESSION = gql`
Read more >Mutations – Angular - GraphQL Code Generator
The mutation name with arguments ( submitRepository ), which represents the ... variables: { repoFullName: 'apollographql/apollo-client' } ...
Read more >Apollo client.mutate for GraphQL mutation update - Hasura
+ variables: {id: todo.id, isCompleted: !todo.is_completed},. + optimisticResponse: ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I tried your example project, this seems to work fine:
@jarnojellesma Any insight on the cause of this? Seems to be happening to me right now 😦