Class: GraphQL::Schema
- Inherits:
-
Object
- Object
- GraphQL::Schema
- Defined in:
- lib/graph_ql/schema.rb
Defined Under Namespace
Classes: EachItemValidator, FieldValidator, ImplementationValidator, SchemaValidator, TypeReducer, TypeValidator
Constant Summary collapse
- DIRECTIVES =
[GraphQL::SkipDirective, GraphQL::IncludeDirective]
Instance Attribute Summary collapse
-
#directives ⇒ Object
readonly
Returns the value of attribute directives.
-
#mutation ⇒ Object
readonly
Returns the value of attribute mutation.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#static_validator ⇒ Object
readonly
Returns the value of attribute static_validator.
Instance Method Summary collapse
-
#initialize(query:, mutation:) ⇒ Schema
constructor
A new instance of Schema.
- #types ⇒ Object
Constructor Details
#initialize(query:, mutation:) ⇒ Schema
Returns a new instance of Schema.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/graph_ql/schema.rb', line 5 def initialize(query:, mutation:) # Add fields to this query root for introspection: query.fields = query.fields.merge({ "__type" => GraphQL::Field.new do |f, type, field, arg| f.description("A type in the GraphQL system") f.arguments({name: arg.build(type: !type.String)}) f.type(!GraphQL::Introspection::TypeType) f.resolve -> (o, a, c) { self.types[a["name"]] } end, "__schema" => GraphQL::Field.new do |f| f.description("This GraphQL schema") f.type(!GraphQL::Introspection::SchemaType) f.resolve -> (o, a, c) { self } end }) @query = query @mutation = mutation @directives = DIRECTIVES.reduce({}) { |m, d| m[d.name] = d; m } @static_validator = GraphQL::StaticValidation::Validator.new(schema: self) errors = SchemaValidator.new.validate(self) if errors.any? raise("Schema is invalid: \n#{errors.join("\n")}") end end |
Instance Attribute Details
#directives ⇒ Object (readonly)
Returns the value of attribute directives.
4 5 6 |
# File 'lib/graph_ql/schema.rb', line 4 def directives @directives end |
#mutation ⇒ Object (readonly)
Returns the value of attribute mutation.
4 5 6 |
# File 'lib/graph_ql/schema.rb', line 4 def mutation @mutation end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
4 5 6 |
# File 'lib/graph_ql/schema.rb', line 4 def query @query end |
#static_validator ⇒ Object (readonly)
Returns the value of attribute static_validator.
4 5 6 |
# File 'lib/graph_ql/schema.rb', line 4 def static_validator @static_validator end |
Instance Method Details
#types ⇒ Object
32 33 34 |
# File 'lib/graph_ql/schema.rb', line 32 def types @types ||= TypeReducer.new(query, {}).result end |