File: entry_points_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 (59 lines) | stat: -rw-r--r-- 1,610 bytes parent folder | download | duplicates (3)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# frozen_string_literal: true
require "spec_helper"

describe GraphQL::Introspection::EntryPoints do
  describe "#__type" do
    let(:schema) do
      nested_invisible_type = Class.new(GraphQL::Schema::Object) do
        graphql_name 'NestedInvisible'
        field :foo, String, null: false
      end

      invisible_type = Class.new(GraphQL::Schema::Object) do
        graphql_name 'Invisible'
        field :foo, String, null: false
        field :nested_invisible, nested_invisible_type, null: false

        def self.visible?(context)
          false
        end
      end

      visible_type = Class.new(GraphQL::Schema::Object) do
        graphql_name 'Visible'
        field :foo, String, null: false
      end

      query_type = Class.new(GraphQL::Schema::Object) do
        graphql_name 'Query'
        field :foo, String, null: false
        field :invisible, invisible_type, null: false
        field :visible, visible_type, null: false
      end

      Class.new(GraphQL::Schema) do
        query query_type
      end
    end

    let(:query_string) {%|
      query getType($name: String!) {
        __type(name: $name) {
          name
        }
      }
    |}

    it "returns reachable types" do
      result = schema.execute(query_string, variables: { name: 'Visible' })
      type_name = result['data']['__type']['name']
      assert_equal('Visible', type_name)
    end

    it "returns nil for unreachable types" do
      result = schema.execute(query_string, variables: { name: 'NestedInvisible' })
      type_name = result['data']['__type']
      assert_nil(type_name)
    end
  end
end