Mirror: The small sibling of the graphql package, slimmed down for client-side libraries.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Implement nullability operators in query language

The ["Nullability RFC" for GraphQL](https://github.com/graphql/graphql-wg/issues/694)
allows fields to individually be marked as optional or required in a query by the
client-side. ([See Strawman Proposal](https://github.com/graphql/graphql-spec/issues/867))

If a field is marked as optional then it's allowed to be missing and `null`, which
can control where missing values cascade to:

```graphql
query {
me {
name?
}
}
```

If a field is marked as required it may never be allowed to become `null` and must
cascade if it otherwise would have been set to `null`:

```graphql
query {
me {
name!
}
}
```

+24 -3
+8
alias/language/__tests__/printer.test.js
··· 54 54 name 55 55 } 56 56 `); 57 + 58 + const queryWithNullabilityFields = parse('query { id?, name! }'); 59 + expect(print(queryWithNullabilityFields)).toBe(dedent` 60 + { 61 + id? 62 + name! 63 + } 64 + `); 57 65 }); 58 66 59 67 it('prints query with variable directives', () => {
+9
alias/language/parser.mjs
··· 147 147 ${directive}* 148 148 `; 149 149 150 + const nullability = match(null, (x) => { 151 + return x[0] === '?' ? 'optional' : 'required'; 152 + })` 153 + :${ignored}? 154 + ${/[?!]/} 155 + `; 156 + 150 157 const field = match(Kind.FIELD, (x) => { 151 158 let i = 0; 152 159 return { 153 160 kind: x.tag, 154 161 alias: x[1].kind === Kind.NAME ? x[i++] : undefined, 155 162 name: x[i++], 163 + required: typeof x[i] === 'string' ? x[i++] : 'unset', 156 164 arguments: x[i++], 157 165 directives: x[i++], 158 166 selectionSet: x[i++], ··· 164 172 (?: ${ignored}? ${':'} ${ignored}?) 165 173 ${name} 166 174 )? 175 + ${nullability}? 167 176 ${args} 168 177 ${directives} 169 178 ${() => selectionSet}?
+7 -3
alias/language/printer.mjs
··· 36 36 ); 37 37 38 38 case 'Field': 39 + let prefix = wrap('', print(node.alias), ': ') + print(node.name); 40 + if (node.required === 'optional') { 41 + prefix += '?'; 42 + } else if (node.required === 'required') { 43 + prefix += '!'; 44 + } 39 45 return join( 40 46 [ 41 - wrap('', print(node.alias), ': ') + 42 - print(node.name) + 43 - wrap('(', join(print(node.arguments), ', '), ')'), 47 + prefix + wrap('(', join(print(node.arguments), ', '), ')'), 44 48 join(print(node.directives), ' '), 45 49 print(node.selectionSet), 46 50 ],