Skip to content

Commit

Permalink
Showing 18 changed files with 1,795 additions and 2,636 deletions.
7 changes: 7 additions & 0 deletions .changeset/short-pets-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@gql.tada/cli-utils': patch
'@gql.tada/internal': patch
'gql.tada': patch
---

Upgrade dependencies
44 changes: 22 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
@@ -49,7 +49,7 @@
},
"dependencies": {
"@0no-co/graphql.web": "^1.0.5",
"@0no-co/graphqlsp": "^1.12.9",
"@0no-co/graphqlsp": "^1.12.13",
"@gql.tada/cli-utils": "workspace:*",
"@gql.tada/internal": "workspace:*"
},
@@ -111,35 +111,35 @@
"devDependencies": {
"@0no-co/typescript.js": "5.3.2-2",
"@actions/core": "^1.10.0",
"@actions/github": "^5.1.1",
"@babel/plugin-transform-block-scoping": "^7.23.4",
"@babel/plugin-transform-typescript": "^7.23.6",
"@changesets/cli": "^2.27.1",
"@actions/github": "^6.0.0",
"@babel/plugin-transform-block-scoping": "^7.25.0",
"@babel/plugin-transform-typescript": "^7.25.2",
"@changesets/cli": "^2.27.7",
"@changesets/get-github-info": "^0.6.0",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-commonjs": "^26.0.1",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-terser": "^0.4.4",
"@types/node": "^20.11.0",
"@typescript-eslint/eslint-plugin": "^6.18.1",
"@typescript-eslint/parser": "^6.18.1",
"dotenv": "^16.3.1",
"@types/node": "^22.4.0",
"@typescript-eslint/eslint-plugin": "^8.1.0",
"@typescript-eslint/parser": "^8.1.0",
"dotenv": "^16.4.5",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-tsdoc": "^0.2.17",
"expect-type": "^0.17.3",
"graphql": "^16.8.1",
"lint-staged": "^15.2.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-tsdoc": "^0.3.0",
"expect-type": "^0.19.0",
"graphql": "^16.9.0",
"lint-staged": "^15.2.9",
"npm-run-all": "^4.1.5",
"prettier": "^3.1.1",
"rimraf": "^5.0.5",
"rollup": "^4.9.4",
"prettier": "^3.3.3",
"rimraf": "^6.0.1",
"rollup": "^4.21.0",
"rollup-plugin-cjs-check": "^1.0.3",
"rollup-plugin-dts": "^6.1.0",
"terser": "^5.26.0",
"typescript": "^5.5.2",
"vitest": "1.1.3"
"rollup-plugin-dts": "^6.1.1",
"terser": "^5.31.6",
"typescript": "^5.5.4",
"vitest": "2.0.5"
},
"publishConfig": {
"access": "public",
6 changes: 3 additions & 3 deletions packages/cli-utils/package.json
Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@
"devDependencies": {
"@clack/prompts": "^0.7.0",
"@types/node": "^20.11.0",
"@volar/source-map": "^2.1.6",
"@volar/source-map": "~2.1.6",
"clipanion": "4.0.0-rc.3",
"execa": "^8.0.1",
"rollup": "^4.9.4",
@@ -54,7 +54,7 @@
"wonka": "^6.3.4"
},
"dependencies": {
"@0no-co/graphqlsp": "^1.12.9",
"@0no-co/graphqlsp": "^1.12.13",
"@gql.tada/internal": "workspace:*",
"graphql": "^15.5.0 || ^16.0.0 || ^17.0.0"
},
@@ -67,7 +67,7 @@
}
},
"peerDependencies": {
"@0no-co/graphqlsp": "^1.12.9",
"@0no-co/graphqlsp": "^1.12.13",
"@gql.tada/svelte-support": "workspace:*",
"@gql.tada/vue-support": "workspace:*",
"graphql": "^15.5.0 || ^16.0.0 || ^17.0.0",
3 changes: 2 additions & 1 deletion packages/cli-utils/src/commands/check/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as t from 'typanion';
import { Command, Option } from 'clipanion';

import { exitCode } from '../../utils/error';
import { initTTY } from '../../term';
import { run } from './runner';

@@ -30,6 +31,6 @@ export class CheckCommand extends Command {
tsconfig: this.tsconfig,
})
);
return process.exitCode || (typeof result === 'object' ? result.exit : 0);
return exitCode() || (typeof result === 'object' ? result.exit : 0);
}
}
4 changes: 2 additions & 2 deletions packages/cli-utils/src/commands/check/thread.ts
Original file line number Diff line number Diff line change
@@ -47,8 +47,8 @@ async function* _runDiagnostics(
...pluginInfo.config,
shouldCheckForColocatedFragments: isVueOrSvelte
? false
: pluginInfo.config.shouldCheckForColocatedFragments ?? false,
trackFieldUsage: isVueOrSvelte ? false : pluginInfo.config.trackFieldUsage ?? false,
: (pluginInfo.config.shouldCheckForColocatedFragments ?? false),
trackFieldUsage: isVueOrSvelte ? false : (pluginInfo.config.trackFieldUsage ?? false),
};
const diagnostics = getGraphQLDiagnostics(filePath, schemaRef, pluginInfo);
const messages: DiagnosticMessage[] = [];
3 changes: 2 additions & 1 deletion packages/cli-utils/src/commands/doctor/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Command } from 'clipanion';
import { exitCode } from '../../utils/error';
import { initTTY } from '../../term';
import { run } from './runner';

