Skip to content

Commit

Permalink
Fix CI
Browse files Browse the repository at this point in the history
  • Loading branch information
swalkinshaw committed May 21, 2024
1 parent 7468658 commit f38eb81
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 103 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ Rake::TestTask.new(:test) do |t|
t.test_files = FileList['test/**/*_test.rb']
end

task :default => :test
task default: :test
10 changes: 3 additions & 7 deletions graphql_schema.gemspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'graphql_schema/version'
require_relative 'lib/graphql_schema/version'

Gem::Specification.new do |spec|
spec.name = "graphql_schema"
Expand All @@ -23,8 +20,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]
spec.metadata['allowed_push_host'] = "https://rubygems.org"

spec.add_development_dependency "graphql", "~> 1.2"
spec.add_development_dependency "byebug", '~> 9.0' if RUBY_ENGINE == 'ruby'
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "graphql", ">= 2.3"
spec.add_development_dependency "rake", "~> 13.0"
spec.add_development_dependency "minitest", "~> 5.0"
end
2 changes: 1 addition & 1 deletion lib/graphql_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ class Directive
include NamedHash
include WithArgs

BUILTIN = %w(skip include deprecated).to_set
BUILTIN = %w(skip include deprecated oneOf specifiedBy).to_set

def initialize(directive)
@hash = directive
Expand Down
40 changes: 22 additions & 18 deletions test/graphql_schema_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@

class GraphQLSchemaTest < Minitest::Test
def setup
@schema = GraphQLSchema.new(Support::Schema.introspection_result)
@schema = GraphQLSchema.new(Support::Schema::ExampleSchema.as_json)
end

def test_that_it_has_a_version_number
refute_nil ::GraphQLSchema::VERSION
end

def test_application_types
expect = %w(QueryRoot Mutation Entry IntegerEntry StringEntry Time KeyType SetIntegerInput).sort
expect = %w(QueryRoot MutationRoot Entry IntegerEntry StringEntry Time Key SetIntegerInput).sort
assert_equal expect, @schema.types.reject(&:builtin?).map(&:name)
end

def test_roots
assert_equal 'QueryRoot', @schema.query_root_name
assert_equal 'Mutation', @schema.mutation_root_name
assert_equal ['Mutation', 'QueryRoot'], @schema.types.select { |type| @schema.root_name?(type.name) }.map(&:name)
assert_equal 'MutationRoot', @schema.mutation_root_name
assert_equal ['MutationRoot', 'QueryRoot'], @schema.types.select { |type| @schema.root_name?(type.name) }.map(&:name)
end

def test_no_mutation_root
schema = GraphQLSchema.new(Support::Schema.introspection_result(Support::Schema::NoMutationSchema))
schema = GraphQLSchema.new(Support::Schema::NoMutationSchema.as_json)
assert_nil schema.mutation_root_name
end

Expand All @@ -44,7 +44,7 @@ def test_upcase_name
end

def test_nil_fields
assert_nil type('KeyType').fields
assert_nil type('Key').fields
end

def test_deprecated_fields
Expand All @@ -54,7 +54,7 @@ def test_deprecated_fields
end

def test_deprecated_enum_values
deprecated = type('KeyType').enum_values(include_deprecated: true) - type('KeyType').enum_values
deprecated = type('Key').enum_values(include_deprecated: true) - type('Key').enum_values
assert_equal %w(NOT_FOUND), deprecated.map(&:name)
assert_equal "GraphQL null now used instead", deprecated.first.deprecation_reason
end
Expand Down Expand Up @@ -120,8 +120,8 @@ def test_optional_args
end

def test_default_args
assert_equal "\"I am default\"", arg('Mutation', 'set_string_with_default', 'value').default_value
assert_nil arg('Mutation', 'set_string_with_default', 'key').default_value
assert_equal "\"I am default\"", arg('MutationRoot', 'setStringWithDefault', 'value').default_value
assert_nil arg('MutationRoot', 'setStringWithDefault', 'key').default_value
end

def test_possible_types
Expand All @@ -144,9 +144,9 @@ def test_enum?
end

def test_fields_by_name
assert_equal get_string_field, type('QueryRoot').fields_by_name['get_string']
assert_equal get_string_field, type('QueryRoot').fields_by_name['getString']
assert_equal get_field, type('QueryRoot').fields_by_name['get']
assert_nil type('QueryRoot').fields_by_name['does_not_exist']
assert_nil type('QueryRoot').fields_by_name['doesNotExist']
end

def test_type_by_name
Expand All @@ -157,9 +157,9 @@ def test_type_by_name
def test_description
assert_equal 'Time since epoch in seconds', type('Time').description
assert_nil type('StringEntry').description
assert_nil type('KeyType').enum_values.first.description
assert_nil type('Key').enum_values.first.description
assert_nil input_field('SetIntegerInput', 'negate').description
assert_equal 'Get an entry of any type with the given key', field('QueryRoot', 'get_entry').description
assert_equal 'Get an entry of any type with the given key', field('QueryRoot', 'getEntry').description
end

def test_directives
Expand All @@ -173,7 +173,9 @@ def test_directives
assert directive("skip").builtin?
assert directive("include").builtin?
assert directive("deprecated").builtin?
assert_equal 4, @schema.directives.length
assert directive("oneOf").builtin?
assert directive("specifiedBy").builtin?
assert_equal 6, @schema.directives.length
end

def test_to_h
Expand All @@ -192,15 +194,17 @@ def test_to_h
'name' => 'negate',
'description' => nil,
'type' => {'kind' => 'SCALAR', 'name' => 'Boolean', 'ofType' => nil },
'defaultValue' => 'false'
'defaultValue' => 'false',
"isDeprecated" => false,
"deprecationReason" => nil
}, input_field('SetIntegerInput', 'negate').to_h)

assert_equal({
'name' => 'INTEGER',
'description' => nil,
'isDeprecated' => false,
'deprecationReason' => nil
}, type('KeyType').enum_values.first.to_h)
}, type('Key').enum_values.first.to_h)
end

private
Expand Down Expand Up @@ -240,14 +244,14 @@ def get_field
end

def get_string_field
field('QueryRoot', 'get_string')
field('QueryRoot', 'getString')
end

def keys_field
field('QueryRoot', 'keys')
end

def not_found_value
enum_value('KeyType', 'NOT_FOUND')
enum_value('Key', 'NOT_FOUND')
end
end
134 changes: 59 additions & 75 deletions test/support/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,124 +3,108 @@

module Support
module Schema
KeyType = GraphQL::EnumType.define do
name "KeyType"
class Key < GraphQL::Schema::Enum
description "Types of values that can be stored in a key"
value("STRING")
value("INTEGER")
value("NOT_FOUND", deprecation_reason: "GraphQL null now used instead")
end

TimeType = GraphQL::ScalarType.define do
name "Time"
class Time < GraphQL::Schema::Scalar
description "Time since epoch in seconds"
end

EntryType = GraphQL::InterfaceType.define do
name "Entry"
field :key, !types.String
field :ttl, TimeType
end
module Entry
include GraphQL::Schema::Interface

StringEntryType = GraphQL::ObjectType.define do
name "StringEntry"
interfaces [EntryType]
field :key, !types.String
field :value, !types.String
field :ttl, TimeType
field :key, String, null: false
field :ttl, Time, null: true
end

IntegerEntryType = GraphQL::ObjectType.define do
name "IntegerEntry"
interfaces [EntryType]
field :key, !types.String
field :value, !types.Int
field :ttl, TimeType
class StringEntry < GraphQL::Schema::Object
implements Entry
field :key, String, null: false
field :value, String, null: false
field :ttl, Time, null: true
end

QueryType = GraphQL::ObjectType.define do
name "QueryRoot"
class IntegerEntry < GraphQL::Schema::Object
implements Entry
field :key, String, null: false
field :value, Int, null: false
field :ttl, Time, null: true
end

field :get, types.String do
class QueryRoot < GraphQL::Schema::Object
field :get, String, null: true, deprecation_reason: "Ambiguous, use get_string instead" do
description "Get a string value with the given key"
deprecation_reason "Ambiguous, use get_string instead"
argument :key, !types.String
argument :key, String, required: true
end
field :get_string, types.String do
field :get_string, String do
description "Get a string value with the given key"
argument :key, !types.String
argument :key, String, required: true
end
field :get_integer, types.Int do
field :get_integer, Int do
description "Get a integer value with the given key"
argument :key, !types.String
argument :key, String, required: true
end
field :get_entry, EntryType do
field :get_entry, Entry, null: true do
description "Get an entry of any type with the given key"
argument :key, !types.String
argument :key, String, required: true
end
field :type, KeyType
field :ttl, TimeType
field :keys, !types[!types.String] do
argument :first, !types.String
argument :after, types.String
field :type, Key, null: true
field :ttl, Time, null: true
field :keys, [String], null: false do
argument :first, String, required: true
argument :after, String, required: false
end
field :entries, !types[!EntryType] do
argument :first, !types.String
argument :after, types.String
field :entries, [Entry], null: false do
argument :first, String, required: true
argument :after, String, required: false
end
end

SetIntegerInput = GraphQL::InputObjectType.define do
name "SetIntegerInput"
argument :key, !types.String
argument :value, !types.Int
argument :ttl, TimeType
argument :negate, types.Boolean, default_value: false
class SetIntegerInput < GraphQL::Schema::InputObject
argument :key, String, required: true
argument :value, Int, required: true
argument :ttl, Time, required: false
argument :negate, Boolean, default_value: false, required: false
end

MutationType = GraphQL::ObjectType.define do
name "Mutation"

field :set, types.String do
deprecation_reason "Ambiguous, use set_string instead"
argument :key, !types.String
class MutationRoot < GraphQL::Schema::Object
field :set, String, null: true, deprecation_reason: "Ambiguous, use set_string instead" do
argument :key, String, required: true
end
field :set_string, !types.Boolean do
argument :key, !types.String
argument :value, !types.String
field :set_string, Boolean, null: false do
argument :key, String, required: true
argument :value, String, required: true
end
field :set_string_with_default, !types.Boolean do
argument :key, !types.String
argument :value, types.String, default_value: "I am default"
field :set_string_with_default, Boolean, null: false do
argument :key, String, required: true
argument :value, String, required: false, default_value: "I am default"
end
field :set_integer, !types.Boolean do
argument :input, !SetIntegerInput
field :set_integer, Boolean, null: false do
argument :input, SetIntegerInput, required: true
end
end

class DirectiveExample < GraphQL::Schema::Directive
description "A nice runtime customization"
locations FIELD
argument :input, !SetIntegerInput, required: true
argument :input, SetIntegerInput, required: true
argument :enabled, Boolean, required: false
end

ExampleSchema = GraphQL::Schema.define do
query QueryType
mutation MutationType
directive(DirectiveExample)
orphan_types [StringEntryType, IntegerEntryType]
resolve_type ->(obj, ctx) {}
end

NoMutationSchema = GraphQL::Schema.define do
query QueryType
orphan_types [StringEntryType, IntegerEntryType]
resolve_type ->(obj, ctx) {}
class ExampleSchema < GraphQL::Schema
query QueryRoot
mutation MutationRoot
directive DirectiveExample
orphan_types [StringEntry, IntegerEntry]
end

def self.introspection_result(schema = ExampleSchema)
GraphQL::Query.new(schema, GraphQL::Introspection::INTROSPECTION_QUERY).result
class NoMutationSchema < GraphQL::Schema
query QueryRoot
orphan_types [StringEntry, IntegerEntry]
end
end
end
1 change: 0 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
require 'graphql_schema'

require 'minitest/autorun'
Expand Down

0 comments on commit f38eb81

Please sign in to comment.