Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for TypedDocumentNode #174

Open
homoky opened this issue May 14, 2024 · 5 comments
Open

Support for TypedDocumentNode #174

homoky opened this issue May 14, 2024 · 5 comments

Comments

@homoky
Copy link

homoky commented May 14, 2024

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.

Copy link

linear bot commented May 14, 2024

@remorses
Copy link
Owner

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

@homoky
Copy link
Author

homoky commented May 20, 2024

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

@lukepolo
Copy link

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

@homoky
Copy link
Author

homoky commented Aug 12, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants