File: introspection_query_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 (62 lines) | stat: -rw-r--r-- 1,576 bytes parent folder | download | duplicates (2)
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
# frozen_string_literal: true
require "spec_helper"

describe "GraphQL::Introspection::INTROSPECTION_QUERY" do
  let(:schema)  {
    Class.new(Dummy::Schema) do
      max_depth(15)
    end
  }
  let(:query_string) { GraphQL::Introspection::INTROSPECTION_QUERY }
  let(:result) { schema.execute(query_string) }

  it "runs" do
    assert(result["data"])
  end

  it "is limited to the max query depth" do
    query_type =  Class.new(GraphQL::Schema::Object) do
      graphql_name "DeepQuery"

      field :foo, [[[Float]]], null: false
    end

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

     result = deep_schema.execute(query_string)
     assert(GraphQL::Schema::Loader.load(result))
  end

  it "doesn't handle too deeply nested (< 8) schemas" do
    query_type =  Class.new(GraphQL::Schema::Object) do
      graphql_name "DeepQuery"

      field :foo, [[[[Float]]]], null: false
    end

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

     result = deep_schema.execute(query_string)
     assert_raises(KeyError) {
       GraphQL::Schema::Loader.load(result)
     }
  end

  it "doesn't contain blank lines" do
    int_query = GraphQL::Introspection.query
    refute_includes int_query, "\n\n"

    int_query_with_options = GraphQL::Introspection.query(
      include_deprecated_args: true,
      include_schema_description: true,
      include_is_repeatable: true,
      include_specified_by_url: true,
      include_is_one_of: true
    )
    refute_includes int_query_with_options, "\n\n"
  end
end