Support for TypedDocumentNode
I really love the API (how the genql is used). It would be great if:
- generateQueryOp
- generateMutationOp
- generatSubscriptionOp
would support TypedDocumentNode so it would be possible to use with any React client.
generateQueryOp returns a string and an object with the variables, you can already use it with any React client. I have no idea what TypedDocumentNode is but you can probably parse a string and return that
TypedDocumentNode - https://the-guild.dev/graphql/codegen/plugins/typescript/typed-document-node
It is really great thing, beacuse you can use it in basically any client out there like urql, react, etc - this is the part of the types, it cannot be just string.
And secondly, generateMutationOp, does require you to include variables straight away, but that is not how it is used in react clients, you know what variables are once you are calling it, not when you make definition - something like this:
const [createAccountMutation, createAccount] = useMutation(MUTATION_DEFINITION) // genql requires me here to define variables with generateMutationOp
useEffect(()=> {
createAccount({name:"Super!"}) // We need to be able to set them here.
})
yah following @homoky here , im using with vue though and typically you would use it with a named parameter
query matches($id:uuid!) {
matches_by_pk(id: $id) {
id
}
}
in code it would look like
apollo: {
$subscribe: {
matches_by_pk: {
variables: function () {
return {
$matchId: this.$route.params.id
}
},
query: generateSubscription({
matches_by_pk: {
__args: {
id: '$matchId'
},
id: true,
}
}),
result: function ({ data }) {
this.match = data.matches_by_pk;
},
},
},
},
Im looking to create the typed-document-node since the types should be enough to allow for it
I spend another few days checking the alternatives, closest is the typed-graphql-builder that is working as expected with clients like urql or graphql-request, but the syntax is not readable at all in more complex queries.
This requested change would make genql usable literaly everywhere, with any graphql client but still 100 % typed.
Has anybody found another alternative that supports TypedDocumentNode?