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

Provide access to field variables through Error object

Open LastDragon-ru opened this issue 4 years ago • 3 comments

In our logs I see few:

Cannot return null for non-nullable field "MyType.property".

Probably some data are invalid in the database and I need to fix it (or maybe allow nulls). But the problem is: this error is totally useless and there is no way to reproduce it because GraphQL\Error\Error doesn't have any information about variables that were passed from the js client :(

Would be good if Error will also store variables.

LastDragon-ru avatar Oct 22 '21 14:10 LastDragon-ru

What exactly would you expect? Should the message change in some way?

spawnia avatar Oct 22 '21 14:10 spawnia

@spawnia not message (it is ok), just some way to get variables from GraphQL\Error\Error, eg $error->getSource()->variables.

LastDragon-ru avatar Oct 22 '21 14:10 LastDragon-ru

GraphQL\Type\Definition\ResolveInfo might be a suitable inclusion, it holds a lot of information about the execution state at the time the error was thrown. It would have to be optional, since a GraphQL\Error\Error can also be thrown outside of query execution.

spawnia avatar Oct 22 '21 15:10 spawnia

We have solved debugging issues like this through the use of Sentry. I recommend generally improving the logging and traceability of what happens in your application.

spawnia avatar Oct 15 '22 12:10 spawnia