Class: Graphlyte::SchemaQuery::Query
- Inherits:
-
Object
- Object
- Graphlyte::SchemaQuery::Query
- Defined in:
- lib/graphlyte/schema_query.rb
Overview
Builder for a schema query
Instance Attribute Summary collapse
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
-
#dsl ⇒ Object
readonly
Returns the value of attribute dsl.
Instance Method Summary collapse
- #build ⇒ Object
- #enums_fragment ⇒ Object
- #fields_fragment ⇒ Object
- #full_type_fragment ⇒ Object
-
#initialize ⇒ Query
constructor
A new instance of Query.
- #input_value_fragment ⇒ Object
- #query_directives(schema) ⇒ Object
- #select_type_reference(node, depth: 0) ⇒ Object
- #type_ref_fragment ⇒ Object
Constructor Details
Instance Attribute Details
#doc ⇒ Object (readonly)
Returns the value of attribute doc.
14 15 16 |
# File 'lib/graphlyte/schema_query.rb', line 14 def doc @doc end |
#dsl ⇒ Object (readonly)
Returns the value of attribute dsl.
14 15 16 |
# File 'lib/graphlyte/schema_query.rb', line 14 def dsl @dsl end |
Instance Method Details
#build ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/graphlyte/schema_query.rb', line 21 def build @build ||= dsl.query('Schema', doc) do |q| q.__schema do |s| s.query_type(&:name) s.mutation_type(&:name) s.subscription_type(&:name) s.types(full_type_fragment) query_directives(s) end end end |
#enums_fragment ⇒ Object
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/graphlyte/schema_query.rb', line 66 def enums_fragment @enums_fragment ||= dsl.fragment(on: '__Type', doc: doc) do |t| t.enum_values(include_deprecated: true) do |e| e.name e.description e.is_deprecated e.deprecation_reason end end end |
#fields_fragment ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/graphlyte/schema_query.rb', line 77 def fields_fragment @fields_fragment ||= dsl.fragment(on: '__Type', doc: doc) do |t| t.fields(include_deprecated: true) do |f| f.name f.description f.args(input_value_fragment) f.type(type_ref_fragment) f.is_deprecated f.deprecation_reason end end end |
#full_type_fragment ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/graphlyte/schema_query.rb', line 53 def full_type_fragment @full_type_fragment ||= dsl.fragment(on: '__Type', doc: doc) do |t| t.kind t.name t.description t << fields_fragment t.input_fields(input_value_fragment) t.interfaces(type_ref_fragment) t << enums_fragment t.possible_types(type_ref_fragment) end end |
#input_value_fragment ⇒ Object
90 91 92 93 94 95 96 97 |
# File 'lib/graphlyte/schema_query.rb', line 90 def input_value_fragment @input_value_fragment ||= dsl.fragment(on: '__InputValue', doc: doc) do |v| v.name v.description v.type type_ref_fragment v.default_value end end |
#query_directives(schema) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/graphlyte/schema_query.rb', line 33 def query_directives(schema) schema.directives do |d| d.name d.description d.args(input_value_fragment) end end |
#select_type_reference(node, depth: 0) ⇒ Object
47 48 49 50 51 |
# File 'lib/graphlyte/schema_query.rb', line 47 def select_type_reference(node, depth: 0) node.kind node.name node.of_type { |child| select_type_reference(child, depth: depth + 1) } if depth < 8 end |
#type_ref_fragment ⇒ Object
41 42 43 44 45 |
# File 'lib/graphlyte/schema_query.rb', line 41 def type_ref_fragment @type_ref_fragment ||= dsl.fragment(on: '__Type', doc: doc) do |t| select_type_reference(t) end end |