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 }
      locations
    }
  }
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DSL

enum, enum, fragment, fragment, mutation, mutation, query, query, subscription, subscription

Constructor Details

#initialize(client) ⇒ Introspection

Returns a new instance of Introspection.



79
80
81
82
83
84
85
# File 'lib/gqli/introspection.rb', line 79

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.



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

def mutation_type
  @mutation_type
end

#query_typeObject (readonly)

Returns the value of attribute query_type.



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

def query_type
  @query_type
end

#schemaObject (readonly)

Returns the value of attribute schema.



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

def schema
  @schema
end

#subscription_typeObject (readonly)

Returns the value of attribute subscription_type.



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

def subscription_type
  @subscription_type
end

#typesObject (readonly)

Returns the value of attribute types.



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

def types
  @types
end

Instance Method Details

#valid?(query) ⇒ Boolean

Returns if the query is valid

Returns:

  • (Boolean)


93
94
95
# File 'lib/gqli/introspection.rb', line 93

def valid?(query)
  validate(query).valid?
end

#validate(query) ⇒ Object

Returns the evaluated validation for a query



88
89
90
# File 'lib/gqli/introspection.rb', line 88

def validate(query)
  Validation.new(self, query)
end