Skip to content

Commit 3df7788

Browse files
committed
Make introspection query in type/__tests__ a fully featured
introspection query and factor it out into its own module. This will allow it to be reused in other contexts.
1 parent 3f2a252 commit 3df7788

File tree

2 files changed

+190
-82
lines changed

2 files changed

+190
-82
lines changed

src/type/__tests__/introspection.js

Lines changed: 100 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -21,104 +21,122 @@ import {
2121
GraphQLEnumType,
2222
} from '../../';
2323

24+
import { introspectionQuery } from '../introspectionQuery';
2425

2526
describe('Introspection', () => {
26-
2727
it('executes an introspection query', () => {
28-
2928
var EmptySchema = new GraphQLSchema({
3029
query: new GraphQLObjectType({
3130
name: 'QueryRoot',
3231
fields: {}
3332
})
3433
});
3534

36-
var request = `
37-
query IntrospectionTestQuery {
38-
schemaType: __type(name: "__Schema") {
39-
name
40-
}
41-
queryRootType: __type(name: "QueryRoot") {
42-
name
43-
}
44-
__schema {
45-
__typename
46-
types {
47-
__typename
48-
kind
49-
name
50-
fields {
51-
__typename
52-
name
53-
args {
54-
__typename
55-
name
56-
type { ...TypeRef }
57-
defaultValue
58-
}
59-
type {
60-
...TypeRef
61-
}
62-
isDeprecated
63-
deprecationReason
64-
}
65-
interfaces {
66-
...TypeRef
67-
}
68-
enumValues {
69-
__typename
70-
name
71-
isDeprecated
72-
deprecationReason
73-
}
74-
}
75-
directives {
76-
__typename
77-
name
78-
args {
79-
__typename
80-
name
81-
type { ...TypeRef }
82-
defaultValue
83-
}
84-
onOperation
85-
onFragment
86-
onField
87-
}
88-
}
89-
}
90-
91-
fragment TypeRef on __Type {
92-
__typename
93-
kind
94-
name
95-
ofType {
96-
__typename
97-
kind
98-
name
99-
ofType {
100-
__typename
101-
kind
102-
name
103-
ofType {
104-
__typename
105-
kind
106-
name
107-
}
108-
}
109-
}
110-
}
111-
`;
112-
11335
return expect(
114-
graphql(EmptySchema, request)
36+
graphql(EmptySchema, introspectionQuery)
11537
).to.become({
11638
data: {
11739
schemaType: {
118-
name: '__Schema'
40+
__typename: '__Type',
41+
enumValues: null,
42+
fields: [
43+
{
44+
__typename: '__Field',
45+
args: [],
46+
deprecationReason: null,
47+
isDeprecated: false,
48+
name: 'types',
49+
type: {
50+
__typename: '__Type',
51+
kind: 'NON_NULL',
52+
name: null,
53+
ofType: {
54+
__typename: '__Type',
55+
kind: 'LIST',
56+
name: null,
57+
ofType: {
58+
__typename: '__Type',
59+
kind: 'NON_NULL',
60+
name: null,
61+
ofType: {
62+
__typename: '__Type',
63+
kind: 'OBJECT',
64+
name: '__Type',
65+
}
66+
}
67+
}
68+
}
69+
},
70+
{
71+
__typename: '__Field',
72+
args: [],
73+
deprecationReason: null,
74+
isDeprecated: false,
75+
name: 'queryType',
76+
type: {
77+
__typename: '__Type',
78+
kind: 'NON_NULL',
79+
name: null,
80+
ofType: {
81+
__typename: '__Type',
82+
kind: 'OBJECT',
83+
name: '__Type',
84+
ofType: null,
85+
},
86+
},
87+
},
88+
{
89+
__typename: '__Field',
90+
args: [],
91+
deprecationReason: null,
92+
isDeprecated: false,
93+
name: 'mutationType',
94+
type: {
95+
__typename: '__Type',
96+
kind: 'OBJECT',
97+
name: '__Type',
98+
ofType: null,
99+
},
100+
},
101+
{
102+
__typename: '__Field',
103+
args: [],
104+
deprecationReason: null,
105+
isDeprecated: false,
106+
name: 'directives',
107+
type: {
108+
__typename: '__Type',
109+
kind: 'NON_NULL',
110+
name: null,
111+
ofType: {
112+
__typename: '__Type',
113+
kind: 'LIST',
114+
name: null,
115+
ofType: {
116+
__typename: '__Type',
117+
kind: 'NON_NULL',
118+
name: null,
119+
ofType: {
120+
__typename: '__Type',
121+
kind: 'OBJECT',
122+
name: '__Directive',
123+
},
124+
},
125+
},
126+
},
127+
},
128+
],
129+
interfaces: [],
130+
kind: 'OBJECT',
131+
name: '__Schema',
119132
},
120133
queryRootType: {
121-
name: 'QueryRoot'
134+
__typename: '__Type',
135+
enumValues: null,
136+
fields: [],
137+
interfaces: [],
138+
kind: 'OBJECT',
139+
name: 'QueryRoot',
122140
},
123141
__schema: {
124142
__typename: '__Schema',

src/type/introspectionQuery.js

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/**
2+
* Copyright (c) 2015, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
export var introspectionQuery = `
11+
query IntrospectionTestQuery {
12+
schemaType: __type(name: "__Schema") {
13+
...FullType
14+
}
15+
queryRootType: __type(name: "QueryRoot") {
16+
...FullType
17+
}
18+
__schema {
19+
__typename
20+
types {
21+
...FullType
22+
}
23+
directives {
24+
__typename
25+
name
26+
args {
27+
__typename
28+
name
29+
type { ...TypeRef }
30+
defaultValue
31+
}
32+
onOperation
33+
onFragment
34+
onField
35+
}
36+
}
37+
}
38+
39+
fragment FullType on __Type {
40+
__typename
41+
kind
42+
name
43+
fields {
44+
__typename
45+
name
46+
args {
47+
__typename
48+
name
49+
type { ...TypeRef }
50+
defaultValue
51+
}
52+
type {
53+
...TypeRef
54+
}
55+
isDeprecated
56+
deprecationReason
57+
}
58+
interfaces {
59+
...TypeRef
60+
}
61+
enumValues {
62+
__typename
63+
name
64+
isDeprecated
65+
deprecationReason
66+
}
67+
}
68+
69+
fragment TypeRef on __Type {
70+
__typename
71+
kind
72+
name
73+
ofType {
74+
__typename
75+
kind
76+
name
77+
ofType {
78+
__typename
79+
kind
80+
name
81+
ofType {
82+
__typename
83+
kind
84+
name
85+
}
86+
}
87+
}
88+
}
89+
`;
90+

0 commit comments

Comments
 (0)