@@ -123,4 +123,44 @@ def test_deprecations
123123 assert fields [ 1 ] [ :is_deprecated ]
124124 assert fields [ 2 ] [ :arguments ] [ 0 ] [ :is_deprecated ]
125125 end
126+
127+ def test_query_field_deprecation
128+ schema = MySchema
129+ results = GraphQLDocs ::Parser . new ( schema , { } ) . parse
130+
131+ query_types = results [ :query_types ]
132+
133+ # Find the myField query
134+ my_field = query_types . find { |q | q [ :name ] == 'myField' }
135+ refute my_field [ :is_deprecated ] , "myField should not be deprecated"
136+ assert_nil my_field [ :deprecation_reason ] , "myField should not have a deprecation reason"
137+
138+ # Find the deprecatedField query
139+ deprecated_field = query_types . find { |q | q [ :name ] == 'deprecatedField' }
140+ assert deprecated_field [ :is_deprecated ] , "deprecatedField should be marked as deprecated"
141+ assert_equal "Not useful any more" , deprecated_field [ :deprecation_reason ] , "deprecatedField should have correct deprecation reason"
142+
143+ # Find the fieldWithDeprecatedArg query
144+ field_with_deprecated_arg = query_types . find { |q | q [ :name ] == 'fieldWithDeprecatedArg' }
145+ refute field_with_deprecated_arg [ :is_deprecated ] , "fieldWithDeprecatedArg itself should not be deprecated"
146+ assert field_with_deprecated_arg [ :arguments ] [ 0 ] [ :is_deprecated ] , "myArg should be marked as deprecated"
147+ assert_equal "Not useful any more" , field_with_deprecated_arg [ :arguments ] [ 0 ] [ :deprecation_reason ] , "myArg should have correct deprecation reason"
148+ end
149+
150+ def test_mutation_field_deprecation
151+ schema = MySchema
152+ results = GraphQLDocs ::Parser . new ( schema , { } ) . parse
153+
154+ mutation_types = results [ :mutation_types ]
155+
156+ # Find the createUser mutation
157+ create_user = mutation_types . find { |m | m [ :name ] == 'createUser' }
158+ refute create_user [ :is_deprecated ] , "createUser should not be deprecated"
159+ assert_nil create_user [ :deprecation_reason ] , "createUser should not have a deprecation reason"
160+
161+ # Find the deprecatedMutation
162+ deprecated_mutation = mutation_types . find { |m | m [ :name ] == 'deprecatedMutation' }
163+ assert deprecated_mutation [ :is_deprecated ] , "deprecatedMutation should be marked as deprecated"
164+ assert_equal "Use createUser instead" , deprecated_mutation [ :deprecation_reason ] , "deprecatedMutation should have correct deprecation reason"
165+ end
126166end
0 commit comments