-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
153 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,6 @@ | |
|
||
module GraphQL | ||
module Stitching | ||
VERSION = "1.4.0" | ||
VERSION = "1.4.1" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
require_relative "../../../schemas/merged_child" | ||
|
||
describe 'GraphQL::Stitching, merged child' do | ||
def setup | ||
@supergraph = compose_definitions({ | ||
"a" => Schemas::MergedChild::ParentSchema, | ||
"b" => Schemas::MergedChild::ChildSchema, | ||
}) | ||
|
||
@expected = { | ||
"author" => { | ||
"name" => "Frank Herbert", | ||
"book" => { | ||
"title" => "Dune", | ||
"year" => 1965, | ||
}, | ||
}, | ||
} | ||
end | ||
|
||
def test_resolves_fragment_spread_for_parent_of_merged_child | ||
result = plan_and_execute(@supergraph, %| | ||
query { | ||
author { ...AuthorAttrs } | ||
} | ||
fragment AuthorAttrs on Author { | ||
name | ||
book { | ||
title | ||
year | ||
} | ||
} | ||
|) | ||
|
||
assert_equal @expected, result["data"] | ||
end | ||
|
||
def test_resolves_inline_fragment_for_parent_of_merged_child | ||
result = plan_and_execute(@supergraph, %| | ||
query { | ||
author { | ||
...on Author { | ||
name | ||
book { | ||
title | ||
year | ||
} | ||
} | ||
} | ||
} | ||
|) | ||
|
||
assert_equal @expected, result["data"] | ||
end | ||
|
||
def test_resolves_untyped_fragment_for_parent_of_merged_child | ||
result = plan_and_execute(@supergraph, %| | ||
query { | ||
author { | ||
... { | ||
name | ||
book { | ||
title | ||
year | ||
} | ||
} | ||
} | ||
} | ||
|) | ||
|
||
assert_equal @expected, result["data"] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# frozen_string_literal: true | ||
|
||
module Schemas | ||
module MergedChild | ||
class StitchingResolver < GraphQL::Schema::Directive | ||
graphql_name "stitch" | ||
locations FIELD_DEFINITION | ||
argument :key, String, required: true | ||
argument :arguments, String, required: false | ||
repeatable true | ||
end | ||
|
||
AUTHOR = { | ||
id: "1", | ||
name: "Frank Herbert", | ||
book: { | ||
id: "1", | ||
title: "Dune", | ||
year: 1965, | ||
}, | ||
}.freeze | ||
|
||
class ParentSchema < GraphQL::Schema | ||
class Book < GraphQL::Schema::Object | ||
field :id, ID, null: false | ||
field :title, String, null: false | ||
end | ||
|
||
class Author < GraphQL::Schema::Object | ||
field :id, ID, null: false | ||
field :name, String, null: false | ||
field :book, Book, null: true | ||
end | ||
|
||
class Query < GraphQL::Schema::Object | ||
field :author, Author, null: false | ||
|
||
def author | ||
AUTHOR | ||
end | ||
|
||
field :book, Book, null: true do | ||
directive StitchingResolver, key: "id" | ||
argument :id, ID, required: true | ||
end | ||
|
||
def book(id:) | ||
AUTHOR[:book] if AUTHOR[:book][:id] == id | ||
end | ||
end | ||
|
||
query Query | ||
end | ||
|
||
class ChildSchema < GraphQL::Schema | ||
class Book < GraphQL::Schema::Object | ||
field :id, ID, null: false | ||
field :year, Int, null: false | ||
end | ||
|
||
class Query < GraphQL::Schema::Object | ||
field :book, Book, null: true do | ||
directive StitchingResolver, key: "id" | ||
argument :id, ID, required: true | ||
end | ||
|
||
def book(id:) | ||
AUTHOR[:book] if AUTHOR[:book][:id] == id | ||
end | ||
end | ||
|
||
query Query | ||
end | ||
end | ||
end |