Module: GraphQL

Defined in:
lib/graphql/parse_error.rb,
lib/graphql.rb,
lib/graphql/field.rb,
lib/graphql/query.rb,
lib/graphql/define.rb,
lib/graphql/filter.rb,
lib/graphql/schema.rb,
lib/graphql/tracing.rb,
lib/graphql/version.rb,
lib/graphql/argument.rb,
lib/graphql/function.rb,
lib/graphql/language.rb,
lib/graphql/backtrace.rb,
lib/graphql/base_type.rb,
lib/graphql/directive.rb,
lib/graphql/enum_type.rb,
lib/graphql/list_type.rb,
lib/graphql/rake_task.rb,
lib/graphql/relay/edge.rb,
lib/graphql/relay/node.rb,
lib/graphql/type_kinds.rb,
lib/graphql/union_type.rb,
lib/graphql/object_type.rb,
lib/graphql/scalar_type.rb,
lib/graphql/query/result.rb,
lib/graphql/field/resolve.rb,
lib/graphql/introspection.rb,
lib/graphql/non_null_type.rb,
lib/graphql/query/context.rb,
lib/graphql/schema/loader.rb,
lib/graphql/schema/warden.rb,
lib/graphql/subscriptions.rb,
lib/graphql/analysis_error.rb,
lib/graphql/coercion_error.rb,
lib/graphql/execution/lazy.rb,
lib/graphql/interface_type.rb,
lib/graphql/language/lexer.rb,
lib/graphql/language/nodes.rb,
lib/graphql/language/token.rb,
lib/graphql/name_validator.rb,
lib/graphql/query/executor.rb,
lib/graphql/relay/mutation.rb,
lib/graphql/schema/printer.rb,
lib/graphql/backtrace/table.rb,
lib/graphql/execution_error.rb,
lib/graphql/language/parser.rb,
lib/graphql/query/arguments.rb,
lib/graphql/query/variables.rb,
lib/graphql/relay/edge_type.rb,
lib/graphql/relay/page_info.rb,
lib/graphql/relay/range_add.rb,
lib/graphql/backtrace/tracer.rb,
lib/graphql/language/visitor.rb,
lib/graphql/schema/null_mask.rb,
lib/graphql/schema/traversal.rb,
lib/graphql/execution/execute.rb,
lib/graphql/execution/flatten.rb,
lib/graphql/input_object_type.rb,
lib/graphql/language/comments.rb,
lib/graphql/schema/validation.rb,
lib/graphql/execution/typecast.rb,
lib/graphql/invalid_name_error.rb,
lib/graphql/invalid_null_error.rb,
lib/graphql/query/null_context.rb,
lib/graphql/rake_task/validate.rb,
lib/graphql/runtime_type_error.rb,
lib/graphql/define/type_definer.rb,
lib/graphql/execution/multiplex.rb,
lib/graphql/language/generation.rb,
lib/graphql/query/literal_input.rb,
lib/graphql/subscriptions/event.rb,
lib/graphql/analysis/field_usage.rb,
lib/graphql/analysis/query_depth.rb,
lib/graphql/query/arguments_cache.rb,
lib/graphql/relay/base_connection.rb,
lib/graphql/relay/connection_type.rb,
lib/graphql/relay/mutation/result.rb,
lib/graphql/schema/possible_types.rb,
lib/graphql/string_encoding_error.rb,
lib/graphql/tracing/scout_tracing.rb,
lib/graphql/unresolved_type_error.rb,
lib/graphql/analysis/analyze_query.rb,
lib/graphql/analysis/reducer_state.rb,
lib/graphql/backtrace/traced_error.rb,
lib/graphql/define/assign_argument.rb,
lib/graphql/execution/lazy/resolve.rb,
lib/graphql/query/serial_execution.rb,
lib/graphql/relay/array_connection.rb,
lib/graphql/relay/mutation/resolve.rb,
lib/graphql/schema/base_64_encoder.rb,
lib/graphql/schema/type_expression.rb,
lib/graphql/backwards_compatibility.rb,
lib/graphql/relay/global_id_resolve.rb,
lib/graphql/schema/middleware_chain.rb,
lib/graphql/subscriptions/serialize.rb,
lib/graphql/analysis/max_query_depth.rb,
lib/graphql/backtrace/inspect_result.rb,
lib/graphql/define/assign_connection.rb,
lib/graphql/define/assign_enum_value.rb,
lib/graphql/relay/connection_resolve.rb,
lib/graphql/schema/rescue_middleware.rb,
lib/graphql/tracing/platform_tracing.rb,
lib/graphql/tracing/skylight_tracing.rb,
lib/graphql/analysis/query_complexity.rb,
lib/graphql/define/instance_definable.rb,
lib/graphql/define/non_null_with_bang.rb,
lib/graphql/language/definition_slice.rb,
lib/graphql/query/validation_pipeline.rb,
lib/graphql/relay/relation_connection.rb,
lib/graphql/schema/default_type_error.rb,
lib/graphql/schema/invalid_type_error.rb,
lib/graphql/schema/timeout_middleware.rb,
lib/graphql/schema/unique_within_type.rb,
lib/graphql/static_validation/message.rb,
lib/graphql/tracing/appsignal_tracing.rb,
lib/graphql/tracing/new_relic_tracing.rb,
lib/graphql/define/assign_object_field.rb,
lib/graphql/define/no_definition_error.rb,
lib/graphql/execution/directive_checks.rb,
lib/graphql/introspection/schema_field.rb,
lib/graphql/schema/catchall_middleware.rb,
lib/graphql/schema/default_parse_error.rb,
lib/graphql/define/defined_object_proxy.rb,
lib/graphql/relay/edges_instrumentation.rb,
lib/graphql/static_validation/all_rules.rb,
lib/graphql/static_validation/validator.rb,
lib/graphql/internal_representation/node.rb,
lib/graphql/introspection/typename_field.rb,
lib/graphql/schema/build_from_definition.rb,
lib/graphql/static_validation/type_stack.rb,
lib/graphql/analysis/max_query_complexity.rb,
lib/graphql/define/assign_global_id_field.rb,
lib/graphql/internal_representation/print.rb,
lib/graphql/internal_representation/scope.rb,
lib/graphql/internal_representation/visit.rb,
lib/graphql/query/input_validation_result.rb,
lib/graphql/subscriptions/instrumentation.rb,
lib/graphql/execution/lazy/lazy_method_map.rb,
lib/graphql/relay/mutation/instrumentation.rb,
lib/graphql/define/assign_mutation_function.rb,
lib/graphql/internal_representation/rewrite.rb,
lib/graphql/query/variable_validation_error.rb,
lib/graphql/internal_representation/document.rb,
lib/graphql/introspection/type_by_name_field.rb,
lib/graphql/relay/connection_instrumentation.rb,
lib/graphql/static_validation/literal_validator.rb,
lib/graphql/static_validation/validation_context.rb,
lib/graphql/compatibility/execution_specification.rb,
lib/graphql/static_validation/arguments_validator.rb,
lib/graphql/query/serial_execution/field_resolution.rb,
lib/graphql/query/serial_execution/value_resolution.rb,
lib/graphql/compatibility/query_parser_specification.rb,
lib/graphql/schema/build_from_definition/resolve_map.rb,
lib/graphql/subscriptions/action_cable_subscriptions.rb,
lib/graphql/compatibility/schema_parser_specification.rb,
lib/graphql/static_validation/definition_dependencies.rb,
lib/graphql/static_validation/rules/fields_will_merge.rb,
lib/graphql/compatibility/lazy_execution_specification.rb,
lib/graphql/static_validation/rules/fragments_are_used.rb,
lib/graphql/query/serial_execution/operation_resolution.rb,
lib/graphql/query/serial_execution/selection_resolution.rb,
lib/graphql/static_validation/rules/fragments_are_named.rb,
lib/graphql/static_validation/rules/fragment_types_exist.rb,
lib/graphql/static_validation/rules/fragments_are_finite.rb,
lib/graphql/static_validation/rules/mutation_root_exists.rb,
lib/graphql/tracing/active_support_notifications_tracing.rb,
lib/graphql/static_validation/rules/arguments_are_defined.rb,
lib/graphql/static_validation/rules/directives_are_defined.rb,
lib/graphql/static_validation/rules/subscription_root_exists.rb,
lib/graphql/static_validation/rules/fragment_names_are_unique.rb,
lib/graphql/static_validation/rules/operation_names_are_valid.rb,
lib/graphql/static_validation/rules/variables_are_input_types.rb,
lib/graphql/static_validation/rules/fields_are_defined_on_type.rb,
lib/graphql/static_validation/rules/no_definitions_are_present.rb,
lib/graphql/static_validation/rules/variable_usages_are_allowed.rb,
lib/graphql/compatibility/execution_specification/counter_schema.rb,
lib/graphql/static_validation/rules/fragment_spreads_are_possible.rb,
lib/graphql/compatibility/lazy_execution_specification/lazy_schema.rb,
lib/graphql/static_validation/rules/required_arguments_are_present.rb,
lib/graphql/static_validation/rules/unique_directives_per_location.rb,
lib/graphql/static_validation/rules/variables_are_used_and_defined.rb,
lib/graphql/schema/build_from_definition/resolve_map/default_resolve.rb,
lib/graphql/static_validation/rules/argument_literals_are_compatible.rb,
lib/graphql/static_validation/rules/fragments_are_on_composite_types.rb,
lib/graphql/compatibility/query_parser_specification/query_assertions.rb,
lib/graphql/static_validation/rules/directives_are_in_valid_locations.rb,
lib/graphql/compatibility/execution_specification/specification_schema.rb,
lib/graphql/static_validation/rules/fields_have_appropriate_selections.rb,
lib/graphql/compatibility/query_parser_specification/parse_error_specification.rb,
lib/graphql/static_validation/rules/variable_default_values_are_correctly_typed.rb

