dotansimha / dotansimha/graphql-code-generator-community
Angular apollo @client @export local state with variable used in mutation
- Dominant language
- TypeScript
- Stars
- 137
- Forks
- 195
- Avg merge
- 6h 20m
- Merged PRs (30d)
- 16
Description
Using:
"@graphql-codegen/typescript": "^2.2.4",
"@graphql-codegen/typescript-apollo-angular": "^3.2.2",
"@graphql-codegen/typescript-operations": "^2.1.8",
"@graphql-codegen/typescript-resolvers": "^2.3.2"
I am using the angular apollo plugin make calls to a graphql backend.
I use local state variables extensively, and want to make a mutation where I first query a local variable and then use that variable in the mutation itself:
```
mutation someMutation($someLocalVariable) {
getLocalVariable @client {
id @client @export (as: "someLocalVariable")
}
someMutation(input: $someLocalVariable}) {
somefield {
...somefragment
}
}
}
```
This works perfectly fine If i write the angular service myself.
However when I run this through codegen with an expectation to generate the angular service, I get:
**GraphQLDocumentError: Cannot query field "getLocalVariable " on type "Mutation".**
It appears that while GQL and apollo is fine with pulling a local state variable using @client @export and using those fields IN the mutation even though those fields themselves aren't mutations works fine.
But CodeGen expects that everything inside mutations, be a literal mutation, and doesnt make an exception for client local state variables.
I can hack around it by creating a mutation that doesn't mutate anything and just returns the local state variable, and then codegen doesn't complain, but I'm wondering am I going about this wrong.
Is there another way to, in GQL, query a local state variable, and then use it in a mutation, but do the whole thing in GQL as opposed to application-level.
```
mutation someMutation($someLocalVariable) {
**fakemutation**@client {
id @client @export (as: "someLocalVariable")
}
someMutation(input: $someLocalVariable}) {
somefield {
...somefragment
}
}
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.