Skip to content

Commit

Permalink
Deprecate resolvePresets in favour of resolvePreset (#2253)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjie authored Nov 27, 2024
2 parents db406b7 + 2c8cb5e commit ae2bf43
Show file tree
Hide file tree
Showing 37 changed files with 370 additions and 380 deletions.
8 changes: 8 additions & 0 deletions .changeset/nine-suits-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"graphile-config": patch
---

🚨 `{}` is no longer a valid `GraphileConfig.ResolvedPreset`; use
`resolvePreset({})`

Also: adds `resolvePreset(preset)` and deprecates `resolvePresets(presets)`.
4 changes: 2 additions & 2 deletions grafast/bench/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { pathToFileURL } from "node:url";

import { glob } from "glob";
import { isSchema } from "grafast/graphql";
import { resolvePresets } from "graphile-config";
import { resolvePreset } from "graphile-config";
import type { ArgsFromOptions, Argv } from "graphile-config/cli";
import { loadConfig } from "graphile-config/load";

Expand Down Expand Up @@ -49,7 +49,7 @@ async function configFromArgs(args: ArgsFromOptions<typeof options>) {
preset.bench.operations = operations;
}

const config = resolvePresets([preset]);
const config = resolvePreset(preset);
return config;
}

Expand Down
4 changes: 2 additions & 2 deletions grafast/dataplan-pg/scripts/runExampleSchema.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { makePgService } from "@dataplan/pg/adaptors/pg";
import { readFile } from "fs/promises";
import { sync as globSync } from "glob";
import { grafast } from "grafast";
import { resolvePresets } from "graphile-config";
import { resolvePreset } from "graphile-config";
import { isAsyncIterable } from "iterall";
import JSON5 from "json5";

Expand All @@ -33,7 +33,7 @@ const preset = {
},
},
};
const resolvedPreset = resolvePresets([preset]);
const resolvedPreset = resolvePreset(preset);

