jeddeloh / rescript-apollo-client

ReScript bindings for the Apollo Client ecosystem
MIT License
126 stars 18 forks source link

Add "extensions" to GraphQLError type #60

Closed kgoggin closed 4 years ago

kgoggin commented 4 years ago

The GraphQL error type allows for an extensions field, which is an arbitrary key/value object. Apollo leverages this to provide an error code: https://www.apollographql.com/docs/apollo-server/data/errors/#codes.

I'm not entirely sure what the correct type should be here. Apollo provides some pre-defined errors in apollo-server, but you can extend the ApolloError class to define other errors specific to your domain (which I've done in the app I'm using this for). One option might be to allow for passing your own GraphQLError and/or extensions type in the config, which you could define to contain the specific errors your app needs to handle? Aside from that, at least providing the extensions field which contains a code field typed as a string would be something.

jeddeloh commented 4 years ago

Yes, it looks like the (TypeScript) type for extensions is readonly extensions: { [key: string]: any } | undefined; I'd probably stick pretty close to this since I can't guarantee what all servers provide. Maybe extensions: option(Js.Dict.t(Js.Json.t))? I'll add this shortly.

Configuration would be really nice, but I went down the functor path and it was not a good tradeoff in my eyes, but I welcome anyone to come in and give it a go. It's made a bit more difficult than it might otherwise be because I mirror the Js package structure for ease of human maintenance/conversion.

kgoggin commented 4 years ago

Awesome, thanks! Yeah, I can see where it'd get difficult to handle the complexity of making that configurable, and I think that type definition you suggested works well.

jeddeloh commented 4 years ago

Fixed in v1.0.0-beta.0