Skip to content

all but visitor test passing #2

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

Merged
merged 2 commits into from
Dec 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/__testUtils__/kitchenSinkQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,21 @@ query queryName($foo: ComplexType, $site: Site = MOBILE) @onQuery {
...frag @onFragmentSpread
}
}

field3!
field4?
requiredField5: field5!
requiredSelectionSet(first: 10)! @directive {
field
}

unsetListItemsRequiredList: listField[]!
requiredListItemsUnsetList: listField[!]
requiredListItemsRequiredList: listField[!]!
unsetListItemsOptionalList: listField[]?
optionalListItemsUnsetList: listField[?]
optionalListItemsOptionalList: listField[?]?
multidimensionalList: listField[[[!]!]!]!
}
... @skip(unless: $foo) {
id
Expand Down
318 changes: 318 additions & 0 deletions src/language/__tests__/parser-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ describe('Parser', () => {
required: {
kind: Kind.REQUIRED_DESIGNATOR,
loc: { start: 15, end: 16 },
element: undefined,
},
},
],
Expand Down Expand Up @@ -359,6 +360,323 @@ describe('Parser', () => {
).to.not.throw();
});

it('parses field with required list elements', () => {
const document = '{ field[!] }';
const result = parse(document, {
experimentalClientControlledNullability: true,
});

expectJSON(result).toDeepEqual({
kind: Kind.DOCUMENT,
loc: { start: 0, end: 12 },
definitions: [
{
kind: Kind.OPERATION_DEFINITION,
loc: { start: 0, end: 12 },
operation: 'query',
name: undefined,
variableDefinitions: [],
directives: [],
selectionSet: {
kind: Kind.SELECTION_SET,
loc: { start: 0, end: 12 },
selections: [
{
kind: Kind.FIELD,
loc: { start: 2, end: 10 },
alias: undefined,
name: {
kind: Kind.NAME,
loc: { start: 2, end: 7 },
value: 'field',
},
arguments: [],
directives: [],
required: {
kind: Kind.LIST_NULLABILITY,
loc: { start: 7, end: 10 },
element: {
kind: Kind.REQUIRED_DESIGNATOR,
loc: { start: 8, end: 9 },
element: undefined,
},
},
selectionSet: undefined,
},
],
},
},
],
});
});

it('parses field with optional list elements', () => {
const document = '{ field[?] }';
const result = parse(document, {
experimentalClientControlledNullability: true,
});

expectJSON(result).toDeepEqual({
kind: Kind.DOCUMENT,
loc: { start: 0, end: 12 },
definitions: [
{
kind: Kind.OPERATION_DEFINITION,
loc: { start: 0, end: 12 },
operation: 'query',
name: undefined,
variableDefinitions: [],
directives: [],
selectionSet: {
kind: Kind.SELECTION_SET,
loc: { start: 0, end: 12 },
selections: [
{
kind: Kind.FIELD,
loc: { start: 2, end: 10 },
alias: undefined,
name: {
kind: Kind.NAME,
loc: { start: 2, end: 7 },
value: 'field',
},
arguments: [],
directives: [],
required: {
kind: Kind.LIST_NULLABILITY,
loc: { start: 7, end: 10 },
element: {
kind: Kind.OPTIONAL_DESIGNATOR,
loc: { start: 8, end: 9 },
element: undefined,
},
},
selectionSet: undefined,
},
],
},
},
],
});
});

it('parses field with required list', () => {
const document = '{ field[]! }';
const result = parse(document, {
experimentalClientControlledNullability: true,
});

expectJSON(result).toDeepEqual({
kind: Kind.DOCUMENT,
loc: { start: 0, end: 12 },
definitions: [
{
kind: Kind.OPERATION_DEFINITION,
loc: { start: 0, end: 12 },
operation: 'query',
name: undefined,
variableDefinitions: [],
directives: [],
selectionSet: {
kind: Kind.SELECTION_SET,
loc: { start: 0, end: 12 },
selections: [
{
kind: Kind.FIELD,
loc: { start: 2, end: 10 },
alias: undefined,
name: {
kind: Kind.NAME,
loc: { start: 2, end: 7 },
value: 'field',
},
arguments: [],
directives: [],
selectionSet: undefined,
required: {
kind: Kind.REQUIRED_DESIGNATOR,
loc: { start: 9, end: 10 },
element: {
kind: Kind.LIST_NULLABILITY,
element: undefined,
loc: { start: 7, end: 9 },
},
},
},
],
},
},
],
});
});

