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

Enable nested variables in stiching #1746

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
13 changes: 12 additions & 1 deletion src/Core/Language/Visitors/QuerySyntaxRewriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,18 @@ public virtual ISyntaxNode Rewrite(
case InlineFragmentNode inline:
return RewriteInlineFragment(inline, context);

case ObjectValueNode objectValue:
return RewriteObjectValue(objectValue, context);

case ListValueNode listValue:
return RewriteListValue(listValue, context);

case VariableNode variable:
return RewriteVariable(variable, context);

case IValueNode _:
return node;
michaelstaib marked this conversation as resolved.
Show resolved Hide resolved

default:
throw new NotSupportedException(
LangResources.QuerySyntaxRewriter_NotSupported);
Expand Down Expand Up @@ -209,7 +221,6 @@ protected virtual FieldNode RewriteField(
(p, c) => RewriteMany(p, c, RewriteDirective),
current.WithDirectives);


if (current.SelectionSet != null)
{
current = Rewrite(current, current.SelectionSet, context,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
interface Contract @source(name: "Contract", schema: "A") {
interface Contract @source(name: "Contract", schema: "A") {
id: ID!
}

Expand All @@ -16,6 +16,7 @@ type Customer @source(name: "Customer", schema: "B") {
id: ID!
name: String!
consultant: Consultant
complexArg(arg: ComplexInputType): String
}

type Consultant @source(name: "Consultant", schema: "B") {
Expand All @@ -24,3 +25,10 @@ type Consultant @source(name: "Consultant", schema: "B") {
}

union CustomerOrConsultant @source(name: "CustomerOrConsultant", schema: "B") = Customer | Consultant

input ComplexInputType @source(name: "ComplexInputType", schema: "B") {
deeper: ComplexInputType
deeperArray: [ComplexInputType]
value: String
valueArray: [String]
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type Query {
type Query {
customer(id: ID!): Customer @delegate(schema: "B")
consultant(id: ID!): Consultant @delegate(schema: "B")
customerOrConsultant(id: ID!): CustomerOrConsultant @delegate(schema: "B")
Expand All @@ -22,6 +22,7 @@ type Customer @source(name: "Customer", schema: "B") {
id: ID!
name: String!
consultant: Consultant
complexArg(arg: ComplexInputType): String
}

type Consultant @source(name: "Consultant", schema: "B") {
Expand All @@ -30,3 +31,10 @@ type Consultant @source(name: "Consultant", schema: "B") {
}

union CustomerOrConsultant @source(name: "CustomerOrConsultant", schema: "B") = Customer | Consultant

input ComplexInputType @source(name: "ComplexInputType", schema: "B") {
deeper: ComplexInputType
deeperArray: [ComplexInputType]
value: String
valueArray: [String]
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type Query {
type Query {
contract(contractId: ID!): Contract @delegate(schema: "A")
contracts(customerId: ID!): [Contract!] @delegate(schema: "A")
customer(id: ID!): Customer @delegate(schema: "B")
Expand All @@ -24,6 +24,7 @@ type Customer @source(name: "Customer", schema: "B") {
id: ID!
name: String!
consultant: Consultant
complexArg(arg: ComplexInputType): String
}

type Consultant @source(name: "Consultant", schema: "B") {
Expand All @@ -32,3 +33,10 @@ type Consultant @source(name: "Consultant", schema: "B") {
}

union CustomerOrConsultant @source(name: "CustomerOrConsultant", schema: "B") = Customer | Consultant

input ComplexInputType @source(name: "ComplexInputType", schema: "B") {
deeper: ComplexInputType
deeperArray: [ComplexInputType]
value: String
valueArray: [String]
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public async Task ExecuteStitchingQueryWithVariables()
.SetQuery(FileResource.Open(
"StitchingQueryWithVariables.graphql"))
.SetVariableValue("customerId", "Q3VzdG9tZXIKZDE=")
.SetVariableValue("deep", "deep")
.SetVariableValue("deeper", "deeper")
.Create();

// act
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"consultant": {
"name": "Jordan Belfort"
},
"complexArg": "",
"contracts": [
{
"id": "TGlmZUluc3VyYW5jZUNvbnRyYWN0CmQx",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type CreateCustomerPayload @source(name: "CreateCustomerPayload", schema: "custo
}

type Customer @source(name: "Customer", schema: "customer") {
complexArg(arg: ComplexInputType): String
consultant(customer: CustomerInput): Consultant
id: ID!
kind: CustomerKind!
Expand Down Expand Up @@ -103,6 +104,13 @@ type SomeOtherContract implements Contract @source(name: "SomeOtherContract", sc

union CustomerOrConsultant @source(name: "CustomerOrConsultant", schema: "customer") = Customer | Consultant

input ComplexInputType @source(name: "ComplexInputType", schema: "customer") {
deeper: ComplexInputType
deeperArray: [ComplexInputType]
value: String
valueArray: [String]
}

input CreateCustomerInput @source(name: "CreateCustomerInput", schema: "customer") {
consultantId: String
name: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type CreateCustomerPayload @source(name: "CreateCustomerPayload", schema: "custo
}

type Customer @source(name: "Customer", schema: "customer") {
complexArg(arg: ComplexInputType): String
consultant(customer: CustomerInput): Consultant
id: ID!
kind: CustomerKind!
Expand Down Expand Up @@ -104,6 +105,13 @@ type SomeOtherContract implements Contract @source(name: "SomeOtherContract", sc

union CustomerOrConsultant @source(name: "CustomerOrConsultant", schema: "customer") = Customer | Consultant

input ComplexInputType @source(name: "ComplexInputType", schema: "customer") {
deeper: ComplexInputType
deeperArray: [ComplexInputType]
value: String
valueArray: [String]
}

input CreateCustomerInput @source(name: "CreateCustomerInput", schema: "customer") {
consultantId: String
name: String
Expand Down
13 changes: 13 additions & 0 deletions src/Stitching/Stitching.Tests/Schemas/Customers/ComplexInput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace HotChocolate.Stitching.Schemas.Customers
{
public class ComplexInput
{
public string Value { get; set; }

public ComplexInput Deeper { get; set; }

public string[] ValueArray { get; set; }

public ComplexInput[] DeeperArray { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Linq;
using HotChocolate.Types;
using HotChocolate.Types.Relay;

namespace HotChocolate.Stitching.Schemas.Customers
{
public class ComplexInputType
: InputObjectType<ComplexInput>
{
protected override void Configure(
IInputObjectTypeDescriptor<ComplexInput> descriptor)
{
descriptor.Name("ComplexInputType");
descriptor.Field(t => t.Value).Type<StringType>();
descriptor.Field(t => t.Deeper).Type<ComplexInputType>();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ protected override void Configure(
.Type<StringType>()
.Resolver(ctx => string.Join(", ",
ctx.Argument<SayInput>("input").Words));

descriptor.Field("complexArg")
.Argument("arg", a =>
a.Type<ComplexInputType>())
.Type<StringType>()
.Resolver("");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
query fetch($customerId: ID!) {
query fetch($customerId: ID!, $deep: String!, $deeperInArray: String, $deeper: String!, $deeperArray: String, $complex: ComplexInputType) {
customer(id: $customerId) {
name
consultant {
name
__typename
}
complexArg(arg: { value: $deep, deeperArray: [ "CONSTANT_IN_ARRAY", $deeperInArray ], deeper: { value: "CONSTANT", deeper: { value: $deeper } }, deeperArray: [ { value: "CONSTANT_ARRAY", deeper: { value: $deeperArray } }, $complex ] })
id
__typename
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
query exec_batch($_b_customerId: ID!) {
query exec_batch($_b_customerId: ID!, $_b_deep: String!, $_b_deeper: String!, $_b_deeperArray: String, $_b_complex: ComplexInputType, $_b_deeperInArray: String) {
_a_customer: customerOrConsultant(id: "Q3VzdG9tZXIKZDE=") {
... _a_customer
... _a_consultant
Expand All @@ -12,6 +12,7 @@ query exec_batch($_b_customerId: ID!) {
consultant {
name
}
complexArg(arg: { value: $deep, deeperArray: [ "CONSTANT_IN_ARRAY", $deeperInArray ], deeper: { value: "CONSTANT", deeper: { value: $deeper } }, deeperArray: [ { value: "CONSTANT_ARRAY", deeper: { value: $deeperArray } }, $complex ] })
contracts {
id
... on LifeInsuranceContract {
Expand Down
8 changes: 8 additions & 0 deletions src/Stitching/Stitching.Tests/__resources__/Customer.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type Customer {
id: ID!
name: String!
consultant: Consultant
complexArg(arg: ComplexInputType): String
}

type Consultant {
Expand All @@ -16,3 +17,10 @@ type Consultant {
}

union CustomerOrConsultant = Customer | Consultant

input ComplexInputType {
deeper: ComplexInputType
deeperArray: [ComplexInputType]
value: String
valueArray: [String]
}
8 changes: 8 additions & 0 deletions src/Stitching/Stitching.Tests/__resources__/Stitching.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Query {
type Customer {
id: ID!
name: String!
complexArg(arg:ComplexInputType): String
consultant: Consultant
contracts: [Contract!]
@delegate(schema: "contract", path: "contracts(customerId:$fields:id)")
Expand Down Expand Up @@ -46,3 +47,10 @@ type SomeOtherContract implements Contract {
}

union CustomerOrConsultant = Customer | Consultant

input ComplexInputType {
deeper: ComplexInputType
deeperArray: [ComplexInputType]
value: String
valueArray: [String]
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
query customer_query($customerId: ID!) {
query customer_query(
$customerId: ID!
$deep: String!
$deeper: String!
$deeperArray: String
$complex: ComplexInputType
$deeperInArray: String
) {
customer(id: $customerId) {
name
consultant {
name
}
complexArg(
arg: {
value: $deep
deeperArray: ["CONSTANT_IN_ARRAY", $deeperInArray]
deeper: { value: "CONSTANT", deeper: { value: $deeper } }
deeperArray: [
{ value: "CONSTANT_ARRAY", deeper: { value: $deeperArray } }
$complex
]
}
)
contracts {
id
... on LifeInsuranceContract {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[
[
"type Query {\n contract(contractId: ID!): Contract\n contracts(customerId: ID!): [Contract!]\n}\n\ninterface Contract {\n id: ID!\n}\n\ntype LifeInsuranceContract implements Contract {\n id: ID!\n premium: Float\n}\n\ntype SomeOtherContract implements Contract {\n id: ID!\n expiryDate: DateTime\n}",
"type Query {\n customer(id: ID!): Customer\n consultant(id: ID!): Consultant\n customerOrConsultant(id: ID!): CustomerOrConsultant\n}\n\ntype Customer {\n id: ID!\n name: String!\n consultant: Consultant\n}\n\ntype Consultant {\n id: ID!\n name: String!\n}\n\nunion CustomerOrConsultant = Customer | Consultant"
"type Query {\n customer(id: ID!): Customer\n consultant(id: ID!): Consultant\n customerOrConsultant(id: ID!): CustomerOrConsultant\n}\n\ntype Customer {\n id: ID!\n name: String!\n consultant: Consultant\n complexArg(arg: ComplexInputType): String\n}\n\ntype Consultant {\n id: ID!\n name: String!\n}\n\nunion CustomerOrConsultant = Customer | Consultant\n\ninput ComplexInputType {\n deeper: ComplexInputType\n deeperArray: [ComplexInputType]\n value: String\n valueArray: [String]\n}"
]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[
[
"type Query {\n contract(contractId: ID!): Contract\n contracts(customerId: ID!): [Contract!]\n}\n\ninterface Contract {\n id: ID!\n}\n\ntype LifeInsuranceContract implements Contract {\n id: ID!\n premium: Float\n}\n\ntype SomeOtherContract implements Contract {\n id: ID!\n expiryDate: DateTime\n}",
"type Query {\n customer(id: ID!): Customer\n consultant(id: ID!): Consultant\n customerOrConsultant(id: ID!): CustomerOrConsultant\n}\n\ntype Customer {\n id: ID!\n name: String!\n consultant: Consultant\n}\n\ntype Consultant {\n id: ID!\n name: String!\n}\n\nunion CustomerOrConsultant = Customer | Consultant"
"type Query {\n customer(id: ID!): Customer\n consultant(id: ID!): Consultant\n customerOrConsultant(id: ID!): CustomerOrConsultant\n}\n\ntype Customer {\n id: ID!\n name: String!\n consultant: Consultant\n complexArg(arg: ComplexInputType): String\n}\n\ntype Consultant {\n id: ID!\n name: String!\n}\n\nunion CustomerOrConsultant = Customer | Consultant\n\ninput ComplexInputType {\n deeper: ComplexInputType\n deeperArray: [ComplexInputType]\n value: String\n valueArray: [String]\n}"
]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type Query {
type Query {
contract(contractId: ID!): Contract @delegate(schema: "contract")
contracts(customerId: ID!): [Contract!] @delegate(schema: "contract")
customer(id: ID!): Customer @delegate(schema: "customer")
Expand All @@ -24,6 +24,7 @@ type Customer @source(name: "Customer", schema: "customer") {
id: ID!
name: String!
consultant: Consultant
complexArg(arg: ComplexInputType): String
}

type Consultant @source(name: "Consultant", schema: "customer") {
Expand All @@ -32,3 +33,10 @@ type Consultant @source(name: "Consultant", schema: "customer") {
}

union CustomerOrConsultant @source(name: "CustomerOrConsultant", schema: "customer") = Customer | Consultant

input ComplexInputType @source(name: "ComplexInputType", schema: "customer") {
deeper: ComplexInputType
deeperArray: [ComplexInputType]
value: String
valueArray: [String]
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type Mutation {
}

type Customer @source(name: "Customer", schema: "customer") {
complexArg(arg: ComplexInputType): String
consultant(customer: CustomerInput): Consultant
id: ID!
kind: CustomerKind!
Expand All @@ -39,6 +40,13 @@ input SayInput @source(name: "SayInput", schema: "customer") {
words: [String]
}

input ComplexInputType @source(name: "ComplexInputType", schema: "customer") {
deeper: ComplexInputType
deeperArray: [ComplexInputType]
value: String
valueArray: [String]
}

"A connection to a list of items."
type CustomerConnection @source(name: "CustomerConnection", schema: "customer") {
"A list of edges."
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
type Query {
type Query {
contract(contractId: ID!): Contract @delegate(schema: "contract")
contracts(customerId: ID!): [Contract!] @delegate(schema: "contract")
customer(id: ID!): Customer @delegate(schema: "customer")
Expand All @@ -24,6 +24,7 @@ type Customer @source(name: "Customer", schema: "customer") {
id: ID!
name: String!
consultant: Consultant
complexArg(arg: ComplexInputType): String
}

type Consultant @source(name: "Consultant", schema: "customer") {
Expand All @@ -32,3 +33,10 @@ type Consultant @source(name: "Consultant", schema: "customer") {
}

union CustomerOrConsultant @source(name: "CustomerOrConsultant", schema: "customer") = Customer | Consultant

input ComplexInputType @source(name: "ComplexInputType", schema: "customer") {
deeper: ComplexInputType
deeperArray: [ComplexInputType]
value: String
valueArray: [String]
}
Loading