Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

with_schema #11

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/rspec/graphql_response/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions lib/rspec/graphql_response/helpers/with_schema.rb
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions spec/graphql/alternate_schema.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require "graphql/alternate_schema/alternate_types"
require "graphql/alternate_schema/alternate_queries"

class AlternateSchema < GraphQL::Schema
query AlternateQueries
end
7 changes: 7 additions & 0 deletions spec/graphql/alternate_schema/alternate_queries.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require "graphql/queries/characters"

class AlternateQueries < GraphQL::Schema::Object
graphql_name "Query"

field :employees, resolver: Queries::Characters
end
4 changes: 2 additions & 2 deletions spec/graphql/example_schema.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions spec/graphql/example_schema/example_types.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require "graphql/types/response/character"
44 changes: 44 additions & 0 deletions spec/graphql_response/helpers/with_schema_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
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).to_not be_nil
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