Module: GraphQL

Defined in:
lib/graphql.rb,
lib/graphql/version.rb,
lib/graphql/language.rb,
lib/graphql/language.rb,
lib/graphql/scalar_type.rb,
lib/graphql/introspection.rb,
lib/graphql/query/executor.rb,
lib/graphql/definition_helpers.rb,
lib/graphql/query/base_execution.rb,
lib/graphql/query/serial_execution.rb,
lib/graphql/query/value_resolution.rb,
lib/graphql/query/serial_execution/field_resolution.rb,
lib/graphql/query/serial_execution/operation_resolution.rb,
lib/graphql/query/serial_execution/selection_resolution.rb,
lib/graphql/query/base_execution/selected_object_resolution.rb,
lib/graphql/query/serial_execution/fragment_spread_resolution.rb,
lib/graphql/query/serial_execution/inline_fragment_resolution.rb

Defined Under Namespace

Modules: DefinitionHelpers, Introspection, Language, StaticValidation, TypeKinds Classes: Argument, Directive, EnumType, Field, InputObjectType, InterfaceType, ListType, NonNullType, ObjectType, Query, Repl, ScalarType, Schema, UnionType

Constant Summary collapse

ID_TYPE =
GraphQL::ScalarType.define do
  name "ID"
  coerce -> (value) { value.to_s }
end
VERSION =
"0.7.1"
INT_TYPE =
GraphQL::ScalarType.define do
  name "Int"
  coerce -> (value) { value.is_a?(Numeric) ? value.to_i : nil }
end
TRANSFORM =
GraphQL::Language::Transform.new
PARSER =
GraphQL::Language::Parser.new
FLOAT_TYPE =
GraphQL::ScalarType.define do
  name "Float"
  coerce -> (value) do
    value.respond_to?(:to_f) ? value.to_f : nil
  end
end
STRING_TYPE =
GraphQL::ScalarType.define do
  name "String"
  coerce -> (value) { value.to_s }
end
BOOLEAN_TYPE =
GraphQL::ScalarType.define do
  name "Boolean"
  coerce -> (value) { !!value }
end

Class Method Summary collapse

Class Method Details

.parse(string, as: nil) ⇒ GraphQL::Language::Nodes::Document

Turn a query string into an AST

Parameters:

  • string (String)

    a GraphQL query string

  • as (Symbol) (defaults to: nil)

    If you want to use this to parse some piece of a document, pass the rule name (from Parser)

Returns:


10
11
12
13
14
15
16
17
# File 'lib/graphql.rb', line 10

def self.parse(string, as: nil)
  parser = as ? GraphQL::PARSER.send(as) : GraphQL::PARSER
  tree = parser.parse(string)
  GraphQL::TRANSFORM.apply(tree)
rescue Parslet::ParseFailed => error
  line, col = error.cause.source.line_and_column
  raise [error.message, line, col, string].join(", ")
end