-
Notifications
You must be signed in to change notification settings - Fork 1.1k
RFC: Client Controlled Nullability #895
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
Changes from all commits
8a13c8f
c07d86c
ac03e0e
155e09a
e99db4c
1677f62
ce80aa9
4743051
f392add
1473f78
432555d
1954680
3cc7af5
2782099
6e615bc
0fbd456
f9f5e2f
b24ce32
06819e3
3822c97
159d159
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,7 @@ Token :: | |
- FloatValue | ||
- StringValue | ||
|
||
Punctuator :: one of ! $ & ( ) ... : = @ [ ] { | } | ||
Punctuator :: one of ! ? $ & ( ) ... : = @ [ ] { | } | ||
|
||
Name :: | ||
|
||
|
@@ -156,10 +156,22 @@ Selection : | |
- FragmentSpread | ||
- InlineFragment | ||
|
||
Field : Alias? Name Arguments? Directives? SelectionSet? | ||
Field : Alias? Name Arguments? Nullability? Directives? SelectionSet? | ||
|
||
Alias : Name : | ||
|
||
Nullability : | ||
|
||
- ListNullability NullabilityDesignator? | ||
- NullabilityDesignator | ||
|
||
ListNullability : `[` Nullability? `]` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a good reason for the This means that something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To clarify, I am talking about the If it were There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't it make sense to allow
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Thanks @benjie, you are right! So |
||
|
||
NullabilityDesignator : | ||
|
||
- `!` | ||
- `?` | ||
|
||
Arguments[Const] : ( Argument[?Const]+ ) | ||
|
||
Argument[Const] : Name : Value[?Const] | ||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -564,6 +564,47 @@ fragment conflictingDifferingResponses on Pet { | |||||||
} | ||||||||
``` | ||||||||
|
||||||||
The same is true if a field is designated `Non-Nullable` in an operation. In | ||||||||
this case, `nickname` could be either a `String` or a `String!` which are two | ||||||||
different types and therefore can not be merged: | ||||||||
|
||||||||
```graphql counter-example | ||||||||
fragment conflictingDifferingResponses on Pet { | ||||||||
... on Dog { | ||||||||
nickname | ||||||||
} | ||||||||
... on Cat { | ||||||||
nickname! | ||||||||
} | ||||||||
} | ||||||||
``` | ||||||||
|
||||||||
### Client Controlled Nullability Designator List Dimensions | ||||||||
twof marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
|
||||||||
**Formal Specification** | ||||||||
|
||||||||
- For each {field} in the document | ||||||||
- Let {fieldDef} be the definition of {field} | ||||||||
- Let {fieldType} be the type of {fieldDef} | ||||||||
- Let {requiredStatus} be the required status of {field} | ||||||||
- Let {designatorDepth} be the number of ListNullability operators in | ||||||||
{requiredStatus} | ||||||||
- If {designatorDepth} is 0 | ||||||||
- return true | ||||||||
- Let {typeDepth} be the number of list dimensions in {fieldType} | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question for the community: Is it obvious what's meant by "list dimensions"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. more common term 'rank' There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. number of dimensions is more like matrixes: M[i, j, k] - dimension 3; Graphq does not have these; what we have is rank (I believe) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PostgreSQL uses
C (and thus probably all C-style languages) uses dimensions; the manual page for arrays doesn't mention the term "rank": https://www.gnu.org/software/gnu-c-manual/gnu-c-manual.html#Multidimensional-Arrays Haskell seems to use dimensions (this page on arrays doesn't mention "rank"): https://www.haskell.org/tutorial/arrays.html Fortran uses rank, but defines rank as the "number of dimensions": https://www.ibm.com/docs/en/xffbg/121.141?topic=basics-rank-shape-size-array .NET uses rank, but quickly defines it as "number of dimensions": https://docs.microsoft.com/en-us/dotnet/api/system.array.rank?view=net-6.0 I think "number of dimensions" is the most universal term, and "rank" is a shorthand used in some languages. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From the .NET link above, note that at least in some languages, jagged arrays, i.e. arrays of arrays that need not be the same length, have rank/dimension of 1 rather than being truly multidimensional. Off the cuff, this is not of major concern, as the rank/dimension referred to seems to be most important there in terms of memory management. Although, I agree that the term "depth" more accurately describes what we have in GraphQL. Perhaps we can define depth even without the use of "dimension" at all. |
||||||||
- If {typeDepth} equals {designatorDepth} or {designatorDepth} equals 0 return | ||||||||
true | ||||||||
Comment on lines
+595
to
+596
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about this:
Suggested change
? This way, With this schema: type Query {
field: [[String]]
} This would all be valid: {
# make the list required
a: field!
# make the items of the list required
a: field[!]
# make the items of the items of the list required
a: field[[!]]
} I don't think it's going to be used that much but it's a more generic rule and avoids "0" as an outlier: everything that's not mentioned explicitely is untouched There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Someone will need to go back through the notes, but IIRC the concern with this was that it's not clear how to read a list operator with fewer dimensions than the list type it's being applied to. ie Does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think it would work like for a single dimension list. For this field definition
I won't be able to join unfortunately but I'm working with Calvin so I'll discuss this with him :)! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also think But |
||||||||
- Otherwise return false | ||||||||
|
||||||||
**Explanatory Text** | ||||||||
|
||||||||
List fields can be marked with nullability designators that look like `[?]!` to | ||||||||
indicate the nullability of the list's elements and the nullability of the list | ||||||||
itself. For multi-dimensional lists, the designator would look something like | ||||||||
`[[[!]?]]!`. If any `ListNullability` operators are used then the number of | ||||||||
dimensions of the designator are required to match the number of dimensions of | ||||||||
the field's type. If the two do not match then a validation error is thrown. | ||||||||
|
||||||||
### Leaf Field Selections | ||||||||
|
||||||||
**Formal Specification** | ||||||||
|
Uh oh!
There was an error while loading. Please reload this page.