Skip to content
Merged
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
2 changes: 1 addition & 1 deletion lib/graphql/stitching/executor/shaper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def resolve_object_scope(raw_object, parent_type, selections, typename = nil)
field_name = node.alias || node.name

if @request.query.get_field(parent_type, node.name).introspection?
if node.name == TYPENAME && parent_type == @root_type
if node.name == TYPENAME && parent_type == @root_type && node != TypeResolver::TYPENAME_EXPORT_NODE
raw_object[field_name] = @root_type.graphql_name
end
next
Expand Down
7 changes: 2 additions & 5 deletions lib/graphql/stitching/planner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def perform
end

def steps
@steps_by_entrypoint.each_value.select { _1.selections.any? }.sort_by!(&:index)
@steps_by_entrypoint.values.sort_by!(&:index)
end

private
Expand Down Expand Up @@ -213,7 +213,7 @@ def extract_locale_selections(
input_selections.each do |node|
case node
when GraphQL::Language::Nodes::Field
if node.alias&.start_with?(TypeResolver::EXPORT_PREFIX)
if node.alias&.start_with?(TypeResolver::EXPORT_PREFIX) && node != TypeResolver::TYPENAME_EXPORT_NODE
raise StitchingError, %(Alias "#{node.alias}" is not allowed because "#{TypeResolver::EXPORT_PREFIX}" is a reserved prefix.)
elsif node.name == TYPENAME
locale_selections << node
Expand All @@ -238,7 +238,6 @@ def extract_locale_selections(
selection_set = extract_locale_selections(current_location, field_type, parent_index, node.selections, path, locale_variables)
path.pop

next if selection_set.empty?
locale_selections << node.merge(selections: selection_set)
end

Expand All @@ -251,7 +250,6 @@ def extract_locale_selections(
extract_locale_selections(current_location, fragment_type, parent_index, node.selections, path, locale_variables, selection_set)

unless is_same_scope
next if selection_set.empty?
locale_selections << node.merge(selections: selection_set)
requires_typename = true
end
Expand All @@ -267,7 +265,6 @@ def extract_locale_selections(
extract_locale_selections(current_location, fragment_type, parent_index, fragment.selections, path, locale_variables, selection_set)

unless is_same_scope
next if selection_set.empty?
locale_selections << GraphQL::Language::Nodes::InlineFragment.new(type: fragment.type, selections: selection_set)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/graphql/stitching/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module GraphQL
module Stitching
VERSION = "1.7.1"
VERSION = "1.7.2"
end
end
100 changes: 100 additions & 0 deletions test/graphql/stitching/integration/skip_include_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# frozen_string_literal: true

require "test_helper"
require_relative "../../../schemas/example"

describe 'GraphQL::Stitching, skip/include' do
def setup
@supergraph = compose_definitions({
"products" => Schemas::Example::Products,
"storefronts" => Schemas::Example::Storefronts,
"manufacturers" => Schemas::Example::Manufacturers,
})
end

def test_skips_partial_object_fields
query = %|
query($id: ID!) {
storefront(id: $id) {
products {
upc
manufacturer @skip(if: true) {
name
}
}
}
}
|

result = plan_and_execute(@supergraph, query, { "id" => "1" })
expected = {
"storefront" => {
"products" => [
{ "upc" => "1" },
{ "upc" => "2" },
],
},
}

assert_equal expected, result.dig("data")
end

def test_skips_all_object_fields
query = %|
query($id: ID!) {
storefront(id: $id) {
products {
manufacturer @skip(if: true) {
name
}
}
}
}
|

result = plan_and_execute(@supergraph, query, { "id" => "1" })
expected = {
"storefront" => {
"products" => [
{},
{},
],
},
}

assert_equal expected, result.dig("data")
end

def test_skips_partial_root_fields
query = %|{
product(upc: "1") {
upc
}
storefront(id: "1") @skip(if: true) {
id
}
}|

result = plan_and_execute(@supergraph, query)
expected = {
"product" => { "upc" => "1" }
}

assert_equal expected, result.dig("data")
end

def test_skips_all_root_fields
query = %|
query($id: ID!) {
storefront(id: $id) @skip(if: true) {
id
}
}
|

result = plan_and_execute(@supergraph, query, { "id" => "1" })
expected = {}

assert_equal expected, result.dig("data")
end
end