async function runTestQuery(basePath) {
const source = await readFile(`${basePath}.test.graphql`, "utf8");
Expand Down
15 changes: 7 additions & 8 deletions grafast/grafast/__tests__/awkward-identifiers-test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { expect } from "chai";
import { resolvePreset } from "graphile-config";
import { ExecutionResult, parse } from "graphql";
import { it } from "mocha";

Expand Down Expand Up @@ -89,13 +90,11 @@ it("ok", () => {
}
}`;
expect(JSON.stringify(result.data, null, 2)).to.equal(expected);
const result2 = execute(
{
schema,
document: parse(source),
},
{},
true,
) as any;
const result2 = execute({
schema,
document: parse(source),
resolvedPreset: resolvePreset({}),
outputDataAsString: true,
}) as any;
expect(JSON.stringify(JSON.parse(result2.data), null, 2)).to.equal(expected);
});
10 changes: 7 additions & 3 deletions grafast/grafast/__tests__/errorHandling-test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable graphile-export/exhaustive-deps, graphile-export/export-methods, graphile-export/export-instances, graphile-export/export-subclasses, graphile-export/no-nested */
import { expect } from "chai";
import { resolvePreset } from "graphile-config";
import type { AsyncExecutionResult, ExecutionResult } from "graphql";
import { it } from "mocha";

Expand All @@ -14,6 +15,9 @@ import {
sideEffect,
} from "../dist/index.js";

const resolvedPreset = resolvePreset({});
const requestContext = {};

declare global {
namespace Grafast {
interface Context {
Expand Down Expand Up @@ -146,7 +150,7 @@ it(
requestContext: {
mol: 42,
},
resolvedPreset: {},
resolvedPreset,
})) as AsyncGenerator<AsyncExecutionResult>;
let payloads: AsyncExecutionResult[] = [];
for await (const payload of stream) {
Expand Down Expand Up @@ -185,8 +189,8 @@ it(
variableValues: {
arr: ["A", "b"],
},
requestContext: {},
resolvedPreset: {},
requestContext,
resolvedPreset,
})) as ExecutionResult;
expect(result.errors).to.be.undefined;
expect(result.data).to.deep.equal({
Expand Down
18 changes: 10 additions & 8 deletions grafast/grafast/__tests__/errorHandlingStreamTermination-test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable graphile-export/exhaustive-deps, graphile-export/export-methods, graphile-export/export-instances, graphile-export/export-subclasses, graphile-export/no-nested */
import { expect } from "chai";
import { resolvePreset } from "graphile-config";
import type { AsyncExecutionResult } from "graphql";
import { it } from "mocha";

Expand All @@ -14,6 +15,9 @@ import {
} from "../dist/index.js";
import type { StreamDetails } from "../dist/interfaces.js";

const resolvedPreset = resolvePreset({});
const requestContext = {};

const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));

class SyncListCallbackStep<
Expand Down Expand Up @@ -158,14 +162,12 @@ function throwOnUnhandledRejections(callback: () => Promise<void>) {
streams--;
}
});
const stream = await grafast(
{
schema,
source,
},
{},
{},
);
const stream = await grafast({
schema,
source,
resolvedPreset,
requestContext,
});

let payloads: AsyncExecutionResult[] = [];
const wasAStream = isAsyncIterable(stream);
Expand Down
6 changes: 2 additions & 4 deletions grafast/grafast/__tests__/forbidden-test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
/* eslint-disable graphile-export/exhaustive-deps, graphile-export/export-methods, graphile-export/export-instances, graphile-export/export-subclasses, graphile-export/no-nested */
import { expect } from "chai";
import type { AsyncExecutionResult, ExecutionResult } from "graphql";
import type { ExecutionResult } from "graphql";
import { it } from "mocha";

import type { ExecutionDetails, PromiseOrDirect } from "../dist/index.js";
import type { ExecutionDetails } from "../dist/index.js";
import {
arrayOfLength,
constant,
ExecutableStep,
grafast,
lambda,
makeGrafastSchema,
} from "../dist/index.js";

Expand Down
79 changes: 34 additions & 45 deletions grafast/grafast/__tests__/inputs-test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
/* eslint-disable graphile-export/exhaustive-deps, graphile-export/export-methods, graphile-export/export-instances, graphile-export/export-subclasses, graphile-export/no-nested */
import { expect } from "chai";
import type { AsyncExecutionResult, ExecutionResult } from "graphql";
import { resolvePreset } from "graphile-config";
import type { ExecutionResult } from "graphql";
import { it } from "mocha";

import type { PromiseOrDirect } from "../dist/index.js";
import {
constant,
ExecutableStep,
grafast,
lambda,
makeGrafastSchema,
} from "../dist/index.js";
import { grafast, makeGrafastSchema } from "../dist/index.js";

const resolvedPreset = resolvePreset({});
const requestContext = {};

const makeSchema = (useStreamableStep = false) => {
return makeGrafastSchema({
Expand Down Expand Up @@ -81,15 +78,13 @@ it("executes with matching types", async () => {
nnlos3: [null, null, null],
nnlonns1: ["1", "2", "3"],
};
const result = (await grafast(
{
schema,
source,
variableValues,
},
{},
{},
)) as ExecutionResult;
const result = (await grafast({
schema,
source,
variableValues,
resolvedPreset,
requestContext,
})) as ExecutionResult;
expect(result.data).to.deep.equal(variableValues);
});

Expand Down Expand Up @@ -120,15 +115,13 @@ it("executes with stricter inner type", async () => {
nnlos1: ["1", "2", "3"],
nnlonns1: ["1", "2", "3"],
};
const result = (await grafast(
{
schema,
source,
variableValues,
},
{},
{},
)) as ExecutionResult;
const result = (await grafast({
schema,
source,
variableValues,
resolvedPreset,
requestContext,
})) as ExecutionResult;
expect(result.data).to.deep.equal(variableValues);
});

Expand Down Expand Up @@ -165,15 +158,13 @@ it("executes with stricter outer type", async () => {
nnlos3: [null, null, null],
nnlonns1: ["1", "2", "3"],
};
const result = (await grafast(
{
schema,
source,
variableValues,
},
{},
{},
)) as ExecutionResult;
const result = (await grafast({
schema,
source,
variableValues,
resolvedPreset,
requestContext,
})) as ExecutionResult;
expect(result.data).to.deep.equal(variableValues);
});

Expand All @@ -198,14 +189,12 @@ it("executes with stricter inner and outer type", async () => {
nnlos1: ["1", "2", "3"],
nnlonns1: ["1", "2", "3"],
};
const result = (await grafast(
{
schema,
source,
variableValues,
},
{},
{},
)) as ExecutionResult;
const result = (await grafast({
schema,
source,
variableValues,
resolvedPreset,
requestContext,
})) as ExecutionResult;
expect(result.data).to.deep.equal(variableValues);
});
Loading

0 comments on commit ae2bf43

Please sign in to comment.