Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test all functions (with AST input) that they handle undefined instead of array properites #2203

Closed
IvanGoncharov opened this issue Sep 26, 2019 · 1 comment

Comments

@IvanGoncharov
Copy link
Member

Based on @mjmahone comment #2084 (comment)

I know we ran into problems in the past when hand-modeling the AST where, unless you explicitly set directives: [], you'd end up getting an undefined reference, even though the flow type allowed it.

Currently parse always return empty arrays (and never undefined) but AST definitions explicitly support undefined.

This is done to make AST forward-compatible meaning old code that generate/transformate AST and doesn't know about new properties (e.g. interfaces on InterfaceTypeDefinitionNode node) is still compatible with newer versions of graphql-js.

It also means it's very easy to manually create nodes, for example creating FieldNode you can safely omit arguments, directives and selectionSet properties so minimal field will look like:

{
  kind: 'Field', 
  name: { kind: 'Name', value: 'foo' },
}

At the same time we need to be sure that functions like buildSchema, extendSchema, print, execute, etc. are actually ready to handle such functions and don't crash when they get undefined instead of an empty array.

IvanGoncharov added a commit to IvanGoncharov/graphql-js that referenced this issue Jan 4, 2020
IvanGoncharov added a commit to IvanGoncharov/graphql-js that referenced this issue Jan 4, 2020
yaacovCR added a commit that referenced this issue Oct 14, 2024
see:
#2405 (comment)

Manually created ASTs always allowed undefined in place of empty arrays;
this change simply updates the parser to more closely follow the manual
approach. This is therefore not technically a breaking change, but
considering that there may be tools not aware of this, we have labelled
it a BREAKING_CHANGE to highlight it for consumers.

This closes #2203 as our tests now cover the undefined case by default
whenever there is an empty array.
@yaacovCR
Copy link
Contributor

Closed by #4206

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants