Skip to content
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
1 change: 1 addition & 0 deletions .c8rc.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"src/jsutils/Maybe.ts",
"src/jsutils/ObjMap.ts",
"src/jsutils/PromiseOrValue.ts",
"src/language/KindTypeMap.ts",
"src/utilities/typedQueryDocumentNode.ts",
"src/**/__tests__/**/*.ts"
],
Expand Down
15 changes: 11 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
run: npm run lint

- name: Check Types
run: npm run check
run: npm run check:ts

- name: Lint Prettier
run: npm run prettier:check
Expand Down Expand Up @@ -244,7 +244,7 @@ jobs:
name: denoDist
path: ./denoDist

type-check-deno-dist:
check-deno-dist:
name: Type check denoDist on Deno v${{ matrix.deno_version_to_setup }}
needs: build-deno-dist
runs-on: ubuntu-latest
Expand All @@ -268,5 +268,12 @@ jobs:
with:
deno-version: ${{ matrix.deno_version_to_setup }}

- name: Check denoDist package
run: deno check ./denoDist/index.ts
- name: Run denoDist package publish dry-run checks
# `deno publish --dry-run` performs a number of checks including:
# (a) type-checking package modules/public API,
# (b) validating exports and module-graph resolution,
# (c) validating the publish file set (gitignore + publish.exclude/include),
# (d) validating package metadata/config, and
# (e) enforcing JSR slow-types checks.
working-directory: ./denoDist
run: deno publish --dry-run
7 changes: 1 addition & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,9 @@ jobs:
runs-on: ubuntu-latest
environment: release
permissions:
contents: read # for actions/checkout
contents: read # for actions/download-artifact
id-token: write # for JSR trusted publishing via OIDC
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Download denoDist package
uses: actions/download-artifact@v4
with:
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
"benchmark": "node --import ./resources/register-ts-node.js resources/benchmark.ts",
"test": "npm run lint && npm run check && npm run testonly:cover && npm run prettier:check && npm run check:spelling && npm run check:integrations",
"lint": "eslint --cache --max-warnings 0 .",
"check": "tsc --pretty",
"check": "npm run check:ts && npm run check:deno",
"check:ts": "tsc --pretty",
"check:deno": "npm run build:deno && deno publish --dry-run --allow-dirty --config denoDist/jsr.json",
"testonly": "mocha --full-trace src/**/__tests__/**/*-test.ts",
"testonly:cover": "c8 npm run testonly",
"testonly:watch": "npm run testonly -- --watch",
Expand Down
7 changes: 7 additions & 0 deletions resources/build-deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ interface JSRConfig {
name: string;
version: string;
exports: { [entrypoint: string]: string };
publish: {
exclude: ReadonlyArray<string>;
};
}

