-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement support for @stream directive
# Conflicts: # src/execution/execute.ts # src/validation/index.d.ts # src/validation/index.ts
- Loading branch information
1 parent
78a31b3
commit b2df00a
Showing
11 changed files
with
1,696 additions
and
23 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
src/validation/__tests__/StreamDirectiveOnListFieldRule-test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { describe, it } from 'mocha'; | ||
|
||
import { StreamDirectiveOnListFieldRule } from '../rules/StreamDirectiveOnListFieldRule'; | ||
|
||
import { expectValidationErrors } from './harness'; | ||
|
||
function expectErrors(queryStr: string) { | ||
return expectValidationErrors(StreamDirectiveOnListFieldRule, queryStr); | ||
} | ||
|
||
function expectValid(queryStr: string) { | ||
expectErrors(queryStr).toDeepEqual([]); | ||
} | ||
|
||
describe('Validate: Stream directive on list field', () => { | ||
it('Stream on list field', () => { | ||
expectValid(` | ||
fragment objectFieldSelection on Human { | ||
pets @stream(initialCount: 0) { | ||
name | ||
} | ||
} | ||
`); | ||
}); | ||
|
||
it('Stream on non-null list field', () => { | ||
expectValid(` | ||
fragment objectFieldSelection on Human { | ||
relatives @stream(initialCount: 0) { | ||
name | ||
} | ||
} | ||
`); | ||
}); | ||
|
||
it("Doesn't validate other directives on list fields", () => { | ||
expectValid(` | ||
fragment objectFieldSelection on Human { | ||
pets @include(if: true) { | ||
name | ||
} | ||
} | ||
`); | ||
}); | ||
|
||
it("Doesn't validate other directives on non-list fields", () => { | ||
expectValid(` | ||
fragment objectFieldSelection on Human { | ||
pets { | ||
name @include(if: true) | ||
} | ||
} | ||
`); | ||
}); | ||
|
||
it("Doesn't validate misplaced stream directives", () => { | ||
expectValid(` | ||
fragment objectFieldSelection on Human { | ||
... @stream(initialCount: 0) { | ||
name | ||
} | ||
} | ||
`); | ||
}); | ||
|
||
it('reports errors when stream is used on non-list field', () => { | ||
expectErrors(` | ||
fragment objectFieldSelection on Human { | ||
name @stream(initialCount: 0) | ||
} | ||
`).toDeepEqual([ | ||
{ | ||
message: | ||
'Stream directive cannot be used on non-list field "name" on type "Human".', | ||
locations: [{ line: 3, column: 14 }], | ||
}, | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.