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

Semantic nullability document directive #4271

Open
wants to merge 31 commits into
base: 16.x.x
Choose a base branch
from

Conversation

twof
Copy link
Contributor

@twof twof commented Oct 30, 2024

No description provided.

Comment on lines 1368 to 1369
let executable = document.definitions?.values().next().value as ExecutableDefinitionNode;
let selectionSet = executable.selectionSet.selections.values().next().value;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are just tests so it's not the biggest deal, but is there a better way to retrieve the node for use in error construction? This is workable, but unwieldy.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we do not yet enable noUncheckedIndexAccess (see #3867) I think you could just index it via 0 at this point although I think what you are doing is preferred, for example

const [responseName, fieldNodes] = [...rootFields.entries()][0];

Has been changed in main to your method.

You could assert that you have an executable definition or selection node instead of using typescript casting….

In fact, I think that needs to be improved in main for the example I gave!

const firstRootField = groupedFieldSet.entries().next().value as [

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export function isExecutableDefinitionNode(

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Paid greater attention when working on twof#5 and I think the answer is that generally the tests use expectJSON and some other testing deduplication, added second commit there demonstrating use.

@twof twof marked this pull request as ready for review November 8, 2024 06:42
@twof twof requested a review from a team as a code owner November 8, 2024 06:42
@twof
Copy link
Contributor Author

twof commented Nov 8, 2024

Notes for reviewers

I'm looking for review on everything but utilities. I'm going to let @benjie handle those. Once I've been given a go ahead on the implementation, I'll write the spec edits.

There are a large number of files failing linting. Let me know if there's anything I need to do to fix that.

Coverage is passing on my machine. Unclear why it's not passing CI. It also seems to be treating one of my new test files as uncovered code.

@yaacovCR
Copy link
Contributor

yaacovCR commented Nov 8, 2024

Is there a reason for the introduction of two new wrapping types as opposed to a single one? Is it because of an unresolved syntax question or is it expected to remain in the final implementation?

I could see this being useful if we were to actually allow multiple coexisting syntax variants as dictated by arguments on the semantic nullability directive (but I am not in favor of that additional complexity).

@twof
Copy link
Contributor Author

twof commented Nov 8, 2024

Is there a reason for the introduction of two new wrapping types as opposed to a single one? Is it because of an unresolved syntax question or is it expected to remain in the final implementation?

I could see this being useful if we were to actually allow multiple coexisting syntax variants as dictated by arguments on the semantic nullability directive (but I am not in favor of that additional complexity).

In the first commit with the parsing implementation I had a single type.

The printer was the main driver here. In the parser there was a clear place to set the useSemanticNullability mode flag, but with the printer it wasn't so obvious.

@@ -740,6 +754,7 @@ export class Parser {
* - NamedType
* - ListType
* - NonNullType
* - SemanticNonNullType
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* - SemanticNonNullType
* - SemanticNonNullType
* - SemanticNullableType

@yaacovCR
Copy link
Contributor

The printer was the main driver here. In the parser there was a clear place to set the useSemanticNullability mode flag, but with the printer it wasn't so obvious.

I raised twof#5 as a proof-of-concept for what it might look like with a single new wrapper type.

I stored within the created GraphQLSchema whether it was created usingSemanticNullability and built printing and execution related changed off of that flag.

You can add in semantically nullable types even in a schema that is not using usingSemanticNullability and they will be ignored. In particular, to remain with simply one version of the Introspection types, I modified the built-in Introspection types where I thought to be appropriate to use the new GraphQLSemanticNullable wrapping types; these types are unwrapped but otherwise ignored even when usingSemanticNullability is not set.

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

Successfully merging this pull request may close these issues.

4 participants