Class: GQLi::Introspection

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_typeObject (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_typeObject (readonly)

Returns the value of attribute query_type



78
79
80
# File 'lib/gqli/introspection.rb', line 78

def query_type
  @query_type
end

#schemaObject (readonly)

Returns the value of attribute schema



78
79
80
# File 'lib/gqli/introspection.rb', line 78

def schema
  @schema
end

#subscription_typeObject (readonly)

Returns the value of attribute subscription_type



78
79
80
# File 'lib/gqli/introspection.rb', line 78

def subscription_type
  @subscription_type
end

#typesObject (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

Returns:

  • (Boolean)


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