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

Upgrade @apollo libraries and fix usage of fed-internals #266

Merged
merged 2 commits into from
Nov 17, 2023
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
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@
"dev": "node bin/index.js",
"dev:customer": "node bin/index.js audit --account <account-name>",
"check:lint": "yarn eslint",
"check:tcs": "yarn tsc"
"check:tsc": "yarn tsc"
},
"dependencies": {
"@apollo/composition": "^2.2.1",
"@apollo/composition": "^2.5.7",
"@apollo/federation-1": "npm:@apollo/[email protected]",
"@apollo/federation-internals": "^2.2.1",
"@apollo/gateway": "^2.2.1",
"@apollo/query-planner": "^2.2.1",
"@apollo/federation-internals": "^2.5.7",
"@apollo/gateway": "^2.5.7",
"@apollo/query-planner": "^2.5.7",
"@apollo/query-planner-1": "npm:@apollo/[email protected]",
"@apollo/subgraph": "^2.2.1",
"@apollo/subgraph": "^2.5.7",
"@urql/core": "^2.6.0",
"cli-progress": "^3.11.2",
"clipanion": "^3.2.0-rc.11",
Expand Down
3 changes: 2 additions & 1 deletion src/federation/normalize-2.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { parse, print, visit } from 'graphql';
* @typedef {import('@apollo/query-planner').QueryPlanSelectionNode} QueryPlanSelectionNode
* @typedef {import('@apollo/query-planner').QueryPlan} QueryPlan
* @typedef {import('@apollo/query-planner').PlanNode} PlanNode
* @typedef {import('@apollo/query-planner').SubscriptionNode} SubscriptionNode
* @typedef {import('../typings').QueryPlanVisitor2} QueryPlanVisitor
*/

Expand All @@ -14,7 +15,7 @@ import { parse, print, visit } from 'graphql';
function visitQueryPlan(plan, visitor) {
const newPlan = { ...plan };
/**
* @param {PlanNode} node
* @param {PlanNode | SubscriptionNode} node
*/
function recurse(node) {
const newNode = { ...node };
Expand Down
51 changes: 36 additions & 15 deletions src/federation/queryPlanToMermaid.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function hash() {
* sharable package
*
* https://github.com/mdg-private/studio-ui/blob/f4341fd691794e68901b5122403b038749d15a82/src/app/graph/explorerPage/resultsPane/queryPlan/queryPlanToMermaid.ts#L137
* @param {import("@apollo/query-planner-1").PlanNode|import("@apollo/query-planner").PlanNode} currentNode
* @param {import("@apollo/query-planner-1").PlanNode|import("@apollo/query-planner").PlanNode|import("@apollo/query-planner").SubscriptionNode} currentNode
* @return {{nodeText: string, startHash: string, endHash: string}}
*/
function process(currentNode) {
Expand All @@ -28,28 +28,27 @@ function process(currentNode) {
return `
${link}
${processedChild.nodeText}
`;
`;
})
.join(''),
};
}
case 'Parallel': {
const nodeHash = hash();
const children = currentNode.nodes.map((childNode) => {
const processedChild = process(childNode);
return `
${nodeHash} --> ${processedChild.startHash}
${processedChild.nodeText}
`;
});
return {
startHash: nodeHash,
endHash: nodeHash,
nodeText: `
${nodeHash}("Parallel")

${currentNode.nodes
.map((node) => {
const processedChild = process(node);
return `
${nodeHash} --> ${processedChild.startHash}
${processedChild.nodeText}
`;
})
.join('')}
${children.join('')}
`,
};
}
Expand All @@ -71,18 +70,17 @@ function process(currentNode) {
case 'Flatten': {
const nodeHash = hash();
const processedChild = process(currentNode.node);
const nodePath = currentNode.path.join(',').replaceAll('@', '[]');

return {
startHash: processedChild.startHash,
endHash: nodeHash,
nodeText: `
${nodeHash}("Flatten (${currentNode.path
.join(',')
.replaceAll('@', '[]')})")
${nodeHash}("Flatten (${nodePath})")

${processedChild.endHash} --> ${nodeHash}
${processedChild.nodeText}
`,
`,
};
}
case 'Condition': {
Expand All @@ -101,6 +99,29 @@ function process(currentNode) {
nodeText: `${nodeHash}("Defer")`,
};
}
case 'Subscription': {
const nodeHash = hash();
const processedPrimary = process(currentNode.primary);
const processedRest = currentNode.rest ? process(currentNode.rest) : null;
const restNodeText = processedRest
? `
${nodeHash} --> ("Rest ${processedRest.startHash}")
${processedRest.nodeText}
`
: '';

return {
startHash: nodeHash,
endHash: nodeHash,
nodeText: `
${nodeHash}("Subscription")

${nodeHash} --> ("Primary ${processedPrimary.startHash}")
${processedPrimary.nodeText}
${restNodeText}
`,
};
}
default:
return currentNode;
}
Expand Down
13 changes: 8 additions & 5 deletions src/federation/two.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { compose } from '@apollo/composition';
import {
buildSubgraph,
buildSupergraphSchema,
errorCauses,
operationFromDocument,
Subgraphs,
Supergraph,
} from '@apollo/federation-internals';
import { QueryPlanner } from '@apollo/query-planner';
import { GraphQLError, parse } from 'graphql';
Expand Down Expand Up @@ -58,7 +58,8 @@ export function queryPlan(schema, operationDoc, operationName) {
const operation = operationFromDocument(schema, documentNode, {
operationName,
});
const queryPlanner = new QueryPlanner(schema);
const supergraph = new Supergraph(schema, null, false);
const queryPlanner = new QueryPlanner(supergraph);
return queryPlanner.buildQueryPlan(operation);
}

Expand All @@ -73,10 +74,12 @@ export function queryPlanWithFed1Schema(
operationName,
) {
const documentNode = parse(operationDoc);
const [schema] = buildSupergraphSchema(supergraphSdl);
const operation = operationFromDocument(schema, documentNode, {
const supergraph = Supergraph.build(supergraphSdl, {
validateSupergraph: true,
});
const operation = operationFromDocument(supergraph.schema, documentNode, {
operationName,
});
const queryPlanner = new QueryPlanner(schema);
const queryPlanner = new QueryPlanner(supergraph);
return queryPlanner.buildQueryPlan(operation);
}
4 changes: 4 additions & 0 deletions src/federation/two.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,13 @@ Object {
"nodes": Array [
Object {
"id": undefined,
"inputRewrites": undefined,
"kind": "Fetch",
"operation": "query Search__products__0($search:[String!]){products(search:$search){__typename id name}}",
"operationDocumentNode": undefined,
"operationKind": "query",
"operationName": "Search__products__0",
"outputRewrites": undefined,
"requires": undefined,
"serviceName": "products",
"variableUsages": Array [
Expand All @@ -87,11 +89,13 @@ Object {
"kind": "Flatten",
"node": Object {
"id": undefined,
"inputRewrites": undefined,
"kind": "Fetch",
"operation": "query Search__reviews__1($representations:[_Any!]!){_entities(representations:$representations){...on Product{reviews{rating}}}}",
"operationDocumentNode": undefined,
"operationKind": "query",
"operationName": "Search__reviews__1",
"outputRewrites": undefined,
"requires": Array [
Object {
"kind": "InlineFragment",
Expand Down
Loading
Loading