remorses / genql

Type safe TypeScript client for any GraphQL API
https://genql.dev
MIT License
882 stars 37 forks source link

Feature request: response extensions #126

Closed fdiogo closed 11 hours ago

fdiogo commented 1 year ago

The latest spec states that the response might have three fields: data, errors and extensions. Extensions here work in the same way as in errors[number].extensions, it's open for implementers to add whatever they might want.

https://spec.graphql.org/October2021/#sel-DAPHDJAACLAnxP

The response map may also contain an entry with key extensions. This entry, if set, must have a map as its value. This entry is reserved for implementors to extend the protocol however they see fit, and hence there are no additional restrictions on its contents.

Examples of potentially useful extensions at this level would be: correlation_id, status, etc..

We're loving our experience with genql, it's a game changer. We'd love to have this if the team thinks it's a good idea, we might able to open a PR with a working example

remorses commented 1 year ago

I will do more research on this

nullndr commented 1 year ago

Any news on this?

I'm building a large shopify app and I require to handle throttling according to a shopify extension.

Would love to handle this directly on genql.

remorses commented 1 year ago

Adding the extensions field would require a breaking change because Genql currently only returns the data, i will keep in mind for the next breaking release, but for now i have no plans for it

fdiogo commented 1 year ago

@remorses have you considered supporting both paths? To circumvent this we actually created a wrapper around the existing client that overrides the fetcher and returns this instead on query/mutation:

const { data, errors, extensions } = client.query...

Something that's specific to our use case is that errors are also returned as is, instead of thrown. Makes it a bit more ergonomic for us, no type narrowing needed or try/catches.

This change would be additive, and it would be a choice to the consumer to use the raw client or this new theorical wrapper