File: result_spec.rb

package info (click to toggle)
ruby-graphql 2.5.19-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 13,868 kB
  • sloc: ruby: 80,420; ansic: 1,808; yacc: 845; javascript: 480; makefile: 6
file content (35 lines) | stat: -rw-r--r-- 1,024 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# frozen_string_literal: true
require "spec_helper"

describe GraphQL::Query::Result do
  let(:query_string) { '{ __type(name: "Cheese") { name } }' }
  let(:schema) { Dummy::Schema }
  let(:result) { schema.execute(query_string, context: { a: :b }) }

  it "exposes hash-like methods" do
    assert_equal "Cheese", result["data"]["__type"]["name"]
    refute result.key?("errors")
    assert_equal ["data"], result.keys
  end

  it "is equal with hashes" do
    hash_result = {"data" => { "__type" => { "name" => "Cheese" } } }
    assert_equal hash_result, result
  end

  it "tells the kind of operation" do
    assert result.query?
    refute result.mutation?
  end

  it "exposes the context" do
    assert_instance_of GraphQL::Query::Context, result.context
    expected_ctx = if GraphQL::Schema.use_visibility_profile? && result.context.schema.visibility.migration_errors?
      {a: :b, visibility_migration_running: true}
    else
      {a: :b}
    end

    assert_equal(expected_ctx, result.context.to_h)
  end
end