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

add the operation kind to FetchNode #1427

Merged
merged 4 commits into from
Feb 10, 2022
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
52 changes: 52 additions & 0 deletions gateway-js/src/__tests__/build-query-plan.feature

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions query-planner-js/src/QueryPlan.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
Kind,
SelectionNode as GraphQLJSSelectionNode,
OperationTypeNode,
} from 'graphql';
import prettyFormat from 'pretty-format';
import { queryPlanSerializer, astSerializer } from './snapshotSerializers';
Expand Down Expand Up @@ -30,6 +31,7 @@ export interface FetchNode {
variableUsages?: string[];
requires?: QueryPlanSelectionNode[];
operation: string;
operationKind: OperationTypeNode;
}

export interface FlattenNode {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Scenario: handles an abstract type from the base service
"kind": "Fetch",
"serviceName": "product",
"variableUsages": ["upc"],
"operationKind": "query",
"operation": "query($upc:String!){product(upc:$upc){__typename ...on Book{__typename isbn upc price}...on Furniture{upc name price}}}"
},
{
Expand All @@ -41,6 +42,7 @@ Scenario: handles an abstract type from the base service
}
],
"variableUsages": [],
"operationKind": "query",
"operation": "query($representations:[_Any!]!){_entities(representations:$representations){...on Book{title year}}}"
}
},
Expand All @@ -63,6 +65,7 @@ Scenario: handles an abstract type from the base service
}
],
"variableUsages": [],
"operationKind": "query",
"operation": "query($representations:[_Any!]!){_entities(representations:$representations){...on Book{name}}}"
}
}
Expand Down Expand Up @@ -91,6 +94,7 @@ Scenario: can request fields on extended interfaces
"kind": "Fetch",
"serviceName": "product",
"variableUsages": ["upc"],
"operationKind": "query",
"operation": "query($upc:String!){product(upc:$upc){__typename ...on Book{__typename isbn}...on Furniture{__typename sku}}}"
},
{
Expand Down Expand Up @@ -118,6 +122,7 @@ Scenario: can request fields on extended interfaces
}
],
"variableUsages": [],
"operationKind": "query",
"operation": "query($representations:[_Any!]!){_entities(representations:$representations){...on Book{inStock}...on Furniture{inStock}}}"
}
}
Expand Down Expand Up @@ -149,6 +154,7 @@ Scenario: can request fields on extended types that implement an interface
"kind": "Fetch",
"serviceName": "product",
"variableUsages": ["upc"],
"operationKind": "query",
"operation": "query($upc:String!){product(upc:$upc){__typename ...on Book{__typename isbn}...on Furniture{__typename sku}}}"
},
{
Expand Down Expand Up @@ -176,6 +182,7 @@ Scenario: can request fields on extended types that implement an interface
}
],
"variableUsages": [],
"operationKind": "query",
"operation": "query($representations:[_Any!]!){_entities(representations:$representations){...on Book{inStock}...on Furniture{inStock isHeavy}}}"
}
}
Expand Down Expand Up @@ -210,6 +217,7 @@ Scenario: prunes unfilled type conditions
"kind": "Fetch",
"serviceName": "product",
"variableUsages": ["upc"],
"operationKind": "query",
"operation": "query($upc:String!){product(upc:$upc){__typename ...on Book{__typename isbn}...on Furniture{__typename sku}}}"
},
{
Expand Down Expand Up @@ -237,6 +245,7 @@ Scenario: prunes unfilled type conditions
}
],
"variableUsages": [],
"operationKind": "query",
"operation": "query($representations:[_Any!]!){_entities(representations:$representations){...on Book{inStock isCheckedOut}...on Furniture{inStock isHeavy}}}"
}
}
Expand Down Expand Up @@ -272,6 +281,7 @@ Scenario: fetches interfaces returned from other services
"kind": "Fetch",
"serviceName": "accounts",
"variableUsages": [],
"operationKind": "query",
"operation": "{me{__typename id}}"
},
{
Expand All @@ -291,6 +301,7 @@ Scenario: fetches interfaces returned from other services
}
],
"variableUsages": [],
"operationKind": "query",
"operation": "query($representations:[_Any!]!){_entities(representations:$representations){...on User{reviews{product{__typename ...on Book{__typename isbn}...on Furniture{__typename upc}}}}}}"
}
},
Expand All @@ -314,6 +325,7 @@ Scenario: fetches interfaces returned from other services
}
],
"variableUsages": [],
"operationKind": "query",
"operation": "query($representations:[_Any!]!){_entities(representations:$representations){...on Book{title}}}"
}
},
Expand Down Expand Up @@ -342,6 +354,7 @@ Scenario: fetches interfaces returned from other services
}
],
"variableUsages": [],
"operationKind": "query",
"operation": "query($representations:[_Any!]!){_entities(representations:$representations){...on Book{price}...on Furniture{price}}}"
}
}
Expand Down Expand Up @@ -379,6 +392,7 @@ Scenario: fetches composite fields from a foreign type casted to an interface [@
"kind": "Fetch",
"serviceName": "accounts",
"variableUsages": [],
"operationKind": "query",
"operation": "{me{__typename id}}"
},
{
Expand All @@ -398,6 +412,7 @@ Scenario: fetches composite fields from a foreign type casted to an interface [@
}
],
"variableUsages": [],
"operationKind": "query",
"operation": "query($representations:[_Any!]!){_entities(representations:$representations){...on User{reviews{product{__typename ...on Book{__typename isbn}...on Furniture{__typename upc}}}}}}"
}
},
Expand Down Expand Up @@ -429,6 +444,7 @@ Scenario: fetches composite fields from a foreign type casted to an interface [@
}
],
"variableUsages": [],
"operationKind": "query",
"operation": "query($representations:[_Any!]!){_entities(representations:$representations){...on Book{price}...on Furniture{price}}}"
}
},
Expand All @@ -452,6 +468,7 @@ Scenario: fetches composite fields from a foreign type casted to an interface [@
}
],
"variableUsages": [],
"operationKind": "query",
"operation": "query($representations:[_Any!]!){_entities(representations:$representations){...on Book{title year}}}"
}
},
Expand All @@ -474,6 +491,7 @@ Scenario: fetches composite fields from a foreign type casted to an interface [@
}
],
"variableUsages": [],
"operationKind": "query",
"operation": "query($representations:[_Any!]!){_entities(representations:$representations){...on Book{name}}}"
}
}
Expand Down Expand Up @@ -508,6 +526,7 @@ Scenario: allows for extending an interface from another service with fields
"kind": "Fetch",
"serviceName": "product",
"variableUsages": ["upc"],
"operationKind": "query",
"operation": "query($upc:String!){product(upc:$upc){__typename ...on Book{__typename isbn}...on Furniture{__typename upc}}}"
},
{
Expand Down Expand Up @@ -535,6 +554,7 @@ Scenario: allows for extending an interface from another service with fields
}
],
"variableUsages": [],
"operationKind": "query",
"operation": "query($representations:[_Any!]!){_entities(representations:$representations){...on Book{reviews{body}}...on Furniture{reviews{body}}}}"
}
}
Expand Down Expand Up @@ -577,6 +597,7 @@ Scenario: handles unions from the same service
"kind": "Fetch",
"serviceName": "accounts",
"variableUsages": [],
"operationKind": "query",
"operation": "{me{__typename id}}"
},
{
Expand All @@ -596,6 +617,7 @@ Scenario: handles unions from the same service
}
],
"variableUsages": [],
"operationKind": "query",
"operation": "query($representations:[_Any!]!){_entities(representations:$representations){...on User{reviews{product{__typename ...on Book{__typename isbn}...on Furniture{__typename upc}}}}}}"
}
},
Expand Down Expand Up @@ -624,6 +646,7 @@ Scenario: handles unions from the same service
}
],
"variableUsages": [],
"operationKind": "query",
"operation": "query($representations:[_Any!]!){_entities(representations:$representations){...on Book{price}...on Furniture{price brand{__typename ...on Ikea{asile}...on Amazon{referrer}}}}}"
}
}
Expand Down
11 changes: 11 additions & 0 deletions query-planner-js/src/__tests__/features/basic/aliases.feature
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Scenario: supports simple aliases
"kind": "Fetch",
"serviceName": "product",
"variableUsages": ["upc"],
"operationKind": "query",
"operation": "query($upc:String!){product(upc:$upc){__typename ...on Book{__typename isbn}...on Furniture{name title:name}}}"
},
{
Expand All @@ -41,6 +42,7 @@ Scenario: supports simple aliases
}
],
"variableUsages": [],
"operationKind": "query",
"operation": "query($representations:[_Any!]!){_entities(representations:$representations){...on Book{title year}}}"
}
},
Expand All @@ -63,6 +65,7 @@ Scenario: supports simple aliases
}
],
"variableUsages": [],
"operationKind": "query",
"operation": "query($representations:[_Any!]!){_entities(representations:$representations){...on Book{title:name name}}}"
}
}
Expand Down Expand Up @@ -98,6 +101,7 @@ Scenario: supports aliases of root fields on subservices
"kind": "Fetch",
"serviceName": "product",
"variableUsages": ["upc"],
"operationKind": "query",
"operation": "query($upc:String!){product(upc:$upc){__typename ...on Book{__typename isbn}...on Furniture{__typename upc name title:name}}}"
},
{
Expand Down Expand Up @@ -128,6 +132,7 @@ Scenario: supports aliases of root fields on subservices
}
],
"variableUsages": [],
"operationKind": "query",
"operation": "query($representations:[_Any!]!){_entities(representations:$representations){...on Book{reviews{body}productReviews:reviews{body}}...on Furniture{reviews{body}productReviews:reviews{body}}}}"
}
},
Expand All @@ -151,6 +156,7 @@ Scenario: supports aliases of root fields on subservices
}
],
"variableUsages": [],
"operationKind": "query",
"operation": "query($representations:[_Any!]!){_entities(representations:$representations){...on Book{title year}}}"
}
},
Expand All @@ -173,6 +179,7 @@ Scenario: supports aliases of root fields on subservices
}
],
"variableUsages": [],
"operationKind": "query",
"operation": "query($representations:[_Any!]!){_entities(representations:$representations){...on Book{title:name name}}}"
}
}
Expand Down Expand Up @@ -216,6 +223,7 @@ Scenario: supports aliases of nested fields on subservices
"kind": "Fetch",
"serviceName": "product",
"variableUsages": ["upc"],
"operationKind": "query",
"operation": "query($upc:String!){product(upc:$upc){__typename ...on Book{__typename isbn}...on Furniture{__typename upc name title:name}}}"
},
{
Expand Down Expand Up @@ -246,6 +254,7 @@ Scenario: supports aliases of nested fields on subservices
}
],
"variableUsages": [],
"operationKind": "query",
"operation": "query($representations:[_Any!]!){_entities(representations:$representations){...on Book{reviews{content:body body}productReviews:reviews{body reviewer:author{name:username}}}...on Furniture{reviews{content:body body}productReviews:reviews{body reviewer:author{name:username}}}}}"
}
},
Expand All @@ -269,6 +278,7 @@ Scenario: supports aliases of nested fields on subservices
}
],
"variableUsages": [],
"operationKind": "query",
"operation": "query($representations:[_Any!]!){_entities(representations:$representations){...on Book{title year}}}"
}
},
Expand All @@ -291,6 +301,7 @@ Scenario: supports aliases of nested fields on subservices
}
],
"variableUsages": [],
"operationKind": "query",
"operation": "query($representations:[_Any!]!){_entities(representations:$representations){...on Book{title:name name}}}"
}
}
Expand Down
13 changes: 13 additions & 0 deletions query-planner-js/src/__tests__/features/basic/boolean.feature
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Scenario: supports @skip when a boolean condition is met
"kind": "Fetch",
"serviceName": "reviews",
"variableUsages": [],
"operationKind": "query",
"operation": "{topReviews{body author@skip(if:true){__typename id}}}"
},
{
Expand All @@ -44,6 +45,7 @@ Scenario: supports @skip when a boolean condition is met
}
],
"variableUsages": [],
"operationKind": "query",
"operation": "query($representations:[_Any!]!){_entities(representations:$representations){...on User@skip(if:true){name{first}}}}"
}
}
Expand Down Expand Up @@ -72,6 +74,7 @@ Scenario: supports @skip when a boolean condition is met (variable driven)
"kind": "Fetch",
"serviceName": "reviews",
"variableUsages": ["skip"],
"operationKind": "query",
"operation": "query($skip:Boolean!=true){topReviews{body author@skip(if:$skip){username}}}"
}
}
Expand Down Expand Up @@ -102,6 +105,7 @@ Scenario: supports @skip when a boolean condition is not met
"kind": "Fetch",
"serviceName": "reviews",
"variableUsages": [],
"operationKind": "query",
"operation": "{topReviews{body author@skip(if:false){__typename id}}}"
},
{
Expand All @@ -121,6 +125,7 @@ Scenario: supports @skip when a boolean condition is not met
}
],
"variableUsages": [],
"operationKind": "query",
"operation": "query($representations:[_Any!]!){_entities(representations:$representations){...on User@skip(if:false){name{first}}}}"
}
}
Expand Down Expand Up @@ -154,6 +159,7 @@ Scenario: supports @skip when a boolean condition is not met (variable driven)
"kind": "Fetch",
"serviceName": "reviews",
"variableUsages": ["skip"],
"operationKind": "query",
"operation": "query($skip:Boolean!){topReviews{body author@skip(if:$skip){__typename id}}}"
},
{
Expand All @@ -173,6 +179,7 @@ Scenario: supports @skip when a boolean condition is not met (variable driven)
}
],
"variableUsages": ["skip"],
"operationKind": "query",
"operation": "query($representations:[_Any!]!$skip:Boolean!){_entities(representations:$representations){...on User@skip(if:$skip){name{first}}}}"
}
}
Expand Down Expand Up @@ -201,6 +208,7 @@ Scenario: supports @include when a boolean condition is not met
"kind": "Fetch",
"serviceName": "reviews",
"variableUsages": [],
"operationKind": "query",
"operation": "{topReviews{body author@include(if:false){username}}}"
}
}
Expand All @@ -226,6 +234,7 @@ Scenario: supports @include when a boolean condition is not met (variable driven
"kind": "Fetch",
"serviceName": "reviews",
"variableUsages": ["include"],
"operationKind": "query",
"operation": "query($include:Boolean!=false){topReviews{body author@include(if:$include){username}}}"
}
}
Expand Down Expand Up @@ -256,6 +265,7 @@ Scenario: supports @include when a boolean condition is met
"kind": "Fetch",
"serviceName": "reviews",
"variableUsages": [],
"operationKind": "query",
"operation": "{topReviews{body author@include(if:true){__typename id}}}"
},
{
Expand All @@ -275,6 +285,7 @@ Scenario: supports @include when a boolean condition is met
}
],
"variableUsages": [],
"operationKind": "query",
"operation": "query($representations:[_Any!]!){_entities(representations:$representations){...on User@include(if:true){name{first}}}}"
}
}
Expand Down Expand Up @@ -310,6 +321,7 @@ Scenario: supports @include when a boolean condition is met (variable driven)
"kind": "Fetch",
"serviceName": "reviews",
"variableUsages": ["include"],
"operationKind": "query",
"operation": "query($include:Boolean!){topReviews{body author@include(if:$include){__typename id}}}"
},
{
Expand All @@ -329,6 +341,7 @@ Scenario: supports @include when a boolean condition is met (variable driven)
}
],
"variableUsages": ["include"],
"operationKind": "query",
"operation": "query($representations:[_Any!]!$include:Boolean!){_entities(representations:$representations){...on User@include(if:$include){name{first}}}}"
}
}
Expand Down
Loading