it('parses field with optional list', () => {
const document = '{ field[]? }';
const result = parse(document, {
experimentalClientControlledNullability: true,
});

expectJSON(result).toDeepEqual({
kind: Kind.DOCUMENT,
loc: { start: 0, end: 12 },
definitions: [
{
kind: Kind.OPERATION_DEFINITION,
loc: { start: 0, end: 12 },
operation: 'query',
name: undefined,
variableDefinitions: [],
directives: [],
selectionSet: {
kind: Kind.SELECTION_SET,
loc: { start: 0, end: 12 },
selections: [
{
kind: Kind.FIELD,
loc: { start: 2, end: 10 },
alias: undefined,
name: {
kind: Kind.NAME,
loc: { start: 2, end: 7 },
value: 'field',
},
arguments: [],
directives: [],
required: {
kind: Kind.OPTIONAL_DESIGNATOR,
loc: { start: 9, end: 10 },
element: {
kind: Kind.LIST_NULLABILITY,
loc: { start: 7, end: 9 },
element: undefined,
},
},
selectionSet: undefined,
},
],
},
},
],
});
});

it('parses multidimensional field with mixed list elements', () => {
const document = '{ field[[[?]!]]! }';
const result = parse(document, {
experimentalClientControlledNullability: true,
});

expectJSON(result).toDeepEqual({
kind: Kind.DOCUMENT,
loc: { start: 0, end: 18 },
definitions: [
{
kind: Kind.OPERATION_DEFINITION,
loc: { start: 0, end: 18 },
operation: 'query',
name: undefined,
variableDefinitions: [],
directives: [],
selectionSet: {
kind: Kind.SELECTION_SET,
loc: { start: 0, end: 18 },
selections: [
{
kind: Kind.FIELD,
loc: { start: 2, end: 16 },
alias: undefined,
name: {
kind: Kind.NAME,
loc: { start: 2, end: 7 },
value: 'field',
},
arguments: [],
directives: [],
required: {
kind: Kind.REQUIRED_DESIGNATOR,
loc: { start: 15, end: 16 },
element: {
kind: Kind.LIST_NULLABILITY,
loc: { start: 7, end: 15 },
element: {
kind: Kind.LIST_NULLABILITY,
loc: { start: 8, end: 14 },
element: {
kind: Kind.REQUIRED_DESIGNATOR,
loc: { start: 12, end: 13 },
element: {
kind: Kind.LIST_NULLABILITY,
loc: { start: 9, end: 12 },
element: {
kind: Kind.OPTIONAL_DESIGNATOR,
loc: { start: 10, end: 11 },
element: undefined,
},
},
},
},
},
},
selectionSet: undefined,
},
],
},
},
],
});
});

it('does not parse field with unbalanced brackets', () => {
const leftHeavyDocument = '{ field[[] }';
expect(() =>
parse(leftHeavyDocument, {
experimentalClientControlledNullability: true,
}),
).to.throw('Syntax Error: Expected "]", found "}".');

const rightHeavyDocument = '{ field[]] }';
expect(() =>
parse(rightHeavyDocument, {
experimentalClientControlledNullability: true,
}),
).to.throw('Syntax Error: Expected Name, found "]".');

const leftMissingDocument = '{ field] }';
expect(() =>
parse(leftMissingDocument, {
experimentalClientControlledNullability: true,
}),
).to.throw('Syntax Error: Expected Name, found "]".');

const rightMissingDocument = '{ field[ }';
expect(() =>
parse(rightMissingDocument, {
experimentalClientControlledNullability: true,
}),
).to.throw('Syntax Error: Expected "]", found "}".');
});

it('does not parse field with assorted invalid nullability designators', () => {
const doubleDocument = '{ field[][] }';
expect(() =>
parse(doubleDocument, { experimentalClientControlledNullability: true }),
).to.throw('Syntax Error: Expected Name, found "[".');

const doubleBangDocument = '{ field[!!] }';
expect(() =>
parse(doubleBangDocument, {
experimentalClientControlledNullability: true,
}),
).to.throw('Syntax Error: Expected "]", found "!".');

const multipleNullabilityDocument = '{ field[]?! }';
expect(() =>
parse(multipleNullabilityDocument, {
experimentalClientControlledNullability: true,
}),
).to.throw('Syntax Error: Expected Name, found "!".');
});

it('creates ast', () => {
const result = parse(dedent`
{
Expand Down
7 changes: 7 additions & 0 deletions src/language/__tests__/printer-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,13 @@ describe('Printer: Query document', () => {
requiredSelectionSet(first: 10)! @directive {
field
}
unsetListItemsRequiredList: listField[]!
requiredListItemsUnsetList: listField[!]
requiredListItemsRequiredList: listField[!]!
unsetListItemsOptionalList: listField[]?
optionalListItemsUnsetList: listField[?]
optionalListItemsOptionalList: listField[?]?
multidimensionalList: listField[[[!]!]!]!
}
... @skip(unless: $foo) {
id
Expand Down
Loading