graphql-go icon indicating copy to clipboard operation
graphql-go copied to clipboard

Whole object is null, when error returned with some value

Open 0xTanvir opened this issue 5 years ago • 5 comments

I was trying to return a type/object with error, so that I can debug my error from front-end, but it seems when I return any value into error then the whole object always return as null :( but if I return error as nil then it return object's value.

problem

0xTanvir avatar Oct 18 '18 15:10 0xTanvir

Same problem by me

baba2k avatar Oct 19 '18 15:10 baba2k

https://github.com/graph-gophers/graphql-go/blob/995849d5bff2932ba449bea0c7cf0638d7f69f70/internal/exec/exec.go#L209

In fact, this is a tricky problem that is difficult to solve according to the current code implementation.

sanae10001 avatar Nov 12 '18 04:11 sanae10001

this is part of the GraphQL spec:

https://facebook.github.io/graphql/June2018/#sec-Data

If an error was encountered during the execution that prevented a valid response, the data entry in the response should be null.

stefanvanburen avatar Nov 13 '18 21:11 stefanvanburen

@svanburen agree on resolving 1 instance, but this also occurs on returning a list and there I'm not sure if it should...

When you have a list of 10 items and 9 resolve correctly, and the tenth throws an error. Should you still be forced to give a null back while the 9 sub resolvers did produce a valid response?

VincentVW avatar May 28 '19 22:05 VincentVW

@VincentVW https://graphql.github.io/graphql-spec/June2018/#example-90475 - I'd agree that you shouldn't be forced to give null back in that situation.

stefanvanburen avatar May 29 '19 14:05 stefanvanburen

I'm closing this issue as this is part of the spec requirements. @VincentVW if you think that the lib is violating the spec for lists I'd be happy to reopen the issue. A failing test would be more than appreciated.

pavelnikolov avatar Nov 29 '23 20:11 pavelnikolov