Class: GQLi::Introspection
- Inherits:
-
Object
- Object
- GQLi::Introspection
- Extended by:
- DSL
- Defined in:
- lib/gqli/introspection.rb
Overview
Introspection schema and validator
Constant Summary collapse
- TypeRef =
Specific type kind introspection fragment
fragment('TypeRef', '__Type') { kind name ofType { kind name ofType { kind name ofType { kind name } } } }
- InputValue =
Input value introspection fragment
fragment('InputValue', '__InputValue') { name description type { ___ TypeRef } defaultValue }
- FullType =
Type introspection fragment
fragment('FullType', '__Type') { kind name description fields(includeDeprecated: true) { name description args { ___ InputValue } type { ___ TypeRef } isDeprecated deprecationReason } inputFields { ___ InputValue } interfaces { ___ TypeRef } enumValues(includeDeprecated: true) { name description isDeprecated deprecationReason } possibleTypes { ___ TypeRef } }
- IntrospectionQuery =
Query for fetching the complete schema
query { __schema { queryType { name } mutationType { name } subscriptionType { name } types { ___ FullType } directives { name description args { ___ InputValue } onOperation onFragment onField } } }
Instance Attribute Summary collapse
-
#mutation_type ⇒ Object
readonly
Returns the value of attribute mutation_type.
-
#query_type ⇒ Object
readonly
Returns the value of attribute query_type.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
-
#subscription_type ⇒ Object
readonly
Returns the value of attribute subscription_type.
-
#types ⇒ Object
readonly
Returns the value of attribute types.
Instance Method Summary collapse
-
#initialize(client) ⇒ Introspection
constructor
A new instance of Introspection.
-
#valid?(query) ⇒ Boolean
Returns wether the query is valid or not.
Methods included from DSL
fragment, fragment, query, query
Constructor Details
#initialize(client) ⇒ Introspection
Returns a new instance of Introspection
80 81 82 83 84 85 86 |
# File 'lib/gqli/introspection.rb', line 80 def initialize(client) @schema = client.execute!(IntrospectionQuery).data.__schema @query_type = schema.queryType @mutation_type = schema.mutationType @subscription_type = schema.subscriptionType @types = schema.types end |
Instance Attribute Details
#mutation_type ⇒ Object (readonly)
Returns the value of attribute mutation_type
78 79 80 |
# File 'lib/gqli/introspection.rb', line 78 def mutation_type @mutation_type end |
#query_type ⇒ Object (readonly)
Returns the value of attribute query_type
78 79 80 |
# File 'lib/gqli/introspection.rb', line 78 def query_type @query_type end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema
78 79 80 |
# File 'lib/gqli/introspection.rb', line 78 def schema @schema end |
#subscription_type ⇒ Object (readonly)
Returns the value of attribute subscription_type
78 79 80 |
# File 'lib/gqli/introspection.rb', line 78 def subscription_type @subscription_type end |
#types ⇒ Object (readonly)
Returns the value of attribute types
78 79 80 |
# File 'lib/gqli/introspection.rb', line 78 def types @types end |
Instance Method Details
#valid?(query) ⇒ Boolean
Returns wether the query is valid or not
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/gqli/introspection.rb', line 89 def valid?(query) return false unless query.is_a?(Query) query_type = types.find { |t| t.name.casecmp('query').zero? } query.__nodes.each do |node| return false unless valid_node?(query_type, node) end true end |