diff --git a/lib/graphql_schema.rb b/lib/graphql_schema.rb index b6f9cd3..01f221a 100644 --- a/lib/graphql_schema.rb +++ b/lib/graphql_schema.rb @@ -24,6 +24,10 @@ def types @types ||= @hash.fetch('types').map{ |type_hash| TypeDefinition.new(type_hash) }.sort_by(&:name) end + def types_by_name + @types_by_name ||= types.map { |type| [type.name, type] }.to_h + end + module NamedHash def name @hash.fetch('name') diff --git a/test/graphql_schema_test.rb b/test/graphql_schema_test.rb index 6f5ea6e..18bea7d 100644 --- a/test/graphql_schema_test.rb +++ b/test/graphql_schema_test.rb @@ -134,6 +134,11 @@ def test_fields_by_name assert_equal nil, type('QueryRoot').fields_by_name['does_not_exist'] end + def test_type_by_name + assert_equal type('SetIntegerInput'), @schema.types_by_name['SetIntegerInput'] + assert_equal nil, @schema.types_by_name['IDoNotExist'] + end + def test_description assert_equal 'Time since epoch in seconds', type('Time').description assert_nil type('StringEntry').description