Class: GraphQL::Schema
- Inherits:
-
Object
- Object
- GraphQL::Schema
- Defined in:
- lib/graphql/schema.rb,
lib/graphql/schema/type_map.rb
Overview
A GraphQL schema which may be queried with Query.
Defined Under Namespace
Classes: EachItemValidator, FieldValidator, ImplementationValidator, InvalidTypeError, TypeMap, TypeReducer, TypeValidator
Constant Summary collapse
- DIRECTIVES =
[GraphQL::Directive::SkipDirective, GraphQL::Directive::IncludeDirective]
- DYNAMIC_FIELDS =
["__type", "__typename", "__schema"]
Instance Attribute Summary collapse
-
#directives ⇒ Object
readonly
Returns the value of attribute directives.
-
#mutation ⇒ Object
readonly
Returns the value of attribute mutation.
-
#mutation_execution_strategy ⇒ Object
Override these if you don’t want the default executor:.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#query_execution_strategy ⇒ Object
Override these if you don’t want the default executor:.
-
#static_validator ⇒ Object
readonly
Returns the value of attribute static_validator.
Instance Method Summary collapse
-
#get_field(parent_type, field_name) ⇒ Object
Resolve field named ‘field_name` for type `parent_type`.
-
#initialize(query:, mutation: nil) ⇒ Schema
constructor
A new instance of Schema.
-
#types ⇒ Object
A ‘{ name => type }` hash of types in this schema.
Constructor Details
#initialize(query:, mutation: nil) ⇒ Schema
Returns a new instance of Schema.
13 14 15 16 17 18 19 20 21 |
# File 'lib/graphql/schema.rb', line 13 def initialize(query:, mutation: nil) @query = query @mutation = mutation @directives = DIRECTIVES.reduce({}) { |m, d| m[d.name] = d; m } @static_validator = GraphQL::StaticValidation::Validator.new(schema: self) # Default to the built-in execution strategy: self.query_execution_strategy = GraphQL::Query::SerialExecution self.mutation_execution_strategy = GraphQL::Query::SerialExecution end |
Instance Attribute Details
#directives ⇒ Object (readonly)
Returns the value of attribute directives.
6 7 8 |
# File 'lib/graphql/schema.rb', line 6 def directives @directives end |
#mutation ⇒ Object (readonly)
Returns the value of attribute mutation.
6 7 8 |
# File 'lib/graphql/schema.rb', line 6 def mutation @mutation end |
#mutation_execution_strategy ⇒ Object
Override these if you don’t want the default executor:
8 9 10 |
# File 'lib/graphql/schema.rb', line 8 def mutation_execution_strategy @mutation_execution_strategy end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
6 7 8 |
# File 'lib/graphql/schema.rb', line 6 def query @query end |
#query_execution_strategy ⇒ Object
Override these if you don’t want the default executor:
8 9 10 |
# File 'lib/graphql/schema.rb', line 8 def query_execution_strategy @query_execution_strategy end |
#static_validator ⇒ Object (readonly)
Returns the value of attribute static_validator.
6 7 8 |
# File 'lib/graphql/schema.rb', line 6 def static_validator @static_validator end |
Instance Method Details
#get_field(parent_type, field_name) ⇒ Object
Resolve field named ‘field_name` for type `parent_type`. Handles dynamic fields `__typename`, `__type` and `__schema`, too
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/graphql/schema.rb', line 31 def get_field(parent_type, field_name) defined_field = parent_type.fields[field_name] if defined_field defined_field elsif field_name == "__typename" GraphQL::Introspection::TypenameField.create(parent_type) elsif field_name == "__schema" && parent_type == query GraphQL::Introspection::SchemaField.create(self) elsif field_name == "__type" && parent_type == query GraphQL::Introspection::TypeByNameField.create(self.types) else nil end end |
#types ⇒ Object
A ‘{ name => type }` hash of types in this schema
25 26 27 |
# File 'lib/graphql/schema.rb', line 25 def types @types ||= TypeReducer.find_all([query, mutation, GraphQL::Introspection::SchemaType].compact) end |