@@ -7,6 +8,6 @@ export class DoctorCommand extends Command {

async execute() {
const result = await initTTY().start(run());
return process.exitCode || (typeof result === 'object' ? result.exit : 0);
return exitCode() || (typeof result === 'object' ? result.exit : 0);
}
}
3 changes: 2 additions & 1 deletion packages/cli-utils/src/commands/generate-output/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Command, Option } from 'clipanion';

import type { OutputOptions } from './runner';
import { exitCode } from '../../utils/error';
import { initTTY } from '../../term';
import { run } from './runner';

@@ -36,7 +37,7 @@ export class GenerateOutputCommand extends Command {
tsconfig: this.tsconfig,
})
);
return process.exitCode || (typeof result === 'object' ? result.exit : 0);
return exitCode() || (typeof result === 'object' ? result.exit : 0);
}
}

3 changes: 2 additions & 1 deletion packages/cli-utils/src/commands/generate-persisted/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Command, Option } from 'clipanion';

import type { PersistedOptions } from './runner';
import { exitCode } from '../../utils/error';
import { initTTY } from '../../term';
import { run } from './runner';

@@ -35,7 +36,7 @@ export class GeneratePersisted extends Command {
tsconfig: this.tsconfig,
})
);
return process.exitCode || (typeof result === 'object' ? result.exit : 0);
return exitCode() || (typeof result === 'object' ? result.exit : 0);
}
}

3 changes: 2 additions & 1 deletion packages/cli-utils/src/commands/generate-schema/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as t from 'typanion';
import { Command, Option } from 'clipanion';

import { exitCode } from '../../utils/error';
import type { SchemaOptions } from './runner';
import { initTTY } from '../../term';
import { run } from './runner';
@@ -53,7 +54,7 @@ export class GenerateSchema extends Command {
tsconfig: this.tsconfig,
})
);
return process.exitCode || (typeof result === 'object' ? result.exit : 0);
return exitCode() || (typeof result === 'object' ? result.exit : 0);
}
}

3 changes: 2 additions & 1 deletion packages/cli-utils/src/commands/turbo/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Command, Option } from 'clipanion';

import type { TurboOptions } from './runner';
import { exitCode } from '../../utils/error';
import { initTTY } from '../../term';
import { run } from './runner';

@@ -30,7 +31,7 @@ export class TurboCommand extends Command {
tsconfig: this.tsconfig,
})
);
return process.exitCode || (typeof result === 'object' ? result.exit : 0);
return exitCode() || (typeof result === 'object' ? result.exit : 0);
}
}