async function writeJSRConfig(
Expand Down Expand Up @@ -122,6 +125,10 @@ async function writeJSRConfig(
name: '@graphql/graphql-js',
version,
exports: jsrExports,
publish: {
// The package root is `denoDist/`, so unignore relative to that root.
exclude: ['!.'],
},
};

const prettified = await prettify(jsrConfigPath, JSON.stringify(jsrConfig));
Expand Down
8 changes: 5 additions & 3 deletions resources/change-extension-in-import-paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ import ts from 'typescript';
* ```
*
*/
export function changeExtensionInImportPaths(config: { extension: string }) {
export function changeExtensionInImportPaths(config: {
extension: string;
}): ts.TransformerFactory<ts.SourceFile> {
const { extension } = config;
return (context: ts.TransformationContext) => {
return (context: ts.TransformationContext): ts.Transformer<ts.SourceFile> => {
const { factory } = context;

return visitSourceFile;

function visitSourceFile(sourceFile: ts.SourceFile) {
function visitSourceFile(sourceFile: ts.SourceFile): ts.SourceFile {
return ts.visitNode(sourceFile, visitNode, ts.isSourceFile);
}

Expand Down
7 changes: 6 additions & 1 deletion resources/gen-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ export const version = '${version}' as string;
/**
* An object containing the components of the GraphQL.js version string
*/
export const versionInfo = Object.freeze({
export const versionInfo: Readonly<{
major: number;
minor: number;
patch: number;
preReleaseTag: string | null;
}> = Object.freeze({
major: ${major} as number,
minor: ${minor} as number,
patch: ${patch} as number,
Expand Down
6 changes: 4 additions & 2 deletions resources/inline-invariant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import ts from 'typescript';
*
* if (!(<cond>)) invariant(false, ...)
*/
export function inlineInvariant(context: ts.TransformationContext) {
export function inlineInvariant(
context: ts.TransformationContext,
): ts.Transformer<ts.SourceFile> {
const { factory } = context;

return visitSourceFile;

function visitSourceFile(sourceFile: ts.SourceFile) {
function visitSourceFile(sourceFile: ts.SourceFile): ts.SourceFile {
return ts.visitNode(sourceFile, visitNode, ts.isSourceFile);
}

Expand Down
23 changes: 17 additions & 6 deletions src/__testUtils__/expectJSON.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,33 @@ function toJSONDeep(value: unknown): unknown {
return mapValue(value, toJSONDeep);
}

export function expectJSON(actual: unknown) {
export function expectJSON(actual: unknown): {
toDeepEqual: (expected: unknown) => ReturnType<typeof expect>;
toDeepNestedProperty: (
path: string,
expected: unknown,
) => ReturnType<typeof expect>;
} {
const actualJSON = toJSONDeep(actual);

return {
toDeepEqual(expected: unknown) {
toDeepEqual(expected: unknown): ReturnType<typeof expect> {
const expectedJSON = toJSONDeep(expected);
expect(actualJSON).to.deep.equal(expectedJSON);
return expect(actualJSON).to.deep.equal(expectedJSON);
},
toDeepNestedProperty(path: string, expected: unknown) {
toDeepNestedProperty(
path: string,
expected: unknown,
): ReturnType<typeof expect> {
const expectedJSON = toJSONDeep(expected);
expect(actualJSON).to.deep.nested.property(path, expectedJSON);
return expect(actualJSON).to.deep.nested.property(path, expectedJSON);
},
};
}

export function expectToThrowJSON(fn: () => unknown) {
export function expectToThrowJSON(
fn: () => unknown,
): ReturnType<typeof expect> {
function mapException(): unknown {
try {
return fn();
Expand Down
11 changes: 8 additions & 3 deletions src/__testUtils__/expectPromise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@ import { assert, expect } from 'chai';
import { inspect } from '../jsutils/inspect.js';
import { isPromise } from '../jsutils/isPromise.js';

export function expectPromise(maybePromise: unknown) {
interface PromiseExpectation {
toResolve: () => Promise<unknown>;
toRejectWith: (message: string) => Promise<void>;
}

export function expectPromise(maybePromise: unknown): PromiseExpectation {
assert(
isPromise(maybePromise),
`Expected a promise, received '${inspect(maybePromise)}'`,
);

return {
toResolve() {
toResolve(): Promise<unknown> {
return maybePromise;
},
async toRejectWith(message: string) {
async toRejectWith(message: string): Promise<void> {
let caughtError: unknown;
let resolved;
let rejected = false;
Expand Down
2 changes: 1 addition & 1 deletion src/__testUtils__/viralSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ const Query = new GraphQLObjectType({
},
});

export const viralSchema = new GraphQLSchema({
export const viralSchema: GraphQLSchema = new GraphQLSchema({
query: Query,
});
10 changes: 7 additions & 3 deletions src/execution/Executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ export interface ValidatedExecutionArgs {
* type. Memoizing ensures the subfields are not repeatedly calculated, which
* saves overhead when resolving lists of values.
*/
export const collectSubfields = memoize3(
export const collectSubfields: (
validatedExecutionArgs: ValidatedExecutionArgs,
returnType: GraphQLObjectType,
fieldDetailsList: FieldDetailsList,
) => ReturnType<typeof _collectSubfields> = memoize3(
(
validatedExecutionArgs: ValidatedExecutionArgs,
returnType: GraphQLObjectType,
Expand All @@ -138,7 +142,7 @@ export const collectSubfields = memoize3(
},
);

export const getStreamUsage = memoize2(
export const getStreamUsage: typeof _getStreamUsage = memoize2(
(
validatedExecutionArgs: ValidatedExecutionArgs,
fieldDetailsList: FieldDetailsList,
Expand All @@ -160,7 +164,7 @@ class CollectedErrors {
return this._errors;
}

add(error: GraphQLError, path: Path | undefined) {
add(error: GraphQLError, path: Path | undefined): void {
// Do not modify errors list if the execution position for this error or
// any of its ancestors has already been nulled via error propagation.
// This check should be unnecessary for implementations able to implement
Expand Down
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,11 @@ export type {

// Parse and operate on GraphQL language source files.
// @see https://github.com/typescript-eslint/typescript-eslint/issues/10313

// Deno misclassifies this merged value+type re-export and requires `export type`.
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore TS1205
export { Kind } from './language/kinds.js';

export {
Token,
Source,
Expand Down
2 changes: 1 addition & 1 deletion src/jsutils/AccumulatorMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
export class AccumulatorMap<K, T> extends Map<K, Array<T>> {
override get [Symbol.toStringTag]() {
override get [Symbol.toStringTag](): string {
return 'AccumulatorMap';
}

Expand Down
7 changes: 7 additions & 0 deletions src/language/KindTypeMap.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* eslint-disable import/no-namespace */
import type * as Kind_ from './kinds_.js';

// Keep the kind literal map available as a type-only import for `ast.ts`.
// This avoids depending on the `Kind` runtime namespace in type positions,
// which Deno's publish type-output validation rejects for this package shape.
export type KindTypeMap = typeof Kind_;
Loading
Loading