Class: GraphQLSchema
- Inherits:
-
Object
show all
- Defined in:
- lib/graphql_schema.rb,
lib/graphql_schema/version.rb
Defined Under Namespace
Modules: Deprecatable, NamedHash, WithArgs
Classes: Directive, EnumValue, Field, InputValue, Type, TypeDeclaration, TypeDefinition
Constant Summary
collapse
- VERSION =
"0.1.8"
Instance Method Summary
collapse
Constructor Details
#initialize(instrospection_result) ⇒ GraphQLSchema
Returns a new instance of GraphQLSchema.
5
6
7
|
# File 'lib/graphql_schema.rb', line 5
def initialize(instrospection_result)
@hash = instrospection_result.fetch('data').fetch('__schema')
end
|
Instance Method Details
#directives ⇒ Object
23
24
25
26
27
|
# File 'lib/graphql_schema.rb', line 23
def directives
@directives ||= @hash.fetch('directives').map do |directive|
Directive.new(directive)
end.sort_by(&:name)
end
|
#mutation_root_name ⇒ Object
17
18
19
20
21
|
# File 'lib/graphql_schema.rb', line 17
def mutation_root_name
if mutation_type = @hash.fetch('mutationType')
mutation_type.fetch('name')
end
end
|
#query_root_name ⇒ Object
13
14
15
|
# File 'lib/graphql_schema.rb', line 13
def query_root_name
@query_root_name ||= @hash.fetch('queryType').fetch('name')
end
|
#root_name?(type_name) ⇒ Boolean
9
10
11
|
# File 'lib/graphql_schema.rb', line 9
def root_name?(type_name)
type_name == query_root_name || type_name == mutation_root_name
end
|
#types ⇒ Object
29
30
31
|
# File 'lib/graphql_schema.rb', line 29
def types
@types ||= @hash.fetch('types').map{ |type_hash| TypeDefinition.new(type_hash) }.sort_by(&:name)
end
|
#types_by_name ⇒ Object
33
34
35
|
# File 'lib/graphql_schema.rb', line 33
def types_by_name
@types_by_name ||= types.map { |type| [type.name, type] }.to_h
end
|