Repository: brettchalupa/graphql-docs (Ruby)

Issue:
Deprecation notices are not added for query fields
**Describe the bug**
Deprecation notices are not rendered for deprecated query fields.

**To Reproduce**
Steps to reproduce the behavior:

Generate docs for a query like this:

```ruby
class MySchema < GraphQL::Schema
  query(Types::QueryType)
end

class QueryType < Types::BaseObject
  field :my_query,
    MyInterface.connection_type,
    null: true,
    deprecation_reason: "This deprecation reason should render on the page."
end
```

**Expected behavior**
"This deprecation reason should render on the page." should render on the generated page.

**Additional context**
- Version of gem being used: 5.2.0
- Ruby version: 3.4.1



Discussion:
Thanks for logging this, will investigate and try to fix when time allows!
This improvement will go out in the ~v5.3~ v6.0 gem release. I'm going to see if there are some other improvements to include and try to release end of week. 👍 
Awesome, thanks!



Patch:
diff --git a/lib/graphql-docs/parser.rb b/lib/graphql-docs/parser.rb
index e345d1c..2a561e6 100644
--- a/lib/graphql-docs/parser.rb
+++ b/lib/graphql-docs/parser.rb
@@ -60,6 +60,10 @@ def parse
               h[:notices] = @options[:notices].call([object.graphql_name, query.graphql_name].join('.'))
               h[:name] = query.graphql_name
               h[:description] = query.description
+              if query.respond_to?(:deprecation_reason) && !query.deprecation_reason.nil?
+                h[:is_deprecated] = true
+                h[:deprecation_reason] = query.deprecation_reason
+              end
               h[:arguments], = fetch_fields(query.arguments, [object.graphql_name, query.graphql_name].join('.'))
 
               return_type = query.type
@@ -80,6 +84,10 @@ def parse
               h[:notices] = @options[:notices].call([object.graphql_name, mutation.graphql_name].join('.'))
               h[:name] = mutation.graphql_name
               h[:description] = mutation.description
+              if mutation.respond_to?(:deprecation_reason) && !mutation.deprecation_reason.nil?
+                h[:is_deprecated] = true
+                h[:deprecation_reason] = mutation.deprecation_reason
+              end
               h[:input_fields], = fetch_fields(mutation.arguments, [object.graphql_name, mutation.graphql_name].join('.'))
 
               return_type = mutation.type


Test patch:
diff --git a/test/graphql-docs/parser_test.rb b/test/graphql-docs/parser_test.rb
index 91a1a09..c0757ae 100644
--- a/test/graphql-docs/parser_test.rb
+++ b/test/graphql-docs/parser_test.rb
@@ -123,4 +123,44 @@ def test_deprecations
     assert fields[1][:is_deprecated]
     assert fields[2][:arguments][0][:is_deprecated]
   end
+
+  def test_query_field_deprecation
+    schema = MySchema
+    results = GraphQLDocs::Parser.new(schema, {}).parse
+
+    query_types = results[:query_types]
+
+    # Find the myField query
+    my_field = query_types.find { |q| q[:name] == 'myField' }
+    refute my_field[:is_deprecated], "myField should not be deprecated"
+    assert_nil my_field[:deprecation_reason], "myField should not have a deprecation reason"
+
+    # Find the deprecatedField query
+    deprecated_field = query_types.find { |q| q[:name] == 'deprecatedField' }
+    assert deprecated_field[:is_deprecated], "deprecatedField should be marked as deprecated"
+    assert_equal "Not useful any more", deprecated_field[:deprecation_reason], "deprecatedField should have correct deprecation reason"
+
+    # Find the fieldWithDeprecatedArg query
+    field_with_deprecated_arg = query_types.find { |q| q[:name] == 'fieldWithDeprecatedArg' }
+    refute field_with_deprecated_arg[:is_deprecated], "fieldWithDeprecatedArg itself should not be deprecated"
+    assert field_with_deprecated_arg[:arguments][0][:is_deprecated], "myArg should be marked as deprecated"
+    assert_equal "Not useful any more", field_with_deprecated_arg[:arguments][0][:deprecation_reason], "myArg should have correct deprecation reason"
+  end
+
+  def test_mutation_field_deprecation
+    schema = MySchema
+    results = GraphQLDocs::Parser.new(schema, {}).parse
+
+    mutation_types = results[:mutation_types]
+
+    # Find the createUser mutation
+    create_user = mutation_types.find { |m| m[:name] == 'createUser' }
+    refute create_user[:is_deprecated], "createUser should not be deprecated"
+    assert_nil create_user[:deprecation_reason], "createUser should not have a deprecation reason"
+
+    # Find the deprecatedMutation
+    deprecated_mutation = mutation_types.find { |m| m[:name] == 'deprecatedMutation' }
+    assert deprecated_mutation[:is_deprecated], "deprecatedMutation should be marked as deprecated"
+    assert_equal "Use createUser instead", deprecated_mutation[:deprecation_reason], "deprecatedMutation should have correct deprecation reason"
+  end
 end
diff --git a/test/test_helper.rb b/test/test_helper.rb
index c2181e0..7c4ab73 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -34,6 +34,13 @@ class QueryType < GraphQL::Schema::Object
   end
 end
 
+class MutationType < GraphQL::Schema::Object
+  field :create_user, Int, null: false
+
+  field :deprecated_mutation, Int, null: false, deprecation_reason: "Use createUser instead"
+end
+
 class MySchema < GraphQL::Schema
   query QueryType
+  mutation MutationType
 end