From 7eff081b40d9e19e34e0e4c8dddce20310f7e291 Mon Sep 17 00:00:00 2001 From: Daniel Flynn Date: Wed, 26 May 2021 14:56:42 -0400 Subject: [PATCH 1/4] wip: create alternate schema --- spec/graphql/alternate_schema.rb | 6 ++++++ spec/graphql/alternate_schema/alternate_queries.rb | 7 +++++++ .../alternate_types.rb} | 0 spec/graphql/example_schema.rb | 4 ++-- spec/graphql/{ => example_schema}/example_queries.rb | 0 spec/graphql/example_schema/example_types.rb | 1 + 6 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 spec/graphql/alternate_schema.rb create mode 100644 spec/graphql/alternate_schema/alternate_queries.rb rename spec/graphql/{example_types.rb => alternate_schema/alternate_types.rb} (100%) rename spec/graphql/{ => example_schema}/example_queries.rb (100%) create mode 100644 spec/graphql/example_schema/example_types.rb diff --git a/spec/graphql/alternate_schema.rb b/spec/graphql/alternate_schema.rb new file mode 100644 index 0000000..b998bed --- /dev/null +++ b/spec/graphql/alternate_schema.rb @@ -0,0 +1,6 @@ +require "graphql/alternate_schema/alternate_types" +require "graphql/alternate_schema/alternate_queries" + +class AlternateSchema < GraphQL::Schema + query AlternateQueries +end diff --git a/spec/graphql/alternate_schema/alternate_queries.rb b/spec/graphql/alternate_schema/alternate_queries.rb new file mode 100644 index 0000000..84701eb --- /dev/null +++ b/spec/graphql/alternate_schema/alternate_queries.rb @@ -0,0 +1,7 @@ +require "graphql/queries/characters" + +class AlternateQueries < GraphQL::Schema::Object + graphql_name "Query" + + field :employees, resolver: Queries::Characters +end diff --git a/spec/graphql/example_types.rb b/spec/graphql/alternate_schema/alternate_types.rb similarity index 100% rename from spec/graphql/example_types.rb rename to spec/graphql/alternate_schema/alternate_types.rb diff --git a/spec/graphql/example_schema.rb b/spec/graphql/example_schema.rb index 7bbf1f1..4e212c3 100644 --- a/spec/graphql/example_schema.rb +++ b/spec/graphql/example_schema.rb @@ -1,5 +1,5 @@ -require "graphql/example_types" -require "graphql/example_queries" +require "graphql/example_schema/example_types" +require "graphql/example_schema/example_queries" class ExampleSchema < GraphQL::Schema query ExampleQueries diff --git a/spec/graphql/example_queries.rb b/spec/graphql/example_schema/example_queries.rb similarity index 100% rename from spec/graphql/example_queries.rb rename to spec/graphql/example_schema/example_queries.rb diff --git a/spec/graphql/example_schema/example_types.rb b/spec/graphql/example_schema/example_types.rb new file mode 100644 index 0000000..e535a3e --- /dev/null +++ b/spec/graphql/example_schema/example_types.rb @@ -0,0 +1 @@ +require "graphql/types/response/character" From 6f60027fbd49f76e2871699a7b38e6b757b3ff1b Mon Sep 17 00:00:00 2001 From: Daniel Flynn Date: Wed, 26 May 2021 15:04:38 -0400 Subject: [PATCH 2/4] test: add initial with_schema tests --- .../helpers/with_schema_spec.rb | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 spec/graphql_response/helpers/with_schema_spec.rb diff --git a/spec/graphql_response/helpers/with_schema_spec.rb b/spec/graphql_response/helpers/with_schema_spec.rb new file mode 100644 index 0000000..625811f --- /dev/null +++ b/spec/graphql_response/helpers/with_schema_spec.rb @@ -0,0 +1,43 @@ +require "graphql/alternate_schema" + +RSpec.describe RSpec::GraphQLResponse, "helper#with_schema", type: :graphql do + with_schema AlternateSchema + + graphql_operation <<-GQL + query { + employees { + id, + name + } + } + GQL + + it "queries the correct schema with employees" do + expect(response_data).to include( + "employees" => [ + { + "id" => "1", + "name" => "Jam", + "friends" => [ + { "id" => "2", "name" => "Redemption" } + ] + }, + { + "id" => "2", + "name" => "Redemption", + "friends" => [ + { "id" => "1", "name" => "Jam" }, + { "id" => "3", "name" => "Pet" } + ] + }, + { + "id" => "3", + "name" => "Pet", + "friends" => [ + { "id" => "2", "name" => "Redemption" } + ] + } + ] + ) + end +end From 5b5a72ca55e87a4c7bf03e65f1e8bfaee71c700f Mon Sep 17 00:00:00 2001 From: Daniel Flynn Date: Wed, 26 May 2021 15:31:36 -0400 Subject: [PATCH 3/4] wip: naive schema set --- lib/rspec/graphql_response/helpers.rb | 1 + lib/rspec/graphql_response/helpers/with_schema.rb | 4 ++++ spec/graphql_response/helpers/with_schema_spec.rb | 2 ++ 3 files changed, 7 insertions(+) create mode 100644 lib/rspec/graphql_response/helpers/with_schema.rb diff --git a/lib/rspec/graphql_response/helpers.rb b/lib/rspec/graphql_response/helpers.rb index f9bcafa..33d7561 100644 --- a/lib/rspec/graphql_response/helpers.rb +++ b/lib/rspec/graphql_response/helpers.rb @@ -43,6 +43,7 @@ def self.add_helper(name, scope: :spec, &helper) require_relative "helpers/graphql_context" require_relative "helpers/graphql_operation" require_relative "helpers/graphql_variables" +require_relative "helpers/with_schema" # spec level helpers require_relative "helpers/execute_graphql" diff --git a/lib/rspec/graphql_response/helpers/with_schema.rb b/lib/rspec/graphql_response/helpers/with_schema.rb new file mode 100644 index 0000000..b40ba91 --- /dev/null +++ b/lib/rspec/graphql_response/helpers/with_schema.rb @@ -0,0 +1,4 @@ +RSpec::GraphQLResponse.add_context_helper :with_schema do |schema| + # return unless schema.is_a? == GraphQL::Schema + RSpec::GraphQLResponse.configuration.graphql_schema = schema +end diff --git a/spec/graphql_response/helpers/with_schema_spec.rb b/spec/graphql_response/helpers/with_schema_spec.rb index 625811f..c04bf23 100644 --- a/spec/graphql_response/helpers/with_schema_spec.rb +++ b/spec/graphql_response/helpers/with_schema_spec.rb @@ -13,6 +13,8 @@ GQL it "queries the correct schema with employees" do + binding.pry + expect(response).to_not be_nil expect(response_data).to include( "employees" => [ { From 55a6924b6125b767189a80a5f92f658f6a626262 Mon Sep 17 00:00:00 2001 From: Daniel Flynn Date: Wed, 26 May 2021 15:42:06 -0400 Subject: [PATCH 4/4] wip: cleanup pry --- spec/graphql_response/helpers/with_schema_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/graphql_response/helpers/with_schema_spec.rb b/spec/graphql_response/helpers/with_schema_spec.rb index c04bf23..1b19f6d 100644 --- a/spec/graphql_response/helpers/with_schema_spec.rb +++ b/spec/graphql_response/helpers/with_schema_spec.rb @@ -13,7 +13,6 @@ GQL it "queries the correct schema with employees" do - binding.pry expect(response).to_not be_nil expect(response_data).to include( "employees" => [