Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/graphql_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ def subfields?

class TypeDefinition < Type
def fields(include_deprecated: false)
return unless @hash.fetch('fields')
@fields ||= @hash.fetch('fields').map{ |field_hash| Field.new(field_hash) }
include_deprecated ? @fields : @fields.reject(&:deprecated?)
end
Expand Down
4 changes: 4 additions & 0 deletions test/graphql_schema_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ def test_upcase_name
assert_equal 'NOT_FOUND', not_found_value.upcase_name
end

def test_nil_fields
assert_nil type('KeyType').fields
end

def test_deprecated_fields
deprecated = query_root.fields(include_deprecated: true) - query_root.fields
assert_equal %w(get), deprecated.map(&:name)
Expand Down