Overview

test_via: ../subscriptions.rb

Defined Under Namespace

Modules: Analysis, BackwardsCompatibility, Compatibility, Define, Delegate, Execution, InternalRepresentation, Introspection, Language, Relay, StaticValidation, Tracing, TypeKinds Classes: AnalysisError, Argument, Backtrace, BaseType, CoercionError, Directive, DoubleNonNullTypeError, EnumType, Error, ExecutionError, Field, Filter, Function, InputObjectType, InterfaceType, InvalidNameError, InvalidNullError, ListType, NameValidator, NonNullType, ObjectType, ParseError, Query, RakeTask, RuntimeTypeError, ScalarType, Schema, StringEncodingError, Subscriptions, UnionType, UnresolvedTypeError

Constant Summary

ID_TYPE =
GraphQL::ScalarType.define do
  name "ID"
  description "Represents a unique identifier that is Base64 obfuscated. It is often used to refetch an object or as key for a cache. The ID type appears in a JSON response as a String; however, it is not intended to be human-readable. When expected as an input type, any string (such as `\"VXNlci0xMA==\"`) or integer (such as `4`) input value will be accepted as an ID."

  coerce_result ->(value, _ctx) { value.to_s }
  coerce_input ->(value, _ctx) {
    case value
    when String, Integer
      value.to_s
    else
      nil
    end
  }
  default_scalar true
