Skip to content

Commit 66bb7e6

Browse files
committed
feat(Compatibility) finish SchemaParserSpecification
1 parent 99723da commit 66bb7e6

File tree

5 files changed

+111
-373
lines changed

5 files changed

+111
-373
lines changed

lib/graphql/compatibility/schema_parser_specification.rb

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ def parse(query_string)
1616

1717
def test_it_parses_object_types
1818
document = parse('
19+
# This is what
20+
# somebody said about something
1921
type Comment implements Node @deprecated(reason: "No longer supported") {
2022
id: ID!
2123
}
@@ -24,6 +26,7 @@ def test_it_parses_object_types
2426
type = document.definitions.first
2527
assert_equal GraphQL::Language::Nodes::ObjectTypeDefinition, type.class
2628
assert_equal 'Comment', type.name
29+
assert_equal "This is what\nsomebody said about something", type.description
2730
assert_equal ['Node'], type.interfaces.map(&:name)
2831
assert_equal ['id'], type.fields.map(&:name)
2932
assert_equal [], type.fields[0].arguments
@@ -36,6 +39,103 @@ def test_it_parses_object_types
3639
assert_equal 'No longer supported', deprecated_directive.arguments[0].value
3740
end
3841

42+
def test_it_parses_scalars
43+
document = parse('scalar DateTime')
44+
45+
type = document.definitions.first
46+
assert_equal GraphQL::Language::Nodes::ScalarTypeDefinition, type.class
47+
assert_equal 'DateTime', type.name
48+
end
49+
50+
def test_it_parses_enum_types
51+
document = parse('
52+
enum DogCommand {
53+
# Good dog
54+
SIT
55+
DOWN @deprecated(reason: "No longer supported")
56+
HEEL
57+
}
58+
')
59+
60+
type = document.definitions.first
61+
assert_equal GraphQL::Language::Nodes::EnumTypeDefinition, type.class
62+
assert_equal 'DogCommand', type.name
63+
assert_equal 3, type.values.length
64+
65+
assert_equal 'SIT', type.values[0].name
66+
assert_equal [], type.values[0].directives
67+
assert_equal "Good dog", type.values[0].description
68+
69+
assert_equal 'DOWN', type.values[1].name
70+
assert_equal 1, type.values[1].directives.length
71+
deprecated_directive = type.values[1].directives[0]
72+
assert_equal 'deprecated', deprecated_directive.name
73+
assert_equal 'reason', deprecated_directive.arguments[0].name
74+
assert_equal 'No longer supported', deprecated_directive.arguments[0].value
75+
76+
assert_equal 'HEEL', type.values[2].name
77+
assert_equal [], type.values[2].directives
78+
end
79+
80+
def test_it_parses_input_types
81+
document = parse('
82+
input EmptyMutationInput {
83+
clientMutationId: String
84+
}
85+
')
86+
87+
type = document.definitions.first
88+
assert_equal GraphQL::Language::Nodes::InputObjectTypeDefinition, type.class
89+
assert_equal 'EmptyMutationInput', type.name
90+
assert_equal ['clientMutationId'], type.fields.map(&:name)
91+
assert_equal 'String', type.fields[0].type.name
92+
assert_equal nil, type.fields[0].default_value
93+
end
94+
95+
def test_it_parses_directives
96+
document = parse('
97+
directive @include(if: Boolean!)
98+
on FIELD
99+
| FRAGMENT_SPREAD
100+
| INLINE_FRAGMENT
101+
')
102+
103+
type = document.definitions.first
104+
assert_equal GraphQL::Language::Nodes::DirectiveDefinition, type.class
105+
assert_equal 'include', type.name
106+
107+
assert_equal 1, type.arguments.length
108+
assert_equal 'if', type.arguments[0].name
109+
assert_equal 'Boolean', type.arguments[0].type.of_type.name
110+
111+
assert_equal ['FIELD', 'FRAGMENT_SPREAD', 'INLINE_FRAGMENT'], type.locations
112+
end
113+
114+
def test_it_parses_field_arguments
115+
document = parse('
116+
type Mutation {
117+
post(
118+
id: ID! @deprecated(reason: "Not used"),
119+
# This is what goes in the post
120+
data: String
121+
): Post
122+
}
123+
')
124+
125+
field = document.definitions.first.fields.first
126+
assert_equal ['id', 'data'], field.arguments.map(&:name)
127+
id_arg = field.arguments[0]
128+
129+
deprecated_directive = id_arg.directives[0]
130+
assert_equal 'deprecated', deprecated_directive.name
131+
assert_equal 'reason', deprecated_directive.arguments[0].name
132+
assert_equal 'Not used', deprecated_directive.arguments[0].value
133+
134+
data_arg = field.arguments[1]
135+
assert_equal "data", data_arg.name
136+
assert_equal "This is what goes in the post", data_arg.description
137+
end
138+
39139
def test_it_parses_schema_definition
40140
document = parse('
41141
schema {

0 commit comments

Comments
 (0)