Mutations are not working with Apollo Client : passing variables
See original GitHub issueI am using an Angular Client with angular-apollo https://apollo-angular.com/docs/data/mutations and Mutations are throwing an error even though the variables are passed.
This is with Cosmos DB as storage.
Client Code :
const post_SaveHero = gql`
mutation ($id : String!, $publisher : String!, $superhero :String!, $characters:String!){
addHero(id : $id , publisher : $publisher , superhero : $superhero , characters: $characters )
{
superhero
}
}`;
Invoking it as,
updateHero(hero: Hero){
console.log("$$$HERO",hero.id);
console.log("$$$HERO OBJECT",JSON.stringify(hero));
return this.apollo.mutate({
mutation: post_SaveHero,
variables: {
id: hero.superhero,
publisher: hero.publisher,
superhero: hero.superhero,
characters: hero.characters
}
}
);
}
and the error thrown as,
Issue Analytics
- State:
- Created 2 years ago
- Comments:15 (15 by maintainers)
Top Results From Across the Web
Mutations in Apollo Client
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 >Mutations - Apollo GraphQL Docs
If a mutation modifies multiple entities, or if it creates or deletes entities, the Apollo Client cache is not automatically updated to reflect...
Read more >apolloClient.mutate variables not working · Issue #2762
Intended outcome: Variable merged into the mutation ; Actual outcome: Status: 400 error with variable, and the mutation works when hard-coding ...
Read more >How to use GraphQL mutations in React and Apollo Client
Mutations in GraphQL are responsible for saving the data. Apollo Client offers mechanisms that make working with mutations.
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
@sajeetharan - did this work with #290 merged to
main
?I’ve started digging down a rabbit hole of how we parse the variables and arguments in the runtime and what I’ve found is that we have several methods that do it and not all engines process them in the same way.
So, I went back to the HotChocolate source to see if we’d missed something in the parsing, since it has to handle variables itself, and found that they have a method that will get the arguments with variables - https://github.com/ChilliCream/hotchocolate/blob/main/src/HotChocolate/Core/src/Execution/Internal/ArgumentCoercionHelper.cs#L12
I’m going to have a look at refactoring to use that method, which will mean that we can move away from
IDictionary<string, object?>
for theparameters
in the execution engines and have something that is more strongly typed, and the runtime to do less manual processing of the args/variables/etc., instead, just walk the complete graph when it’s time to execute a request.