jasonkuhrt / graphql-request

Minimal GraphQL client
MIT License
5.74k stars 307 forks source link

Extend graphql return mode to include the response when transport is http #921

Open jasonkuhrt opened 3 weeks ago

jasonkuhrt commented 3 weeks ago

Perceived Problem

Ideas / Proposed Solution(s)

This is the current Graffle return mode system:

Mode Throw Sources (no type safety) Returns (type safe)
graphql Extensions, Fetch GraphQLExecutionResult
graphqlSuccess Extensions, Fetch, GraphQLExecutionResult.errors GraphQLExecutionResult with .errors always missing.
data (default) Extensions, Fetch, GraphQLExecutionResult.errors GraphQLExecutionResult.data
dataSuccess Extensions, Fetch, GraphQLExecutionResult.errors, GraphQLExecutionResult.data Schema Errors GraphQLExecutionResult.data without any schema errors
dataAndErrors GraphQLExecutionResult.data, errors from: Extensions, Fetch, GraphQLExecutionResult.errors

I think it's fair to start with permitting response access in the low level escape hatch mode of graphql and graphqlSuccess. We can make the presence of response type safe based on client config (the transport).

We would be extending the native GraphQLExectionResult type so wherever that type is expected in the ecosystem the results of a raw Graffle request would still conform to the interface, the extra response field just being ignored.

I don't think the extensions field is the right place for this but I should double check actually, because I'm realizing now I'm not sure what the extensions field was really for.