genql icon indicating copy to clipboard operation
genql copied to clipboard

Support for TypedDocumentNode

Open homoky opened this issue 1 year ago • 5 comments

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.

homoky avatar May 14 '24 13:05 homoky

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

remorses avatar May 14 '24 13:05 remorses

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.
})
 

homoky avatar May 20 '24 07:05 homoky

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

lukepolo avatar Aug 12 '24 15:08 lukepolo

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.

homoky avatar Aug 12 '24 15:08 homoky

Has anybody found another alternative that supports TypedDocumentNode?

homoky avatar Feb 13 '25 15:02 homoky