File: finder_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 (135 lines) | stat: -rw-r--r-- 4,339 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# frozen_string_literal: true
require "spec_helper"

describe GraphQL::Schema::Finder do
  let(:finder) { GraphQL::Schema::Finder.new(Jazz::Schema) }

  describe "#find" do
    it "finds a valid object type" do
      type = finder.find("Ensemble")
      assert_equal "Ensemble", type.graphql_name
    end

    it "raises when finding an invalid object type" do
      exception = assert_raises GraphQL::Schema::Finder::MemberNotFoundError do
        finder.find("DoesNotExist")
      end

      assert_match(/Could not find type `DoesNotExist` in schema./, exception.message)
    end

    it "finds a valid directive" do
      directive = finder.find("@include")
      assert_equal "include", directive.graphql_name
    end

    it "raises when finding an invalid directive" do
      exception = assert_raises GraphQL::Schema::Finder::MemberNotFoundError do
        finder.find("@yolo")
      end

      assert_match(/Could not find directive `@yolo` in schema./, exception.message)
    end

    it "finds a valid field" do
      field = finder.find("Ensemble.musicians")
      assert_equal "musicians", field.graphql_name
    end

    it "finds a meta field" do
      field = finder.find("Ensemble.__typename")
      assert_equal "__typename", field.graphql_name
    end

    it "raises when finding an in valid field" do
      exception = assert_raises GraphQL::Schema::Finder::MemberNotFoundError do
        finder.find("Ensemble.nope")
      end

      assert_match(/Could not find field `nope` on object type `Ensemble`./, exception.message)
    end

    it "finds a valid argument" do
      arg = finder.find("Query.find.id")
      assert_equal "id", arg.graphql_name
    end

    it "raises when finding an invalid argument" do
      exception = assert_raises GraphQL::Schema::Finder::MemberNotFoundError do
        finder.find("Query.find.thisArgumentIsInvalid")
      end

      assert_match(/Could not find argument `thisArgumentIsInvalid` on field `find`./, exception.message)
    end

    it "raises when selecting on an argument" do
      exception = assert_raises GraphQL::Schema::Finder::MemberNotFoundError do
        finder.find("Query.find.id.whyYouDoThis")
      end

      assert_match(/Cannot select member `whyYouDoThis` on a field./, exception.message)
    end

    it "finds a valid interface" do
      type = finder.find("NamedEntity")
      assert_equal "NamedEntity", type.graphql_name
    end

    it "finds a valid input type" do
      type = finder.find("LegacyInput")
      assert_equal "LegacyInput", type.graphql_name
    end

    it "finds a valid input field" do
      input_field = finder.find("LegacyInput.intValue")
      assert_equal "intValue", input_field.graphql_name
    end

    it "raises when finding an invalid input field" do
      exception = assert_raises GraphQL::Schema::Finder::MemberNotFoundError do
        finder.find("LegacyInput.wat")
      end

      assert_match(/Could not find input field `wat` on input object type `LegacyInput`./, exception.message)
    end

    it "finds a valid union type" do
      type = finder.find("PerformingAct")
      assert_equal "PerformingAct", type.graphql_name
    end

    it "raises when selecting a possible type" do
      exception = assert_raises GraphQL::Schema::Finder::MemberNotFoundError do
        finder.find("PerformingAct.Musician")
      end

      assert_match(/Cannot select union possible type `Musician`. Select the type directly instead./, exception.message)
    end

    it "finds a valid enum type" do
      type = finder.find("Family")
      assert_equal "Family", type.graphql_name
    end

    it "finds a valid enum value" do
      value = finder.find("Family.BRASS")
      assert_equal "BRASS", value.graphql_name
    end

    it "raises when finding an invalid enum value" do
      exception = assert_raises GraphQL::Schema::Finder::MemberNotFoundError do
        finder.find("Family.THISISNOTASTATUS")
      end

      assert_match(/Could not find enum value `THISISNOTASTATUS` on enum type `Family`./, exception.message)
    end

    it "raises when selecting on an enum value" do
      exception = assert_raises GraphQL::Schema::Finder::MemberNotFoundError do
        finder.find("Family.BRASS.wat")
      end

      assert_match(/Cannot select member `wat` on an enum value./, exception.message)
    end
  end
end