Skip to content

Commit

Permalink
update to fed 2.5 (#274)
Browse files Browse the repository at this point in the history
  • Loading branch information
lleadbet authored Jul 28, 2023
1 parent f61d8f0 commit 6953096
Show file tree
Hide file tree
Showing 6 changed files with 12,141 additions and 2,200 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"license": "MIT",
"type": "module",
"dependencies": {
"@apollo/gateway": "^2.4.0",
"@apollo/gateway": "^2.5.0",
"clipanion": "^3.2.0-rc.13",
"graphql": "^16.6.0",
"graphql-request": "^4.3.0",
Expand Down
20 changes: 10 additions & 10 deletions src/commands/default.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
operationFromDocument,
buildSupergraphSchema,
Supergraph
} from "@apollo/federation-internals";
import { QueryPlanner, prettyFormatQueryPlan } from "@apollo/query-planner";
import { Command, Option } from "clipanion";
Expand Down Expand Up @@ -31,8 +31,8 @@ export class DefaultCommand extends Command {
const result = this.supergraph
? await fetchSupergraphFromFile(this.supergraph)
: this.graphref
? await fetchSupergraphFromStudio(this.graphref, this.sudo ?? false)
: null;
? await fetchSupergraphFromStudio(this.graphref, this.sudo ?? false)
: null;

if (!result) {
this.context.stderr.write("cannot load supergraph");
Expand All @@ -41,7 +41,7 @@ export class DefaultCommand extends Command {

const operation = await readFile(this.operation, "utf-8");

const queryPlan = await generateQueryPlan(result[0], operation);
const queryPlan = await generateQueryPlan(result, operation);

if (this.pretty) {
this.context.stdout.write(prettyFormatQueryPlan(queryPlan));
Expand All @@ -53,24 +53,24 @@ export class DefaultCommand extends Command {
}

/**
* @param {import("@apollo/federation-internals").Schema} schema
* @param {import("@apollo/federation-internals").Supergraph} supergraph
* @param {string} operationDoc
* @param {string} [operationName]
*/
export async function generateQueryPlan(schema, operationDoc, operationName) {
export async function generateQueryPlan(supergraph, operationDoc, operationName) {
const documentNode = parse(operationDoc);
const operation = operationFromDocument(schema, documentNode, {
const operation = operationFromDocument(supergraph.schema, documentNode, {
operationName,
});
const queryPlanner = new QueryPlanner(schema);
const queryPlanner = new QueryPlanner(supergraph);
return queryPlanner.buildQueryPlan(operation);
}

/**
* @param {string} file
*/
async function fetchSupergraphFromFile(file) {
return buildSupergraphSchema(await readFile(file, "utf-8"));
return Supergraph.build(await readFile(file, "utf-8"));
}

/**
Expand Down Expand Up @@ -108,7 +108,7 @@ async function fetchSupergraphFromStudio(ref, sudo) {
return null;
}

return buildSupergraphSchema(
return Supergraph.build(
resp.variant.latestApprovedLaunch.build.result.coreSchema.coreDocument
);
}
Loading

0 comments on commit 6953096

Please sign in to comment.