You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description
The InputMapDefinesTooManyFieldsException returns null as locations, but the GraphqlErrorBuilder throws an exception for null as locations.
This seems inconsistent. Though it may not lead to direct conflicts in this project, it is confusing for using projects. For instance, the default error handling of graphql-spring-boot in consequence does not properly handle the InputMapDefinesTooManyFieldsException, see GraphQLErrorFromExceptionHandler#withThrowable.
Possible Solutions
I see three obvious directions:
Commit to non-null locations on GraphQLError.
Handle null as locations in the GraphqlErrorBuilder.
Keep the inconsistency and document it better, so that using frameworks or projects do not rely on false assumptions.
Open Question
Either solution would be fine for me and I may propose a pull request for it. The order above is just my personal preference. Which way to proceed?
This is a great point you have brought up. Some of the GraphQLError instances will always have n on null locations and some do not.
The error builder in question was trying to have a code design that is "if you call this method then you MUST provide a value" and if you dont want a value then dont call this method.
However this puts a lot of assumed knowledge on the caller - for example if the caller is "cloning / copying" an object then they probably just throw N attributes at the build and assume they get a very similar object with the same values, yet it requires you to KNOW not to call some method in a null attribute sense.
I think in this case, I know not all GraphqlError instances have locations we should allow a null input and set it to null if specified.
Activity
[-]GraphqlErrorBuilder poses high non-null requirements[/-][+]Inconsisten null requirement for locations[/+]bbakerman commentedon Jan 3, 2022
This is a great point you have brought up. Some of the
GraphQLErrorinstances will always have n on null locations and some do not.The error builder in question was trying to have a code design that is "if you call this method then you MUST provide a value" and if you dont want a value then dont call this method.
However this puts a lot of assumed knowledge on the caller - for example if the caller is "cloning / copying" an object then they probably just throw N attributes at the build and assume they get a very similar object with the same values, yet it requires you to KNOW not to call some method in a null attribute sense.
I think in this case, I know not all GraphqlError instances have locations we should allow a null input and set it to null if specified.