-
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.
support lower graphql version, use faster routing. (#43)
- Loading branch information
Showing
9 changed files
with
189 additions
and
11 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
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
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
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,57 @@ | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
require_relative "../../../schemas/shareables" | ||
|
||
describe 'GraphQL::Stitching, shareables' do | ||
def setup | ||
@supergraph = compose_definitions({ | ||
"a" => Schemas::Shareables::ShareableA, | ||
"b" => Schemas::Shareables::ShareableB, | ||
}) | ||
end | ||
|
||
def test_mutates_serially_and_stitches_results | ||
query = <<~GRAPHQL | ||
query { | ||
gadgetA(id: "1") { | ||
id | ||
name | ||
gizmo { a b c } | ||
uniqueToA | ||
uniqueToB | ||
} | ||
gadgetB(id: "1") { | ||
id | ||
name | ||
gizmo { a b c } | ||
uniqueToA | ||
uniqueToB | ||
} | ||
} | ||
GRAPHQL | ||
|
||
result = plan_and_execute(@supergraph, query) | ||
|
||
expected = { | ||
"data" => { | ||
"gadgetA" => { | ||
"id" => "1", | ||
"name" => "A1", | ||
"gizmo" => { "a" => "apple", "b" => "banana", "c" => "coconut" }, | ||
"uniqueToA" => "AA", | ||
"uniqueToB" => "BB", | ||
}, | ||
"gadgetB" => { | ||
"id" => "1", | ||
"name" => "B1", | ||
"gizmo" => { "a" => "aardvark", "b" => "bat", "c" => "cat" }, | ||
"uniqueToA" => "AA", | ||
"uniqueToB" => "BB", | ||
}, | ||
}, | ||
} | ||
|
||
assert_equal expected, result | ||
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,80 @@ | ||
# frozen_string_literal: true | ||
|
||
module Schemas | ||
module Shareables | ||
class Boundary < GraphQL::Schema::Directive | ||
graphql_name "stitch" | ||
locations FIELD_DEFINITION | ||
argument :key, String | ||
repeatable true | ||
end | ||
|
||
# ShareableA | ||
|
||
class ShareableA < GraphQL::Schema | ||
class Gizmo < GraphQL::Schema::Object | ||
field :a, String, null: false | ||
field :b, String, null: false | ||
field :c, String, null: false | ||
end | ||
|
||
class Gadget < GraphQL::Schema::Object | ||
field :id, ID, null: false | ||
field :name, String, null: false | ||
field :gizmo, Gizmo, null: false | ||
field :unique_to_a, String, null: false | ||
|
||
def gizmo | ||
{ a: "apple", b: "banana", c: "coconut" } | ||
end | ||
end | ||
|
||
class Query < GraphQL::Schema::Object | ||
field :gadget_a, Gadget, null: false do | ||
directive Boundary, key: "id" | ||
argument :id, ID, required: true | ||
end | ||
|
||
def gadget_a(id:) | ||
{ id: id, name: "A#{id}", unique_to_a: "AA" } | ||
end | ||
end | ||
|
||
query Query | ||
end | ||
|
||
# ShareableB | ||
|
||
class ShareableB < GraphQL::Schema | ||
class Gizmo < GraphQL::Schema::Object | ||
field :a, String, null: false | ||
field :b, String, null: false | ||
field :c, String, null: false | ||
end | ||
|
||
class Gadget < GraphQL::Schema::Object | ||
field :id, ID, null: false | ||
field :name, String, null: false | ||
field :gizmo, Gizmo, null: false | ||
field :unique_to_b, String, null: false | ||
|
||
def gizmo | ||
{ a: "aardvark", b: "bat", c: "cat" } | ||
end | ||
end | ||
|
||
class Query < GraphQL::Schema::Object | ||
field :gadget_b, Gadget, null: false do | ||
directive Boundary, key: "id" | ||
argument :id, ID, required: true | ||
end | ||
|
||
def gadget_b(id:) | ||
{ id: id, name: "B#{id}", unique_to_b: "BB" } | ||
end | ||
end | ||
|
||
query Query | ||
end | ||
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