machinebox / graphql

Simple low-level GraphQL HTTP client for Go
https://blog.machinebox.io/a-graphql-client-library-for-go-5bffd0455878
Apache License 2.0
937 stars 218 forks source link

Update client to pass response along rather than pulling out errors #20

Open erutherford opened 6 years ago

erutherford commented 6 years ago

With graphQL it's possible the response could be partially successful. With the way the client is currently configured, it's parsing the errors property and returning an error with the first error in the array if it's not empty.

Would you be open to a PR that instead passes the entire response? This would allow the caller to decide how it wants to handle the returned errors. We're also currently losing additional error context if more than one error is present.

matryer commented 6 years ago

This seems fair enough.

I think the default behaviour should be to pull out the first error as it does today (it's simpler and what most people need), but I'm not against adding the complete response as an option.

I think the API should be something like this:

err := client.Run(ctx, req, &resp)
if err != nil {
  resp, ok := graphql.Response(err)
  if ok {
    // TODO: use the complete resp here
  }
}
fubarhouse commented 5 years ago

What's the status of this one?