@@ -9,28 +9,16 @@ import { fakeConfig } from './test/util.js';
9
9
describe ( 'getTypeInfos' , ( ) => {
10
10
it ( 'returns typename and field names' , ( ) => {
11
11
const schema = buildSchema ( `
12
- interface Node {
13
- id: ID!
14
- }
15
- type Book implements Node {
12
+ type Book {
16
13
id: ID!
17
14
title: String!
18
15
author: Author!
19
16
}
20
- type Author implements Node {
17
+ type Author {
21
18
id: ID!
22
19
name: String!
23
20
books: [Book!]!
24
21
}
25
- type Query {
26
- node(id: ID!): Node
27
- }
28
- type Subscription {
29
- bookAdded: Book!
30
- }
31
- type Mutation {
32
- addBook(title: String!, authorId: ID!): Book!
33
- }
34
22
` ) ;
35
23
const config : Config = fakeConfig ( ) ;
36
24
expect ( getTypeInfos ( config , schema ) ) . toMatchInlineSnapshot ( `
@@ -85,54 +73,181 @@ describe('getTypeInfos', () => {
85
73
],
86
74
"name": "Author",
87
75
},
88
- {
89
- "comment": undefined,
90
- "fields": [
91
- {
92
- "name": "__typename",
93
- "typeString": "'Query'",
94
- },
95
- {
96
- "comment": undefined,
97
- "name": "node",
98
- "typeString": "Query['node'] | undefined",
99
- },
100
- ],
101
- "name": "Query",
102
- },
103
- {
104
- "comment": undefined,
105
- "fields": [
106
- {
107
- "name": "__typename",
108
- "typeString": "'Subscription'",
109
- },
110
- {
111
- "comment": undefined,
112
- "name": "bookAdded",
113
- "typeString": "OptionalBook | undefined",
114
- },
115
- ],
116
- "name": "Subscription",
117
- },
118
- {
119
- "comment": undefined,
120
- "fields": [
121
- {
122
- "name": "__typename",
123
- "typeString": "'Mutation'",
124
- },
125
- {
126
- "comment": undefined,
127
- "name": "addBook",
128
- "typeString": "OptionalBook | undefined",
129
- },
130
- ],
131
- "name": "Mutation",
132
- },
133
76
]
134
77
` ) ;
135
78
} ) ;
79
+ it ( 'argument' , ( ) => {
80
+ const schema = buildSchema ( `
81
+ type Argument {
82
+ field(arg: String!): String!
83
+ }
84
+ ` ) ;
85
+ const config : Config = fakeConfig ( ) ;
86
+ expect ( getTypeInfos ( config , schema ) [ 0 ] ) . toMatchInlineSnapshot ( `
87
+ {
88
+ "comment": undefined,
89
+ "fields": [
90
+ {
91
+ "name": "__typename",
92
+ "typeString": "'Argument'",
93
+ },
94
+ {
95
+ "comment": undefined,
96
+ "name": "field",
97
+ "typeString": "Argument['field'] | undefined",
98
+ },
99
+ ],
100
+ "name": "Argument",
101
+ }
102
+ ` ) ;
103
+ } ) ;
104
+ it ( 'nullable' , ( ) => {
105
+ const schema = buildSchema ( `
106
+ type Type {
107
+ field1: String
108
+ field2: [String]
109
+ field3: SubType
110
+ field4: [SubType]
111
+ }
112
+ type SubType {
113
+ field: String!
114
+ }
115
+ ` ) ;
116
+ const config : Config = fakeConfig ( ) ;
117
+ expect ( getTypeInfos ( config , schema ) [ 0 ] ) . toMatchInlineSnapshot ( `
118
+ {
119
+ "comment": undefined,
120
+ "fields": [
121
+ {
122
+ "name": "__typename",
123
+ "typeString": "'Type'",
124
+ },
125
+ {
126
+ "comment": undefined,
127
+ "name": "field1",
128
+ "typeString": "Type['field1'] | undefined",
129
+ },
130
+ {
131
+ "comment": undefined,
132
+ "name": "field2",
133
+ "typeString": "Type['field2'] | undefined",
134
+ },
135
+ {
136
+ "comment": undefined,
137
+ "name": "field3",
138
+ "typeString": "Maybe<OptionalSubType> | undefined",
139
+ },
140
+ {
141
+ "comment": undefined,
142
+ "name": "field4",
143
+ "typeString": "Maybe<Maybe<OptionalSubType>[]> | undefined",
144
+ },
145
+ ],
146
+ "name": "Type",
147
+ }
148
+ ` ) ;
149
+ } ) ;
150
+ it ( 'interface' , ( ) => {
151
+ const schema = buildSchema ( `
152
+ interface Interface1 {
153
+ fieldA: String!
154
+ }
155
+ interface Interface2 {
156
+ fieldB: String!
157
+ }
158
+ type ImplementingType implements Interface1 & Interface2 {
159
+ fieldA: String!
160
+ fieldB: String!
161
+ }
162
+ ` ) ;
163
+ const config : Config = fakeConfig ( ) ;
164
+ expect ( getTypeInfos ( config , schema ) [ 0 ] ) . toMatchInlineSnapshot ( `
165
+ {
166
+ "comment": undefined,
167
+ "fields": [
168
+ {
169
+ "name": "__typename",
170
+ "typeString": "'ImplementingType'",
171
+ },
172
+ {
173
+ "comment": undefined,
174
+ "name": "fieldA",
175
+ "typeString": "ImplementingType['fieldA'] | undefined",
176
+ },
177
+ {
178
+ "comment": undefined,
179
+ "name": "fieldB",
180
+ "typeString": "ImplementingType['fieldB'] | undefined",
181
+ },
182
+ ],
183
+ "name": "ImplementingType",
184
+ }
185
+ ` ) ;
186
+ } ) ;
187
+ it ( 'union' , ( ) => {
188
+ const schema = buildSchema ( `
189
+ union Union1 = Member1 | Member2
190
+ union Union2 = Member1 | Member2
191
+ type Member1 {
192
+ field1: String!
193
+ }
194
+ type Member2 {
195
+ field2: String!
196
+ }
197
+ ` ) ;
198
+ const config : Config = fakeConfig ( ) ;
199
+ expect ( getTypeInfos ( config , schema ) [ 0 ] ) . toMatchInlineSnapshot ( `
200
+ {
201
+ "comment": undefined,
202
+ "fields": [
203
+ {
204
+ "name": "__typename",
205
+ "typeString": "'Member1'",
206
+ },
207
+ {
208
+ "comment": undefined,
209
+ "name": "field1",
210
+ "typeString": "Member1['field1'] | undefined",
211
+ },
212
+ ],
213
+ "name": "Member1",
214
+ }
215
+ ` ) ;
216
+ } ) ;
217
+ it ( 'input' , ( ) => {
218
+ const schema = buildSchema ( `
219
+ input Input {
220
+ field1: String!
221
+ field2: SubType!
222
+ }
223
+ type SubType {
224
+ field: String!
225
+ }
226
+ ` ) ;
227
+ const config : Config = fakeConfig ( ) ;
228
+ expect ( getTypeInfos ( config , schema ) [ 0 ] ) . toMatchInlineSnapshot ( `
229
+ {
230
+ "comment": undefined,
231
+ "fields": [
232
+ {
233
+ "name": "__typename",
234
+ "typeString": "'Input'",
235
+ },
236
+ {
237
+ "comment": undefined,
238
+ "name": "field1",
239
+ "typeString": "Input['field1'] | undefined",
240
+ },
241
+ {
242
+ "comment": undefined,
243
+ "name": "field2",
244
+ "typeString": "OptionalSubType | undefined",
245
+ },
246
+ ],
247
+ "name": "Input",
248
+ }
249
+ ` ) ;
250
+ } ) ;
136
251
it ( 'includes __typename if skipTypename is false' , ( ) => {
137
252
const schema = buildSchema ( `
138
253
type Book {
0 commit comments