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
4 changes: 4 additions & 0 deletions lib/graphql_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ def fields(include_deprecated: false)
include_deprecated ? @fields : @fields.reject(&:deprecated?)
end

def fields_by_name
@fields_by_name ||= fields(include_deprecated: true).map{ |field| [field.name, field]}.to_h
end

def input_fields
@input_fields ||= @hash.fetch('inputFields').map{ |field_hash| InputValue.new(field_hash) }
end
Expand Down
10 changes: 10 additions & 0 deletions test/graphql_schema_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ def test_enum?
assert_equal false, field('QueryRoot', 'keys').type.enum?
end

def test_fields_by_name
assert_equal get_string_field, type('QueryRoot').fields_by_name['get_string']
assert_equal get_field, type('QueryRoot').fields_by_name['get']
assert_equal nil, type('QueryRoot').fields_by_name['does_not_exist']
end

def test_description
assert_equal 'Time since epoch in seconds', type('Time').description
assert_nil type('StringEntry').description
Expand Down Expand Up @@ -189,6 +195,10 @@ def query_root
type('QueryRoot')
end

def get_field
field('QueryRoot', 'get')
end

def get_string_field
field('QueryRoot', 'get_string')
end
Expand Down