5 changes: 5 additions & 0 deletions packages/cli-utils/src/utils/error.ts
Original file line number Diff line number Diff line change
@@ -16,3 +16,8 @@ export class TadaError extends Error {
this.name = 'TadaError';
}
}

export const exitCode = () => {
const { exitCode } = process;
return typeof exitCode === 'string' ? parseInt(exitCode, 10) || 0 : exitCode;
};
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ describe('getPeerSupportedFeatures', () => {
"directiveArgumentsIsDeprecated": true,
"directiveIsRepeatable": true,
"fieldArgumentsIsDeprecated": true,
"inputOneOf": false,
"inputOneOf": true,
"inputValueDeprecation": true,
"specifiedByURL": true,
}
4,097 changes: 1,625 additions & 2,472 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions scripts/eslint-preset.js
Original file line number Diff line number Diff line change
@@ -49,6 +49,8 @@ module.exports = {
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/array-type': 'off',
'@typescript-eslint/no-empty-object-type': 'off',
'@typescript-eslint/no-unsafe-function-type': 'off',
'tsdoc/syntax': 'error',

'no-restricted-syntax': [
11 changes: 6 additions & 5 deletions src/__tests__/tsHarness/virtualHost.ts
Original file line number Diff line number Diff line change
@@ -149,11 +149,12 @@ export function readSourceFolders(directories: string[]): Files {
return combinedFiles;
}

export type VirtualHost = ReturnType<typeof createVirtualHost> extends infer U
? U extends CompilerHost
? U
: never
: never;
export type VirtualHost =
ReturnType<typeof createVirtualHost> extends infer U
? U extends CompilerHost
? U
: never
: never;

export function createVirtualHost(files: Files) {
// TODO: When another lib with references is selected, the resolution mode doesn't adapt
38 changes: 18 additions & 20 deletions src/api.ts
Original file line number Diff line number Diff line change
@@ -347,13 +347,14 @@ export type getDocumentNode<
Introspection extends SchemaLike,
Fragments extends { [name: string]: any } = {},
isMaskingDisabled = false,
> = getDocumentType<Document, Introspection, Fragments> extends never
? never
: TadaDocumentNode<
getDocumentType<Document, Introspection, Fragments>,
getVariablesType<Document, Introspection>,
decorateFragmentDef<Document, isMaskingDisabled>
>;
> =
getDocumentType<Document, Introspection, Fragments> extends never
? never
: TadaDocumentNode<
getDocumentType<Document, Introspection, Fragments>,
getVariablesType<Document, Introspection>,
decorateFragmentDef<Document, isMaskingDisabled>
>;

/** A GraphQL `DocumentNode` with attached types for results and variables.
*
@@ -410,9 +411,8 @@ type ResultOf<Document> = Document extends DocumentDecoration<infer Result, any>
* This accepts a {@link TadaDocumentNode} and returns the attached `Variables` type
* of GraphQL documents.
*/
type VariablesOf<Document> = Document extends DocumentDecoration<any, infer Variables>
? Variables
: never;
type VariablesOf<Document> =
Document extends DocumentDecoration<any, infer Variables> ? Variables : never;

/** Creates a fragment mask for a given fragment document.
*
@@ -449,16 +449,14 @@ type FragmentOf<Document extends FragmentShape> = makeFragmentRef<Document>;

type resultOrFragmentOf<Document extends FragmentShape> = FragmentOf<Document> | ResultOf<Document>;

type resultOfT<Document extends FragmentShape, T = unknown> = Document extends DocumentDecoration<
infer Result,
any
>
? '__typename' extends keyof T
? Result extends { __typename?: T['__typename'] }
? Result
: never
: Result
: never;
type resultOfT<Document extends FragmentShape, T = unknown> =
Document extends DocumentDecoration<infer Result, any>
? '__typename' extends keyof T
? Result extends { __typename?: T['__typename'] }
? Result
: never
: Result
: never;

type resultOfFragmentsRec<
Fragments extends readonly any[],
19 changes: 10 additions & 9 deletions src/namespace.ts
Original file line number Diff line number Diff line change
@@ -79,15 +79,16 @@ type getFragmentsOfDocuments<Documents extends readonly FragmentShape[]> = overl
: never
>;

type makeFragmentRef<Document> = Document extends FragmentShape<infer Definition, infer Result>
? Definition['masked'] extends false
? Result
: {
[$tada.fragmentRefs]: {
[Name in Definition['fragment']]: Definition['on'];
};
}
: never;
type makeFragmentRef<Document> =
Document extends FragmentShape<infer Definition, infer Result>
? Definition['masked'] extends false
? Result
: {
[$tada.fragmentRefs]: {
[Name in Definition['fragment']]: Definition['on'];
};
}
: never;

type omitFragmentRefsRec<Data> = Data extends readonly (infer Value)[]
? readonly omitFragmentRefsRec<Value>[]
178 changes: 82 additions & 96 deletions src/parser.ts
Original file line number Diff line number Diff line change
@@ -110,13 +110,10 @@ export type takeDirective<In extends any[], Const extends boolean> = In extends
: void
: void;

export type takeDirectives<
In extends any[],
Const extends boolean,
Directives extends any[] = [],
> = takeDirective<In, Const> extends _match<infer Directive, infer In>
? takeDirectives<In, Const, [...Directives, Directive]>
: _match<Directives, In>;
export type takeDirectives<In extends any[], Const extends boolean, Directives extends any[] = []> =
takeDirective<In, Const> extends _match<infer Directive, infer In>
? takeDirectives<In, Const, [...Directives, Directive]>
: _match<Directives, In>;

type _takeFieldName<In extends any[]> = In extends [
{ kind: Token.Name; name: infer MaybeAlias },
@@ -127,39 +124,36 @@ type _takeFieldName<In extends any[]> = In extends [
: _match2<undefined, { kind: Kind.NAME; value: MaybeAlias }, In>
: void;

type _takeField<In extends any[]> = _takeFieldName<In> extends _match2<
infer Alias,
infer Name,
infer In
>
? takeArguments<In, false> extends _match<infer Arguments, infer In>
? takeDirectives<In, false> extends _match<infer Directives, infer In>
? takeSelectionSet<In> extends _match<infer SelectionSet, infer In>
? _match<
{
kind: Kind.FIELD;
alias: Alias;
name: Name;
arguments: Arguments;
directives: Directives;
selectionSet: SelectionSet;
},
In
>
: _match<
{
kind: Kind.FIELD;
alias: Alias;
name: Name;
arguments: Arguments;
directives: Directives;
selectionSet: undefined;
},
In
>
type _takeField<In extends any[]> =
_takeFieldName<In> extends _match2<infer Alias, infer Name, infer In>
? takeArguments<In, false> extends _match<infer Arguments, infer In>
? takeDirectives<In, false> extends _match<infer Directives, infer In>
? takeSelectionSet<In> extends _match<infer SelectionSet, infer In>
? _match<
{
kind: Kind.FIELD;
alias: Alias;
name: Name;
arguments: Arguments;
directives: Directives;
selectionSet: SelectionSet;
},
In
>
: _match<
{
kind: Kind.FIELD;
alias: Alias;
name: Name;
arguments: Arguments;
directives: Directives;
selectionSet: undefined;
},
In
>
: void
: void
: void
: void;
: void;

export type takeType<In extends any[]> = In extends [Token.BracketOpen, ...infer In]
? takeType<In> extends _match<infer Subtype, infer In>
@@ -227,16 +221,14 @@ type _takeFragmentSpread<In extends any[]> = In extends [
: void
: void;

type _takeSelectionRec<Selections extends any[], In extends any[]> = _takeField<In> extends _match<
infer Selection,
infer In
>
? _takeSelectionRec<[...Selections, Selection], In>
: _takeFragmentSpread<In> extends _match<infer Selection, infer In>
type _takeSelectionRec<Selections extends any[], In extends any[]> =
_takeField<In> extends _match<infer Selection, infer In>
? _takeSelectionRec<[...Selections, Selection], In>
: In extends [Token.BraceClose, ...infer In]
? _match<{ kind: Kind.SELECTION_SET; selections: Selections }, In>
: void;
: _takeFragmentSpread<In> extends _match<infer Selection, infer In>
? _takeSelectionRec<[...Selections, Selection], In>
: In extends [Token.BraceClose, ...infer In]
? _match<{ kind: Kind.SELECTION_SET; selections: Selections }, In>
: void;

export type takeSelectionSet<In extends any[]> = In extends [Token.BraceOpen, ...infer In]
? _takeSelectionRec<[], In>
@@ -321,60 +313,54 @@ type takeOperation<In extends any[]> = In extends [{ kind: Token.Name; name: 'qu
? _match<OperationTypeNode.SUBSCRIPTION, In>
: void;

export type takeOperationDefinition<In extends any[]> = takeOperation<In> extends _match<
infer Operation,
infer In
>
? takeOptionalName<In> extends _match<infer Name, infer In>
? takeVarDefinitions<In> extends _match<infer VarDefinitions, infer In>
? takeDirectives<In, false> extends _match<infer Directives, infer In>
? takeSelectionSet<In> extends _match<infer SelectionSet, infer In>
? _match<
{
kind: Kind.OPERATION_DEFINITION;
operation: Operation;
name: Name;
variableDefinitions: VarDefinitions;
directives: Directives;
selectionSet: SelectionSet;
},
In
>
export type takeOperationDefinition<In extends any[]> =
takeOperation<In> extends _match<infer Operation, infer In>
? takeOptionalName<In> extends _match<infer Name, infer In>
? takeVarDefinitions<In> extends _match<infer VarDefinitions, infer In>
? takeDirectives<In, false> extends _match<infer Directives, infer In>
? takeSelectionSet<In> extends _match<infer SelectionSet, infer In>
? _match<
{
kind: Kind.OPERATION_DEFINITION;
operation: Operation;
name: Name;
variableDefinitions: VarDefinitions;
directives: Directives;
selectionSet: SelectionSet;
},
In
>
: void
: void
: void
: void
: void
: takeSelectionSet<In> extends _match<infer SelectionSet, infer In>
? _match<
{
kind: Kind.OPERATION_DEFINITION;
operation: OperationTypeNode.QUERY;
name: undefined;
variableDefinitions: [];
directives: [];
selectionSet: SelectionSet;
},
In
>
: void;
: takeSelectionSet<In> extends _match<infer SelectionSet, infer In>
? _match<
{
kind: Kind.OPERATION_DEFINITION;
operation: OperationTypeNode.QUERY;
name: undefined;
variableDefinitions: [];
directives: [];
selectionSet: SelectionSet;
},
In
>
: void;

type _takeDocumentRec<
Definitions extends any[],
In extends any[],
> = takeFragmentDefinition<In> extends _match<infer Definition, infer In>
? _takeDocumentRec<[...Definitions, Definition], In>
: takeOperationDefinition<In> extends _match<infer Definition, infer In>
type _takeDocumentRec<Definitions extends any[], In extends any[]> =
takeFragmentDefinition<In> extends _match<infer Definition, infer In>
? _takeDocumentRec<[...Definitions, Definition], In>
: _match<Definitions, In>;
: takeOperationDefinition<In> extends _match<infer Definition, infer In>
? _takeDocumentRec<[...Definitions, Definition], In>
: _match<Definitions, In>;

export type parseDocument<In extends string> = _takeDocumentRec<[], tokenize<In>> extends _match<
[...infer Definitions],
any
>
? Definitions extends []
? never
: { kind: Kind.DOCUMENT; definitions: Definitions }
: never;
export type parseDocument<In extends string> =
_takeDocumentRec<[], tokenize<In>> extends _match<[...infer Definitions], any>
? Definitions extends []
? never
: { kind: Kind.DOCUMENT; definitions: Definitions }
: never;

export type DocumentNodeLike = {
kind: Kind.DOCUMENT;

0 comments on commit cbf5f27

Please sign in to comment.