Skip to content

Commit 87ea684

Browse files
committed
bugfix getAllTypes and star wars introspection test
1 parent c5e95f4 commit 87ea684

File tree

4 files changed

+80
-22
lines changed

4 files changed

+80
-22
lines changed

src/main/java/graphql/schema/SchemaUtil.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33

44
import graphql.GraphQLException;
5+
import graphql.introspection.Introspection;
56

67
import java.util.ArrayList;
78
import java.util.LinkedHashMap;
@@ -101,6 +102,7 @@ public Map<String, GraphQLType> allTypes(GraphQLSchema schema) {
101102
if (schema.isSupportingMutations()) {
102103
collectTypes(schema.getMutationType(), typesByName);
103104
}
105+
collectTypes(Introspection.__Schema, typesByName);
104106
return typesByName;
105107
}
106108

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package graphql
2+
3+
import spock.lang.Specification
4+
5+
6+
class StarWarsIntrospectionTests extends Specification {
7+
8+
def "Allows querying the schema for types"() {
9+
given:
10+
def query = """
11+
query IntrospectionTypeQuery {
12+
__schema {
13+
types {
14+
name
15+
}
16+
}
17+
}
18+
"""
19+
def expected = [
20+
__schema: [types:
21+
[[name: 'QueryType'],
22+
[name: 'Character'],
23+
[name: 'String'],
24+
[name: 'Episode'],
25+
[name: 'Human'],
26+
[name: 'Droid'],
27+
[name: '__Schema'],
28+
[name: '__Type'],
29+
[name: '__TypeKind'],
30+
[name: '__Field'],
31+
[name: '__InputValue'],
32+
[name: 'Boolean'],
33+
[name: '__EnumValue'],
34+
[name: '__Directive']]
35+
]
36+
37+
];
38+
39+
when:
40+
def result = new GraphQL(StarWarsSchema.starWarsSchema).execute(query).result
41+
42+
then:
43+
result == expected
44+
}
45+
46+
47+
}

src/test/groovy/graphql/schema/IntrospectionUtilTest.groovy

Lines changed: 0 additions & 22 deletions
This file was deleted.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package graphql.schema
2+
3+
import graphql.introspection.Introspection
4+
import spock.lang.Specification
5+
6+
import static graphql.Scalars.GraphQLBoolean
7+
import static graphql.Scalars.GraphQLString
8+
import static graphql.StarWarsSchema.*
9+
10+
class SchemaUtilTest extends Specification {
11+
12+
def "collectAllTypes"() {
13+
when:
14+
Map<String, GraphQLType> types = new SchemaUtil().allTypes(starWarsSchema)
15+
then:
16+
types == [(droidType.name) : droidType,
17+
(humanType.name) : humanType,
18+
(queryType.name) : queryType,
19+
(characterInterface.name) : characterInterface,
20+
(episodeEnum.name) : episodeEnum,
21+
(GraphQLString.name) : GraphQLString,
22+
(Introspection.__Schema.name) : Introspection.__Schema,
23+
(Introspection.__Type.name) : Introspection.__Type,
24+
(Introspection.__TypeKind.name) : Introspection.__TypeKind,
25+
(Introspection.__Field.name) : Introspection.__Field,
26+
(Introspection.__InputValue.name): Introspection.__InputValue,
27+
(Introspection.__EnumValue.name) : Introspection.__EnumValue,
28+
(Introspection.__Directive.name) : Introspection.__Directive,
29+
(GraphQLBoolean.name) : GraphQLBoolean]
30+
}
31+
}

0 commit comments

Comments
 (0)