-
-
Notifications
You must be signed in to change notification settings - Fork 100
/
require-nullable-result-in-root.spec.ts
70 lines (67 loc) · 1.4 KB
/
require-nullable-result-in-root.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { GraphQLRuleTester, ParserOptions } from '../src';
import { rule } from '../src/rules/require-nullable-result-in-root';
const ruleTester = new GraphQLRuleTester();
function useSchema(code: string): { code: string; parserOptions: Omit<ParserOptions, 'filePath'> } {
return {
code,
parserOptions: { schema: code },
};
}
ruleTester.runGraphQLTests('require-nullable-result-in-root', rule, {
valid: [
{
...useSchema(/* GraphQL */ `
type Query {
foo: User
baz: [User]!
bar: [User!]!
}
type User {
id: ID!
}
`),
},
],
invalid: [
{
...useSchema(/* GraphQL */ `
type Query {
user: User!
}
type User {
id: ID!
}
`),
errors: 1,
},
{
name: 'should work with extend query',
...useSchema(/* GraphQL */ `
type MyMutation
extend type MyMutation {
user: User!
}
interface User {
id: ID!
}
schema {
mutation: MyMutation
}
`),
errors: 1,
},
{
name: 'should work with default scalars',
...useSchema(/* GraphQL */ `
type MySubscription
extend type MySubscription {
foo: Boolean!
}
schema {
subscription: MySubscription
}
`),
errors: 1,
},
],
});