Class: GraphQL::Client::Definition
- Inherits:
-
Module
- Object
- Module
- GraphQL::Client::Definition
- Defined in:
- lib/graphql/client/definition.rb
Overview
Definitions are constructed by Client.parse and wrap a parsed AST of the query string as well as hold references to any external query definition dependencies.
Definitions MUST be assigned to a constant.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#definition_node ⇒ Object
readonly
Internal: Get underlying operation or fragment defintion AST node for definition.
-
#document ⇒ Object
readonly
Public: Get document with only the definitions needed to perform this operation.
-
#document_types ⇒ Object
readonly
Internal: Mapping of document nodes to schema types.
-
#enforce_collocated_callers ⇒ Object
readonly
Returns the value of attribute enforce_collocated_callers.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
-
#source_location ⇒ Object
readonly
Public: Returns the Ruby source filename and line number containing this definition was not defined in Ruby.
Class Method Summary collapse
Instance Method Summary collapse
-
#definition_name ⇒ Object
Public: Global name of definition in client document.
-
#initialize(node:, document:, schema:, document_types:, source_location:, enforce_collocated_callers:) ⇒ Definition
constructor
A new instance of Definition.
- #new(*args) ⇒ Object
- #type ⇒ Object
Constructor Details
permalink #initialize(node:, document:, schema:, document_types:, source_location:, enforce_collocated_callers:) ⇒ Definition
Returns a new instance of Definition.
21 22 23 24 25 26 27 28 |
# File 'lib/graphql/client/definition.rb', line 21 def initialize(node:, document:, schema:, document_types:, source_location:, enforce_collocated_callers:) @definition_node = node @document = document @schema = schema @document_types = document_types @source_location = source_location @enforce_collocated_callers = enforce_collocated_callers end |
Instance Attribute Details
permalink #definition_node ⇒ Object (readonly)
Internal: Get underlying operation or fragment defintion AST node for definition.
Returns OperationDefinition or FragmentDefinition object.
34 35 36 |
# File 'lib/graphql/client/definition.rb', line 34 def definition_node @definition_node end |
permalink #document ⇒ Object (readonly)
Public: Get document with only the definitions needed to perform this operation.
Returns GraphQL::Language::Nodes::Document with one OperationDefinition and any FragmentDefinition dependencies.
58 59 60 |
# File 'lib/graphql/client/definition.rb', line 58 def document @document end |
permalink #document_types ⇒ Object (readonly)
Internal: Mapping of document nodes to schema types.
61 62 63 |
# File 'lib/graphql/client/definition.rb', line 61 def document_types @document_types end |
permalink #enforce_collocated_callers ⇒ Object (readonly)
Returns the value of attribute enforce_collocated_callers.
71 72 73 |
# File 'lib/graphql/client/definition.rb', line 71 def enforce_collocated_callers @enforce_collocated_callers end |
permalink #schema ⇒ Object (readonly)
Returns the value of attribute schema.
63 64 65 |
# File 'lib/graphql/client/definition.rb', line 63 def schema @schema end |
permalink #source_location ⇒ Object (readonly)
Public: Returns the Ruby source filename and line number containing this definition was not defined in Ruby.
Returns Array pair of [String, Fixnum].
69 70 71 |
# File 'lib/graphql/client/definition.rb', line 69 def source_location @source_location end |
Class Method Details
permalink .for(node:, **kargs) ⇒ Object
[View source]
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/graphql/client/definition.rb', line 10 def self.for(node:, **kargs) case node when Language::Nodes::OperationDefinition OperationDefinition.new(node: node, **kargs) when Language::Nodes::FragmentDefinition FragmentDefinition.new(node: node, **kargs) else raise TypeError, "expected node to be a definition type, but was #{node.class}" end end |
Instance Method Details
permalink #definition_name ⇒ Object
Public: Global name of definition in client document.
Returns a GraphQL safe name of the Ruby constant String.
"Users::UserQuery" #=> "Users__UserQuery"
Returns String.
43 44 45 46 47 48 49 50 51 |
# File 'lib/graphql/client/definition.rb', line 43 def definition_name return @definition_name if defined?(@definition_name) if name @definition_name = name.gsub("::", "__").freeze else "#{self.class.name}_#{object_id}".gsub("::", "__").freeze end end |
permalink #new(*args) ⇒ Object
[View source]
73 74 75 |
# File 'lib/graphql/client/definition.rb', line 73 def new(*args) type.new(*args) end |
permalink #type ⇒ Object
[View source]
77 78 79 80 |
# File 'lib/graphql/client/definition.rb', line 77 def type # TODO: Fix type indirection @type ||= GraphQL::Client::QueryResult.wrap(self, definition_node, name: "#{name}.type") end |