0no-co / gql.tada

🪄 Magical GraphQL query engine for TypeScript
https://gql-tada.0no.co
MIT License
2.44k stars 34 forks source link

passthrough query input string #291

Closed wyattades closed 1 month ago

wyattades commented 1 month ago

Summary

We'd like to send the query string directly to our backend, not the "parsed graphql definition" (not sure the terminology). We have a hacky patch workaround for this, but it seems like something appropriate for other users of this lib as well.

example:

const query = graphql(`
  query MyThing {
    id
  }
`);

const res = await requestDataFromBackend(query.input);

Question: i'm not currenctly using fragments, but it probably also makes sense to passhrough them as well?

Set of changes

changeset-bot[bot] commented 1 month ago

🦋 Changeset detected

Latest commit: a4f513163cbe0bb50598cf1de1c002b08e668adc

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

kitten commented 1 month ago

This is pretty non-standard and the canonical way of doing this is to simply print the query. Can you explain why you would need to do this? We really haven't come across this being necessary (and we've basically been working on urql for a while, and it's not really an issue)

Edit: Also, to point out the obvious, if you need anything non-standard or unconventional, it may make more sense for you to extend/wrap the graphql function, i.e. the initGraphQLTada returned function.

Edit 2: To point this out as well, in case you want to implement this in your own repo. input is not equivalent to what must be sent, since it includes none of the fragment definitions. Further, graphql does define the loc property, however, you'd need to merge all of these recursively.

wyattades commented 1 month ago

This is pretty non-standard and the canonical way of doing this is to simply print the query

Sorry I don't understand. Isn't the standard in the graphql world to send the query string to your backend? Also, what does print the query mean?

it may make more sense for you to extend/wrap the graphql function, i.e. the initGraphQLTada returned function.

That's what we're doing now :) but I figure other people are also using gql.tada just for the type inference, and only accept graphql query strings on their backend.

kitten commented 1 month ago

You use print from graphql.js (or @0no-co/graphql.web if you want a smaller alternative that gql.tada/urql are already using) and that gives you the GraphQL document in its printed, stringified form from the AST.

Most GraphQL clients will do this for you out of the box though, of course

wyattades commented 1 month ago

You use print from graphql.js (or @0no-co/graphql.web if you want a smaller alternative that gql.tada/urql are already using) and that gives you the GraphQL document in its printed, stringified form from the AST.

Most GraphQL clients will do this for you out of the box though, of course

I see your point, it would be more correct to stringify the AST. I'll close this PR