Sha256: cc0ba5728fb14dde2c0484b30c7460da0a558a15a86ad3c3ea7d7e0989f6eef2

Contents?: true

Size: 1.48 KB

Versions: 4

Compression:

Stored size: 1.48 KB

Contents

require 'spec_helper'

describe GraphQL::Query::SerialExecution::ExecutionContext do
  let(:query_string) { %|
    query getFlavor($cheeseId: Int!) {
      brie: cheese(id: 1)   { ...cheeseFields, taste: flavor }
    }
    fragment cheeseFields on Cheese { flavor }
  |}
  let(:debug) { false }
  let(:operation_name) { nil }
  let(:query_variables) { {"cheeseId" => 2} }
  let(:schema) { DummySchema }
  let(:query) { GraphQL::Query.new(
    schema,
    query_string,
    variables: query_variables,
    debug: debug,
    operation_name: operation_name,
  )}
  let(:execution_context) {
    GraphQL::Query::SerialExecution::ExecutionContext.new(query, nil)
  }

  describe "add_error" do
    let(:err) { StandardError.new("test") }
    let(:expected) { [err] }

    it "adds an error on the query context" do
      execution_context.add_error(err)
      assert_equal(expected, query.context.errors)
    end
  end

  describe "get_type" do
    it "returns the respective type from the schema" do
      type = execution_context.get_type('Dairy')
      assert_equal(DairyType, type)
    end
  end

  describe "get_field" do
    it "returns the respective field from the schema" do
      field = execution_context.get_field(DairyType, 'cheese')
      assert_equal('cheese', field.name)
    end
  end

  describe "get_fragment" do
    it "returns a fragment on the query by name" do
      fragment = execution_context.get_fragment('cheeseFields')
      assert_equal('cheeseFields', fragment.name)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
graphql-0.12.1 spec/graphql/query/serial_execution/execution_context_spec.rb
graphql-0.12.0 spec/graphql/query/serial_execution/execution_context_spec.rb
graphql-0.11.1 spec/graphql/query/serial_execution/execution_context_spec.rb
graphql-0.11.0 spec/graphql/query/serial_execution/execution_context_spec.rb