Commit bcc2ad3

mo khan <mo.khan@gmail.com>
2020-12-22 00:23:09
test: play with introspection system
1 parent 143465a
Changed files (2)
lib
test
integration
lib/server.rb
@@ -3,8 +3,13 @@ require 'json'
 require 'graphql'
 
 module Types
-  class QueryType < GraphQL::Schema::Object
+  class Cake < GraphQL::Schema::Object
+    field :name, String, null: false
+  end
+
+  class Query < GraphQL::Schema::Object
     field :me, String, null: false
+    field :cakes, [Cake], null: false
 
     def me
       'mo'
@@ -14,7 +19,7 @@ end
 
 class MySchema < GraphQL::Schema
   max_complexity 400
-  query Types::QueryType
+  query Types::Query
 end
 
 class Server
test/integration/server_test.rb
@@ -28,4 +28,36 @@ class ServerTest < Minitest::Test
     json = JSON.parse(last_response.body)
     assert_equal 'mo', json['data']['me']
   end
+
+  def test_get_schema
+    header 'Content-Type', 'application/graphql'
+    post '/', '{ __schema { types { name } } }'
+
+    assert last_response.ok?
+    json = JSON.parse(last_response.body)
+
+    [
+      'Boolean',
+      'Cake',
+      'Query',
+      'String',
+      '__Directive',
+      '__DirectiveLocation',
+      '__EnumValue',
+      '__InputValue',
+      '__Type',
+      '__TypeKind',
+    ].each do |type|
+      assert json['data']['__schema']['types'].include?('name' => type)
+    end
+  end
+
+  def test_get_query_type
+    header 'Content-Type', 'application/graphql'
+    post '/', '{ __schema { queryType { name } } }'
+
+    assert last_response.ok?
+    json = JSON.parse(last_response.body)
+    assert 'Query', json['data']['__schema']['queryType']['name']
+  end
 end