end
VERSION =
"1.7.4"
INT_TYPE =
GraphQL::ScalarType.define do
  name "Int"
  description "Represents non-fractional signed whole numeric values. Int can represent values between -(2^31) and 2^31 - 1."

  coerce_input ->(value, _ctx) { value.is_a?(Numeric) ? value.to_i : nil }
  coerce_result ->(value, _ctx) { value.to_i }
  default_scalar true
end
FLOAT_TYPE =
GraphQL::ScalarType.define do
  name "Float"
  description "Represents signed double-precision fractional values as specified by [IEEE 754](http://en.wikipedia.org/wiki/IEEE_floating_point)."

  coerce_input ->(value, _ctx) { value.is_a?(Numeric) ? value.to_f : nil }
  coerce_result ->(value, _ctx) { value.to_f }
  default_scalar true
end
STRING_TYPE =
GraphQL::ScalarType.define do
  name "String"
  description "Represents textual data as UTF-8 character sequences. This type is most often used by GraphQL to represent free-form human-readable text."

  coerce_result ->(value, ctx) {
    begin
      str = value.to_s
      str.encoding == Encoding::UTF_8 ? str : str.encode(Encoding::UTF_8)
    rescue EncodingError
      err = GraphQL::StringEncodingError.new(str)
      ctx.schema.type_error(err, ctx)
    end
  }

  coerce_input ->(value, _ctx) { value.is_a?(String) ? value : nil }
  default_scalar true
end
BOOLEAN_TYPE =
GraphQL::ScalarType.define do
  name "Boolean"
  description "Represents `true` or `false` values."

  coerce_input ->(value, _ctx) { (value == true || value == false) ? value : nil }
  coerce_result ->(value, _ctx) { !!value }
  default_scalar true
end

Class Method Summary collapse

Class Method Details

.parse(graphql_string, tracer: GraphQL::Tracing::NullTracer) ⇒ GraphQL::Language::Nodes::Document

Turn a query string or schema definition into an AST



38
39
40
# File 'lib/graphql.rb', line 38

def self.parse(graphql_string, tracer: GraphQL::Tracing::NullTracer)
  parse_with_racc(graphql_string, tracer: tracer)
end

.parse_file(filename) ⇒ GraphQL::Language::Nodes::Document

Read the contents of filename and parse them as GraphQL



45
46
47
48
# File 'lib/graphql.rb', line 45

def self.parse_file(filename)
  content = File.read(filename)
  parse_with_racc(content, filename: filename)
end

.parse_with_racc(string, filename: nil, tracer: GraphQL::Tracing::NullTracer) ⇒ Object



50
51
52
# File 'lib/graphql.rb', line 50

def self.parse_with_racc(string, filename: nil, tracer: GraphQL::Tracing::NullTracer)
  GraphQL::Language::Parser.parse(string, filename: filename, tracer: tracer)
end

.scan(graphql_string) ⇒ Array<GraphQL::Language::Token>



55
56
57
# File 'lib/graphql.rb', line 55

def self.scan(graphql_string)
  scan_with_ragel(graphql_string)
end

.scan_with_ragel(graphql_string) ⇒ Object



59
60
61
# File 'lib/graphql.rb', line 59

def self.scan_with_ragel(graphql_string)
  GraphQL::Language::Lexer.tokenize(graphql_string)
end