This repository has been archived by the owner on Nov 5, 2021. It is now read-only.
/
graphql.test.ts
143 lines (136 loc) · 5.07 KB
/
graphql.test.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import { testTokenization } from '../test/testRunner';
testTokenization('graphql', [
// Keywords
[{
line: 'scalar Date',
tokens: [
{ startIndex: 0, type: 'keyword.gql' },
{ startIndex: 6, type: '' },
{ startIndex: 7, type: 'type.identifier.gql' },
]
}],
// Root schema definition
[{
line: 'schema { query: Query, mutation: Mutation subscription: Subscription }',
tokens: [
{ startIndex: 0, type: "keyword.gql" },
{ startIndex: 6, type: "" },
{ startIndex: 7, type: "delimiter.curly.gql" },
{ startIndex: 8, type: "" },
{ startIndex: 9, type: "keyword.gql" }, // this should be identifier
{ startIndex: 14, type: "operator.gql" },
{ startIndex: 15, type: "" },
{ startIndex: 16, type: "type.identifier.gql" },
{ startIndex: 21, type: "delimiter.gql" },
{ startIndex: 22, type: "" },
{ startIndex: 23, type: "keyword.gql" }, // this should be identifier
{ startIndex: 31, type: "operator.gql" },
{ startIndex: 32, type: "" },
{ startIndex: 33, type: "type.identifier.gql" },
{ startIndex: 41, type: "" },
{ startIndex: 42, type: "keyword.gql" }, // this should be identifier
{ startIndex: 54, type: "operator.gql" },
{ startIndex: 55, type: "" },
{ startIndex: 56, type: "type.identifier.gql" },
{ startIndex: 68, type: "" },
{ startIndex: 69, type: "delimiter.curly.gql" },
]
}],
[{
line: `query testQuery($intValue:Int=3){value(arg:{string:"string" int:$intValue}){field1 field2}}`,
tokens: [
{ startIndex: 0, type: "keyword.gql" }, // 'query'
{ startIndex: 5, type: "" }, // ' '
{ startIndex: 6, type: "key.identifier.gql" }, // 'testQuery'
{ startIndex: 15, type: "delimiter.parenthesis.gql" }, // '('
{ startIndex: 16, type: "argument.identifier.gql" }, // '$intValue'
{ startIndex: 25, type: "operator.gql" }, // ':'
{ startIndex: 26, type: "keyword.gql" }, // 'Int'
{ startIndex: 29, type: "operator.gql" }, // '='
{ startIndex: 30, type: "number.gql" }, // '3'
{ startIndex: 31, type: "delimiter.parenthesis.gql" }, // ')'
{ startIndex: 32, type: "delimiter.curly.gql" }, // '{'
{ startIndex: 33, type: "key.identifier.gql" }, // 'value'
{ startIndex: 38, type: "delimiter.parenthesis.gql" }, // '('
{ startIndex: 39, type: "key.identifier.gql" }, // 'arg'
{ startIndex: 42, type: "operator.gql" }, // ':'
{ startIndex: 43, type: "delimiter.curly.gql" }, // '{'
{ startIndex: 44, type: "key.identifier.gql" }, // 'string'
{ startIndex: 50, type: "operator.gql" }, // ':'
{ startIndex: 51, type: "string.quote.gql" }, // '"'
{ startIndex: 52, type: "string.gql" }, // 'string'
{ startIndex: 58, type: "string.quote.gql" }, // '"'
{ startIndex: 59, type: "" }, // ' '
{ startIndex: 60, type: "key.identifier.gql" }, // 'int'
{ startIndex: 63, type: "operator.gql" }, // ':'
{ startIndex: 64, type: "argument.identifier.gql" }, // '$intValue'
{ startIndex: 73, type: "delimiter.curly.gql" }, // '}'
{ startIndex: 74, type: "delimiter.parenthesis.gql" }, // ')'
{ startIndex: 75, type: "delimiter.curly.gql" }, // '{'
{ startIndex: 76, type: "key.identifier.gql" }, // 'field1'
{ startIndex: 82, type: "" }, // ' '
{ startIndex: 83, type: "key.identifier.gql" }, // 'field2'
{ startIndex: 89, type: "delimiter.curly.gql" }, // '}}'
],
}],
// More complex test:
// """
// Node interface
// - allows (re)fetch arbitrary entity only by ID
// """
// interface Node {
// id: ID!
// }
[
{
line: '"""',
tokens: [
{ startIndex: 0, type: "string.gql" }
],
},
{
line: 'This is MarkDown',
tokens: [
{ startIndex: 0, type: "" }
],
},
{
line: '"""',
tokens: [
{ startIndex: 0, type: "string.gql" }
],
},
{
line: 'interface Node {',
tokens: [
{ startIndex: 0, type: "keyword.gql" },
{ startIndex: 9, type: "" },
{ startIndex: 10, type: "type.identifier.gql" },
{ startIndex: 14, type: "" },
{ startIndex: 15, type: "delimiter.curly.gql" },
],
},
{
line: ' id: ID!',
tokens: [
{ startIndex: 0, type: "" },
{ startIndex: 2, type: "key.identifier.gql" },
{ startIndex: 4, type: "operator.gql" },
{ startIndex: 5, type: "" },
{ startIndex: 6, type: "keyword.gql" },
{ startIndex: 8, type: "operator.gql" },
],
},
{
line: '}',
tokens: [
{ startIndex: 0, type: "delimiter.curly.gql", },
],
},
]
]);