File: result_spec.rb

package info (click to toggle)
ruby-graphql 2.2.17-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,584 kB
  • sloc: ruby: 67,505; ansic: 1,753; yacc: 831; javascript: 331; makefile: 6
file content (29 lines) | stat: -rw-r--r-- 821 bytes parent folder | download | duplicates (4)
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
# 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
    assert_equal({a: :b}, result.context.to_h)
  end
end