Socket
Socket
Sign inDemoInstall

gql.tada

Package Overview
Dependencies
Maintainers
1
Versions
229
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gql.tada - npm Package Compare versions

Comparing version 0.0.0 to 1.0.0-beta.0

1904

dist/gql-tada.d.ts

@@ -1,238 +0,1682 @@

import { Kind, OperationTypeNode } from '@0no-co/graphql.web';
import {
Kind,
OperationTypeNode,
DocumentNode,
FieldNode,
NameNode,
FragmentSpreadNode,
InlineFragmentNode,
TypeNode,
} from '@0no-co/graphql.web';
/** Constraints a given string to a string literal. */
type stringLiteral<T extends string> = string extends T ? never : string;
/** Returns `T` if it matches `Constraint` without being equal to it. Failing this evaluates to `Fallback` otherwise. */
type matchOr<Constraint, T, Fallback> = Constraint extends T
? Fallback
: T extends Constraint
? T
: Fallback;
/** Flattens a given object type.
*
* @remarks
* This is typically used to make a TypeScript type appear as a flat object,
* both in terms of type checking and for type hints and the tsserver output.
*/
type obj<T> = T extends {
[key: string | number]: any;
}
? T extends infer U
? {
[K in keyof U]: U[K];
}
: never
: never;
/** Retrieves all non-nullish value types of an object dictionary. */
type objValues<T> = T[keyof T] extends infer U
? U extends null | undefined | never | void
? never
: U
: never;
/** Annotations for GraphQL’s `DocumentNode` with attached generics for its result data and variables types.
*
* @remarks
* A GraphQL {@link DocumentNode} defines both the variables it accepts on request and the `data`
* shape it delivers on a response in the GraphQL query language.
*
* To bridge the gap to TypeScript, tools may be used to generate TypeScript types that define the shape
* of `data` and `variables` ahead of time. These types are then attached to GraphQL documents using this
* `TypedDocumentNode` type.
*
* Using a `DocumentNode` that is typed like this will cause any `urql` API to type its input `variables`
* and resulting `data` using the types provided.
*
* @privateRemarks
* For compatibility reasons this type has been copied and internalized from:
* https://github.com/dotansimha/graphql-typed-document-node/blob/3711b12/packages/core/src/index.ts#L3-L10
*
* @see {@link https://github.com/dotansimha/graphql-typed-document-node} for more information.
*/
interface DocumentDecoration<
Result = {
[key: string]: any;
},
Variables = {
[key: string]: any;
},
> {
/** Type to support `@graphql-typed-document-node/core`
* @internal
*/
__apiType?: (variables: Variables) => Result;
/** Type to support `TypedQueryDocumentNode` from `graphql`
* @internal
*/
__ensureTypesOfVariablesAndResultMatching?: (variables: Variables) => Result;
}
/** Format of introspection data queryied from your schema.
*
* @remarks
* You must provide your introspected schema in the standard introspection
* format (as represented by this type) to `setupSchema` to configure this
* library to use your types.
*
* @see {@link setupSchema} for where to use this data.
*/
interface IntrospectionQuery {
readonly __schema: IntrospectionSchema;
}
interface IntrospectionSchema {
readonly queryType: IntrospectionNamedTypeRef;
readonly mutationType?: IntrospectionNamedTypeRef | null;
readonly subscriptionType?: IntrospectionNamedTypeRef | null;
readonly types: readonly IntrospectionType[];
}
type IntrospectionType =
| IntrospectionScalarType
| IntrospectionObjectType
| IntrospectionInterfaceType
| IntrospectionUnionType
| IntrospectionEnumType
| IntrospectionInputObjectType;
interface IntrospectionScalarType {
readonly kind: 'SCALAR';
readonly name: string;
readonly specifiedByURL?: string | null;
}
interface IntrospectionObjectType {
readonly kind: 'OBJECT';
readonly name: string;
readonly fields: readonly IntrospectionField[];
readonly interfaces: readonly IntrospectionNamedTypeRef[] | never;
}
interface IntrospectionInterfaceType {
readonly kind: 'INTERFACE';
readonly name: string;
readonly fields: readonly IntrospectionField[];
readonly possibleTypes: readonly IntrospectionNamedTypeRef[];
readonly interfaces?: readonly IntrospectionNamedTypeRef[] | null;
}
interface IntrospectionUnionType {
readonly kind: 'UNION';
readonly name: string;
readonly possibleTypes: readonly IntrospectionNamedTypeRef[];
}
interface IntrospectionEnumValue {
readonly name: string;
}
interface IntrospectionEnumType {
readonly kind: 'ENUM';
readonly name: string;
readonly enumValues: readonly IntrospectionEnumValue[];
}
interface IntrospectionInputObjectType {
readonly kind: 'INPUT_OBJECT';
readonly name: string;
readonly inputFields: readonly IntrospectionInputValue[];
}
interface IntrospectionListTypeRef {
readonly kind: 'LIST';
readonly ofType: IntrospectionTypeRef;
}
interface IntrospectionNonNullTypeRef {
readonly kind: 'NON_NULL';
readonly ofType: IntrospectionTypeRef;
}
type IntrospectionTypeRef =
| IntrospectionNamedTypeRef
| IntrospectionListTypeRef
| IntrospectionNonNullTypeRef;
interface IntrospectionNamedTypeRef {
readonly name: string;
}
interface IntrospectionField {
readonly name: string;
readonly args: readonly IntrospectionInputValue[];
readonly type: IntrospectionTypeRef;
}
interface IntrospectionInputValue {
readonly name: string;
readonly type: IntrospectionTypeRef;
readonly defaultValue?: string | null;
}
interface DefaultScalars {
ID: number | string;
Boolean: boolean;
String: string;
Float: number;
Int: number;
}
type mapNames<T extends readonly any[]> = obj<{
[P in T[number]['name']]: T[number] extends infer Value
? Value extends {
readonly name: P;
}
? obj<Value>
: never
: never;
}>;
type mapScalar<
Type extends IntrospectionScalarType,
Scalars extends ScalarsLike = DefaultScalars,
> = {
kind: 'SCALAR';
type: Type['name'] extends keyof Scalars
? Scalars[Type['name']]
: Type['name'] extends keyof DefaultScalars
? DefaultScalars[Type['name']]
: unknown;
};
type mapEnum<T extends IntrospectionEnumType> = {
kind: 'ENUM';
name: T['name'];
type: T['enumValues'][number]['name'];
};
type mapObject<T extends IntrospectionObjectType> = {
kind: 'OBJECT';
name: T['name'];
interfaces: T['interfaces'][number]['name'];
fields: obj<mapNames<T['fields']>>;
};
type mapInputObject<T extends IntrospectionInputObjectType> = {
kind: 'INPUT_OBJECT';
name: T['name'];
inputFields: [...T['inputFields']];
};
type mapInterface<T extends IntrospectionInterfaceType> = {
kind: 'INTERFACE';
name: T['name'];
interfaces: T['interfaces'] extends readonly any[] ? T['interfaces'][number]['name'] : never;
possibleTypes: T['possibleTypes'][number]['name'];
fields: obj<mapNames<T['fields']>>;
};
type mapUnion<T extends IntrospectionUnionType> = {
kind: 'UNION';
name: T['name'];
fields: {};
possibleTypes: T['possibleTypes'][number]['name'];
};
type mapType<
Type,
Scalars extends ScalarsLike = DefaultScalars,
> = Type extends IntrospectionScalarType
? mapScalar<Type, Scalars>
: Type extends IntrospectionEnumType
? mapEnum<Type>
: Type extends IntrospectionObjectType
? mapObject<Type>
: Type extends IntrospectionInterfaceType
? mapInterface<Type>
: Type extends IntrospectionUnionType
? mapUnion<Type>
: Type extends IntrospectionInputObjectType
? mapInputObject<Type>
: never;
type mapIntrospectionTypes<
Query extends IntrospectionQuery,
Scalars extends ScalarsLike = DefaultScalars,
> = obj<{
[P in Query['__schema']['types'][number]['name']]: Query['__schema']['types'][number] extends infer Type
? Type extends {
readonly name: P;
}
? mapType<Type, Scalars>
: never
: never;
}>;
type mapIntrospection<
Query extends IntrospectionQuery,
Scalars extends ScalarsLike = DefaultScalars,
> = {
query: Query['__schema']['queryType']['name'];
mutation: Query['__schema']['mutationType'] extends {
name: string;
}
? Query['__schema']['mutationType']['name']
: never;
subscription: Query['__schema']['subscriptionType'] extends {
name: string;
}
? Query['__schema']['subscriptionType']['name']
: never;
types: mapIntrospectionTypes<Query, Scalars>;
};
type ScalarsLike = {
[name: string]: any;
};
type IntrospectionLikeType = {
query: string;
mutation: string | never;
subscription: string | never;
types: {
[name: string]: any;
};
};
type digit = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';
type letter = 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' | 'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z' | 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z';
type skipIgnored<In> = In extends `#${infer _}\n${infer In}` ? skipIgnored<In> : In extends `${' ' | '\n' | '\t' | '\r' | ',' | '\ufeff'}${infer In}` ? skipIgnored<In> : In extends string ? In : never;
type letter =
| 'A'
| 'B'
| 'C'
| 'D'
| 'E'
| 'F'
| 'G'
| 'H'
| 'I'
| 'J'
| 'K'
| 'L'
| 'M'
| 'N'
| 'O'
| 'P'
| 'Q'
| 'R'
| 'S'
| 'T'
| 'U'
| 'V'
| 'W'
| 'X'
| 'Y'
| 'Z'
| 'a'
| 'b'
| 'c'
| 'd'
| 'e'
| 'f'
| 'g'
| 'h'
| 'i'
| 'j'
| 'k'
| 'l'
| 'm'
| 'n'
| 'o'
| 'p'
| 'q'
| 'r'
| 's'
| 't'
| 'u'
| 'v'
| 'w'
| 'x'
| 'y'
| 'z';
type skipIgnored<In> = In extends `#${infer _}\n${infer In}`
? skipIgnored<In>
: In extends `${' ' | '\n' | '\t' | '\r' | ',' | '\ufeff'}${infer In}`
? skipIgnored<In>
: In extends string
? In
: never;
type skipDigits<In extends string> = In extends `${digit}${infer In}` ? skipDigits<In> : In;
type skipInt<In extends string> = In extends `${'-'}${digit}${infer In}` ? skipDigits<In> : In extends `${digit}${infer In}` ? skipDigits<In> : void;
type skipExponent<In extends string> = In extends `${'e' | 'E'}${'+' | '-'}${infer In}` ? skipDigits<In> : In extends `${'e' | 'E'}${infer In}` ? skipDigits<In> : In;
type skipFloat<In extends string> = In extends `${'.'}${infer In}` ? In extends `${digit}${infer In}` ? skipExponent<skipDigits<In>> : void : In extends `${'e' | 'E'}${infer _}` ? skipExponent<In> : void;
type skipBlockString<In extends string> = In extends `${infer Hd}${'"""'}${infer In}` ? Hd extends `${infer _}${'\\'}` ? skipBlockString<skipIgnored<In>> : In : void;
type skipString<In extends string> = In extends `${infer Hd}${'"'}${infer In}` ? Hd extends `${infer _}${'\\'}` ? skipString<In> : In : void;
type _TakeNameContinue<PrevMatch extends string, In extends string> = In extends `${infer Match}${infer Out}` ? Match extends letter | digit | '_' ? _TakeNameContinue<`${PrevMatch}${Match}`, Out> : [PrevMatch, In] : [PrevMatch, In];
type _TakeName<In extends string> = In extends `${infer Match}${infer In}` ? Match extends letter | '_' ? _TakeNameContinue<Match, In> : void : void;
type TakeName<In extends string> = _TakeName<In> extends [infer Out, infer In] ? [{
kind: Kind.NAME;
value: Out;
}, In] : void;
type TakeOptionalName<In extends string> = _TakeName<In> extends [infer Out, infer In] ? [{
kind: Kind.NAME;
value: Out;
}, In] : [undefined, In];
type TakeEnum<In extends string> = _TakeName<In> extends [infer Out, infer In] ? [{
kind: Kind.ENUM;
value: Out;
}, In] : void;
type TakeVariable<In extends string, Const extends boolean> = Const extends false ? In extends `${'$'}${infer In}` ? _TakeName<In> extends [infer Out, infer In] ? [{
kind: Kind.VARIABLE;
name: {
type skipInt<In extends string> = In extends `${'-'}${digit}${infer In}`
? skipDigits<In>
: In extends `${digit}${infer In}`
? skipDigits<In>
: void;
type skipExponent<In extends string> = In extends `${'e' | 'E'}${'+' | '-'}${infer In}`
? skipDigits<In>
: In extends `${'e' | 'E'}${infer In}`
? skipDigits<In>
: In;
type skipFloat<In extends string> = In extends `${'.'}${infer In}`
? In extends `${digit}${infer In}`
? skipExponent<skipDigits<In>>
: void
: In extends `${'e' | 'E'}${infer _}`
? skipExponent<In>
: void;
type skipBlockString<In extends string> = In extends `${infer Hd}${'"""'}${infer In}`
? Hd extends `${infer _}${'\\'}`
? skipBlockString<skipIgnored<In>>
: In
: void;
type skipString<In extends string> = In extends `${infer Hd}${'"'}${infer In}`
? Hd extends `${infer _}${'\\'}`
? skipString<In>
: In
: void;
type _takeNameLiteralRec<
PrevMatch extends string,
In extends string,
> = In extends `${infer Match}${infer Out}`
? Match extends letter | digit | '_'
? _takeNameLiteralRec<`${PrevMatch}${Match}`, Out>
: [PrevMatch, In]
: [PrevMatch, In];
type takeNameLiteral<In extends string> = In extends `${infer Match}${infer In}`
? Match extends letter | '_'
? _takeNameLiteralRec<Match, In>
: void
: void;
type takeName<In extends string> = takeNameLiteral<In> extends [infer Out, infer In]
? [
{
kind: Kind.NAME;
value: Out;
};
}, In] : void : void : void;
type TakeNumber<In extends string> = skipInt<In> extends `${infer In}` ? skipFloat<In> extends `${infer In}` ? [{
kind: Kind.FLOAT;
value: string;
}, In] : [{
kind: Kind.INT;
value: string;
}, In] : void;
type TakeString<In extends string> = In extends `${'"""'}${infer In}` ? skipBlockString<In> extends `${infer In}` ? [{
kind: Kind.STRING;
value: string;
block: true;
}, In] : void : In extends `${'"'}${infer In}` ? skipString<In> extends `${infer In}` ? [{
kind: Kind.STRING;
value: string;
block: false;
}, In] : void : void;
type TakeLiteral<In extends string> = In extends `${'null'}${infer In}` ? [{
kind: Kind.NULL;
}, In] : In extends `${'true' | 'false'}${infer In}` ? [{
kind: Kind.BOOLEAN;
value: boolean;
}, In] : void;
type TakeValue<In extends string, Const extends boolean> = TakeLiteral<In> extends [
infer Node,
infer Rest
] ? [Node, Rest] : TakeVariable<In, Const> extends [infer Node, infer Rest] ? [Node, Rest] : TakeNumber<In> extends [infer Node, infer Rest] ? [Node, Rest] : TakeEnum<In> extends [infer Node, infer Rest] ? [Node, Rest] : TakeString<In> extends [infer Node, infer Rest] ? [Node, Rest] : TakeList<In, Const> extends [infer Node, infer Rest] ? [Node, Rest] : TakeObject<In, Const> extends [infer Node, infer Rest] ? [Node, Rest] : void;
type _TakeListContinue<Nodes extends unknown[], In extends string, Const extends boolean> = In extends `${']'}${infer In}` ? [{
kind: Kind.LIST;
values: Nodes;
}, In] : TakeValue<skipIgnored<In>, Const> extends [infer Node, infer In] ? _TakeListContinue<[...Nodes, Node], skipIgnored<In>, Const> : void;
type TakeList<In extends string, Const extends boolean> = In extends `${'['}${infer In}` ? _TakeListContinue<[], skipIgnored<In>, Const> : void;
type TakeObjectField<In extends string, Const extends boolean> = TakeName<In> extends [
infer Name,
infer In
] ? skipIgnored<In> extends `${':'}${infer In}` ? TakeValue<skipIgnored<In>, Const> extends [infer Value, infer In] ? [{
kind: Kind.OBJECT_FIELD;
name: Name;
value: Value;
}, In] : void : void : void;
type _TakeObjectContinue<Fields extends unknown[], In extends string, Const extends boolean> = In extends `${'}'}${infer In}` ? [{
kind: Kind.OBJECT;
fields: Fields;
}, In] : TakeObjectField<skipIgnored<In>, Const> extends [infer Field, infer In] ? _TakeObjectContinue<[...Fields, Field], skipIgnored<In>, Const> : void;
type TakeObject<In extends string, Const extends boolean> = In extends `${'{'}${infer In}` ? _TakeObjectContinue<[], skipIgnored<In>, Const> : void;
type TakeArgument<In extends string, Const extends boolean> = TakeName<In> extends [
infer Name,
infer In
] ? skipIgnored<In> extends `${':'}${infer In}` ? TakeValue<skipIgnored<In>, Const> extends [infer Value, infer In] ? [{
kind: Kind.ARGUMENT;
name: Name;
value: Value;
}, In] : void : void : void;
type _TakeArgumentsContinue<Arguments extends unknown[], In extends string, Const extends boolean> = In extends `${')'}${infer In}` ? Arguments extends [] ? void : [Arguments, In] : TakeArgument<In, Const> extends [infer Argument, infer In] ? _TakeArgumentsContinue<[...Arguments, Argument], skipIgnored<In>, Const> : void;
type TakeArguments<In extends string, Const extends boolean> = In extends `${'('}${infer In}` ? _TakeArgumentsContinue<[], skipIgnored<In>, Const> : [[], In];
type TakeDirective<In extends string, Const extends boolean> = In extends `${'@'}${infer In}` ? TakeName<In> extends [infer Name, infer In] ? TakeArguments<skipIgnored<In>, Const> extends [infer Arguments, infer In] ? [{
kind: Kind.DIRECTIVE;
name: Name;
arguments: Arguments;
}, In] : void : void : void;
type TakeDirectives<In extends string, Const extends boolean> = TakeDirective<In, Const> extends [infer Directive, infer In] ? TakeDirectives<skipIgnored<In>, Const> extends [[...infer Directives], infer In] ? [[Directive, ...Directives], In] : [[], In] : [[], In];
type _TakeFieldName<In extends string> = TakeName<In> extends [infer MaybeAlias, infer In] ? skipIgnored<In> extends `${':'}${infer In}` ? TakeName<skipIgnored<In>> extends [infer Name, infer In] ? [MaybeAlias, Name, In] : void : [undefined, MaybeAlias, In] : void;
type TakeField<In extends string> = _TakeFieldName<In> extends [
infer Alias,
infer Name,
infer In
] ? TakeArguments<skipIgnored<In>, false> extends [infer Arguments, infer In] ? TakeDirectives<skipIgnored<In>, false> extends [infer Directives, infer In] ? TakeSelectionSet<skipIgnored<In>> extends [infer SelectionSet, infer In] ? [
{
kind: Kind.FIELD;
alias: Alias;
name: Name;
arguments: Arguments;
directives: Directives;
selectionSet: SelectionSet;
},
In
] : void : void : void : void;
type TakeType<In extends string> = In extends `${'['}${infer In}` ? TakeType<skipIgnored<In>> extends [infer Subtype, infer In] ? In extends `${']'}${infer In}` ? skipIgnored<In> extends `${'!'}${infer In}` ? [{
kind: Kind.NON_NULL_TYPE;
type: {
kind: 'ListType';
type: Subtype;
};
}, In] : [{
kind: Kind.LIST_TYPE;
type: Subtype;
}, In] : void : void : TakeName<skipIgnored<In>> extends [infer Name, infer In] ? skipIgnored<In> extends `${'!'}${infer In}` ? [{
kind: Kind.NON_NULL_TYPE;
type: {
kind: 'NamedType';
name: Name;
};
}, In] : [{
kind: Kind.NAMED_TYPE;
name: Name;
}, In] : void;
type TakeTypeCondition<In extends string> = In extends `${'on'}${infer In}` ? TakeName<skipIgnored<In>> extends [infer Name, infer In] ? [{
kind: Kind.NAMED_TYPE;
name: Name;
}, In] : void : void;
type TakeFragmentSpread<In extends string> = In extends `${'...'}${infer In}` ? skipIgnored<In> extends `${'on'}${infer In}` ? TakeName<skipIgnored<In>> extends [infer Name, infer In] ? TakeDirectives<skipIgnored<In>, false> extends [infer Directives, infer In] ? TakeSelectionSetContinue<skipIgnored<In>> extends [infer SelectionSet, infer In] ? [
{
kind: Kind.INLINE_FRAGMENT;
typeCondition: {
},
In,
]
: void;
type takeOptionalName<In extends string> = takeNameLiteral<In> extends [infer Out, infer In]
? [
{
kind: Kind.NAME;
value: Out;
},
In,
]
: [undefined, In];
type takeEnum<In extends string> = takeNameLiteral<In> extends [infer Out, infer In]
? [
{
kind: Kind.ENUM;
value: Out;
},
In,
]
: void;
type TakeVariable<In extends string, Const extends boolean> = Const extends false
? In extends `${'$'}${infer In}`
? takeNameLiteral<In> extends [infer Out, infer In]
? [
{
kind: Kind.VARIABLE;
name: {
kind: Kind.NAME;
value: Out;
};
},
In,
]
: void
: void
: void;
type takeNumber<In extends string> = skipInt<In> extends `${infer In}`
? skipFloat<In> extends `${infer In}`
? [
{
kind: Kind.FLOAT;
value: string;
},
In,
]
: [
{
kind: Kind.INT;
value: string;
},
In,
]
: void;
type takeString<In extends string> = In extends `${'"""'}${infer In}`
? skipBlockString<In> extends `${infer In}`
? [
{
kind: Kind.STRING;
value: string;
block: true;
},
In,
]
: void
: In extends `${'"'}${infer In}`
? skipString<In> extends `${infer In}`
? [
{
kind: Kind.STRING;
value: string;
block: false;
},
In,
]
: void
: void;
type takeLiteral<In extends string> = In extends `${'null'}${infer In}`
? [
{
kind: Kind.NULL;
},
In,
]
: In extends `${'true' | 'false'}${infer In}`
? [
{
kind: Kind.BOOLEAN;
value: boolean;
},
In,
]
: void;
type takeValue<In extends string, Const extends boolean> = takeLiteral<In> extends [
infer Node,
infer Rest,
]
? [Node, Rest]
: TakeVariable<In, Const> extends [infer Node, infer Rest]
? [Node, Rest]
: takeNumber<In> extends [infer Node, infer Rest]
? [Node, Rest]
: takeEnum<In> extends [infer Node, infer Rest]
? [Node, Rest]
: takeString<In> extends [infer Node, infer Rest]
? [Node, Rest]
: takeList<In, Const> extends [infer Node, infer Rest]
? [Node, Rest]
: takeObject<In, Const> extends [infer Node, infer Rest]
? [Node, Rest]
: void;
type _takeListRec<
Nodes extends unknown[],
In extends string,
Const extends boolean,
> = In extends `${']'}${infer In}`
? [
{
kind: Kind.LIST;
values: Nodes;
},
In,
]
: takeValue<skipIgnored<In>, Const> extends [infer Node, infer In]
? _takeListRec<[...Nodes, Node], skipIgnored<In>, Const>
: void;
type takeList<In extends string, Const extends boolean> = In extends `${'['}${infer In}`
? _takeListRec<[], skipIgnored<In>, Const>
: void;
type takeObjectField<In extends string, Const extends boolean> = takeName<In> extends [
infer Name,
infer In,
]
? skipIgnored<In> extends `${':'}${infer In}`
? takeValue<skipIgnored<In>, Const> extends [infer Value, infer In]
? [
{
kind: Kind.OBJECT_FIELD;
name: Name;
value: Value;
},
In,
]
: void
: void
: void;
type _takeObjectRec<
Fields extends unknown[],
In extends string,
Const extends boolean,
> = In extends `${'}'}${infer In}`
? [
{
kind: Kind.OBJECT;
fields: Fields;
},
In,
]
: takeObjectField<skipIgnored<In>, Const> extends [infer Field, infer In]
? _takeObjectRec<[...Fields, Field], skipIgnored<In>, Const>
: void;
type takeObject<In extends string, Const extends boolean> = In extends `${'{'}${infer In}`
? _takeObjectRec<[], skipIgnored<In>, Const>
: void;
type takeArgument<In extends string, Const extends boolean> = takeName<In> extends [
infer Name,
infer In,
]
? skipIgnored<In> extends `${':'}${infer In}`
? takeValue<skipIgnored<In>, Const> extends [infer Value, infer In]
? [
{
kind: Kind.ARGUMENT;
name: Name;
value: Value;
},
In,
]
: void
: void
: void;
type _takeArgumentsRec<
Arguments extends unknown[],
In extends string,
Const extends boolean,
> = In extends `${')'}${infer In}`
? Arguments extends []
? void
: [Arguments, In]
: takeArgument<In, Const> extends [infer Argument, infer In]
? _takeArgumentsRec<[...Arguments, Argument], skipIgnored<In>, Const>
: void;
type takeArguments<In extends string, Const extends boolean> = In extends `${'('}${infer In}`
? _takeArgumentsRec<[], skipIgnored<In>, Const>
: [[], In];
type takeDirective<In extends string, Const extends boolean> = In extends `${'@'}${infer In}`
? takeName<In> extends [infer Name, infer In]
? takeArguments<skipIgnored<In>, Const> extends [infer Arguments, infer In]
? [
{
kind: Kind.DIRECTIVE;
name: Name;
arguments: Arguments;
},
In,
]
: void
: void
: void;
type takeDirectives<In extends string, Const extends boolean> = takeDirective<In, Const> extends [
infer Directive,
infer In,
]
? takeDirectives<skipIgnored<In>, Const> extends [[...infer Directives], infer In]
? [[Directive, ...Directives], In]
: [[], In]
: [[], In];
type takeFieldName<In extends string> = takeName<In> extends [infer MaybeAlias, infer In]
? skipIgnored<In> extends `${':'}${infer In}`
? takeName<skipIgnored<In>> extends [infer Name, infer In]
? [MaybeAlias, Name, In]
: void
: [undefined, MaybeAlias, In]
: void;
type takeField<In extends string> = takeFieldName<In> extends [infer Alias, infer Name, infer In]
? takeArguments<skipIgnored<In>, false> extends [infer Arguments, infer In]
? takeDirectives<skipIgnored<In>, false> extends [infer Directives, infer In]
? takeSelectionSet<skipIgnored<In>> extends [infer SelectionSet, infer In]
? [
{
kind: Kind.FIELD;
alias: Alias;
name: Name;
arguments: Arguments;
directives: Directives;
selectionSet: SelectionSet;
},
In,
]
: [
{
kind: Kind.FIELD;
alias: Alias;
name: Name;
arguments: Arguments;
directives: Directives;
selectionSet: undefined;
},
In,
]
: void
: void
: void;
type takeType<In extends string> = In extends `${'['}${infer In}`
? takeType<skipIgnored<In>> extends [infer Subtype, infer In]
? In extends `${']'}${infer In}`
? skipIgnored<In> extends `${'!'}${infer In}`
? [
{
kind: Kind.NON_NULL_TYPE;
type: {
kind: Kind.LIST_TYPE;
type: Subtype;
};
},
In,
]
: [
{
kind: Kind.LIST_TYPE;
type: Subtype;
},
In,
]
: void
: void
: takeName<skipIgnored<In>> extends [infer Name, infer In]
? skipIgnored<In> extends `${'!'}${infer In}`
? [
{
kind: Kind.NON_NULL_TYPE;
type: {
kind: Kind.NAMED_TYPE;
name: Name;
};
},
In,
]
: [
{
kind: Kind.NAMED_TYPE;
name: Name;
};
directives: Directives;
selectionSet: SelectionSet;
},
In
] : void : void : void : TakeName<skipIgnored<In>> extends [infer Name, infer In] ? TakeDirectives<skipIgnored<In>, false> extends [infer Directives, infer In] ? [{
kind: Kind.FRAGMENT_SPREAD;
name: Name;
directives: Directives;
}, In] : void : TakeDirectives<skipIgnored<In>, false> extends [infer Directives, infer In] ? TakeSelectionSetContinue<skipIgnored<In>> extends [infer SelectionSet, infer In] ? [
{
kind: Kind.INLINE_FRAGMENT;
typeCondition: undefined;
directives: Directives;
selectionSet: SelectionSet;
},
In
] : void : void : void;
type _TakeSelection<Selections extends unknown[], In extends string> = In extends `${'}'}${infer In}` ? [{
kind: Kind.SELECTION_SET;
selections: Selections;
}, In] : TakeFragmentSpread<skipIgnored<In>> extends [infer Selection, infer In] ? _TakeSelection<[...Selections, Selection], skipIgnored<In>> : TakeField<skipIgnored<In>> extends [infer Selection, infer In] ? _TakeSelection<[...Selections, Selection], skipIgnored<In>> : void;
type TakeSelectionSetContinue<In extends string> = In extends `${'{'}${infer In}` ? _TakeSelection<[], skipIgnored<In>> : void;
type TakeSelectionSet<In extends string> = TakeSelectionSetContinue<In> extends [
infer SelectionSet,
infer In
] ? [SelectionSet, In] : [undefined, In];
type TakeVarDefinition<In extends string> = TakeVariable<In, false> extends [
infer Variable,
infer In
] ? skipIgnored<In> extends `${':'}${infer In}` ? TakeType<skipIgnored<In>> extends [infer Type, infer In] ? skipIgnored<In> extends `${'='}${infer In}` ? TakeValue<skipIgnored<In>, true> extends [infer DefaultValue, infer In] ? TakeDirectives<skipIgnored<In>, true> extends [infer Directives, infer In] ? [
{
kind: Kind.VARIABLE_DEFINITION;
variable: Variable;
type: Type;
defaultValue: DefaultValue;
directives: Directives;
},
In
] : void : void : TakeDirectives<skipIgnored<In>, true> extends [infer Directives, infer In] ? [
{
kind: Kind.VARIABLE_DEFINITION;
variable: Variable;
type: Type;
defaultValue: undefined;
directives: Directives;
},
In
] : void : void : void : void;
type _TakeVarDefinitionContinue<Definitions extends unknown[], In extends string> = In extends `${')'}${infer In}` ? [Definitions, In] : TakeVarDefinition<In> extends [infer Definition, infer In] ? _TakeVarDefinitionContinue<[...Definitions, Definition], skipIgnored<In>> : void;
type TakeVarDefinitions<In extends string> = skipIgnored<In> extends `${'('}${infer In}` ? _TakeVarDefinitionContinue<[], skipIgnored<In>> : [[], In];
type TakeFragmentDefinition<In extends string> = In extends `${'fragment'}${infer In}` ? TakeName<skipIgnored<In>> extends [infer Name, infer In] ? TakeTypeCondition<skipIgnored<In>> extends [infer TypeCondition, infer In] ? TakeDirectives<skipIgnored<In>, true> extends [infer Directives, infer In] ? TakeSelectionSetContinue<skipIgnored<In>> extends [infer SelectionSet, infer In] ? [
{
kind: Kind.FRAGMENT_DEFINITION;
name: Name;
typeCondition: TypeCondition;
directives: Directives;
selectionSet: SelectionSet;
},
In
] : void : void : void : void : void;
type TakeOperation<In extends string> = In extends `${'query'}${infer In}` ? [OperationTypeNode.QUERY, In] : In extends `${'mutation'}${infer In}` ? [OperationTypeNode.MUTATION, In] : In extends `${'subscription'}${infer In}` ? [OperationTypeNode.SUBSCRIPTION, In] : void;
type TakeOperationDefinition<In extends string> = TakeOperation<In> extends [
infer Operation,
infer In
] ? TakeOptionalName<skipIgnored<In>> extends [infer Name, infer In] ? TakeVarDefinitions<skipIgnored<In>> extends [infer VarDefinitions, infer In] ? TakeDirectives<skipIgnored<In>, false> extends [infer Directives, infer In] ? TakeSelectionSetContinue<skipIgnored<In>> extends [infer SelectionSet, infer In] ? [
{
kind: Kind.OPERATION_DEFINITION;
operation: Operation;
name: Name;
variableDefinitions: VarDefinitions;
directives: Directives;
selectionSet: SelectionSet;
},
In
] : void : void : void : void : TakeSelectionSetContinue<skipIgnored<In>> extends [infer SelectionSet, infer In] ? [
{
kind: Kind.OPERATION_DEFINITION;
operation: OperationTypeNode.QUERY;
name: undefined;
variableDefinitions: [];
directives: [];
selectionSet: SelectionSet;
},
In
] : void;
type _TakeDocumentContinue<Definitions extends unknown[], In extends string> = TakeFragmentDefinition<In> extends [infer Definition, infer In] ? _TakeDocumentContinue<[...Definitions, Definition], skipIgnored<In>> : TakeOperationDefinition<In> extends [infer Definition, infer In] ? _TakeDocumentContinue<[...Definitions, Definition], skipIgnored<In>> : [Definitions, In];
type ParseDocument<In extends string> = _TakeDocumentContinue<[], skipIgnored<In>> extends [
[
...infer Definitions
],
infer _
] ? {
kind: Kind.DOCUMENT;
definitions: Definitions;
} : void;
type ParseValue<In> = TakeValue<skipIgnored<In>, false> extends [infer Node, string] ? Node : void;
type ParseType<In> = TakeType<skipIgnored<In>> extends [infer Node, string] ? Node : void;
type ParseOperation<In> = TakeOperation<skipIgnored<In>> extends [infer Node, string] ? Node : void;
},
In,
]
: void;
type takeTypeCondition<In extends string> = In extends `${'on'}${infer In}`
? takeName<skipIgnored<In>> extends [infer Name, infer In]
? [
{
kind: Kind.NAMED_TYPE;
name: Name;
},
In,
]
: void
: void;
type takeFragmentSpread<In extends string> = In extends `${'...'}${infer In}`
? skipIgnored<In> extends `${'on'}${infer In}`
? takeName<skipIgnored<In>> extends [infer Name, infer In]
? takeDirectives<skipIgnored<In>, false> extends [infer Directives, infer In]
? takeSelectionSet<skipIgnored<In>> extends [infer SelectionSet, infer In]
? [
{
kind: Kind.INLINE_FRAGMENT;
typeCondition: {
kind: Kind.NAMED_TYPE;
name: Name;
};
directives: Directives;
selectionSet: SelectionSet;
},
In,
]
: void
: void
: void
: takeName<skipIgnored<In>> extends [infer Name, infer In]
? takeDirectives<skipIgnored<In>, false> extends [infer Directives, infer In]
? [
{
kind: Kind.FRAGMENT_SPREAD;
name: Name;
directives: Directives;
},
In,
]
: void
: takeDirectives<skipIgnored<In>, false> extends [infer Directives, infer In]
? takeSelectionSet<skipIgnored<In>> extends [infer SelectionSet, infer In]
? [
{
kind: Kind.INLINE_FRAGMENT;
typeCondition: undefined;
directives: Directives;
selectionSet: SelectionSet;
},
In,
]
: void
: void
: void;
type _takeSelectionRec<
Selections extends unknown[],
In extends string,
> = In extends `${'}'}${infer In}`
? [
{
kind: Kind.SELECTION_SET;
selections: Selections;
},
In,
]
: takeFragmentSpread<skipIgnored<In>> extends [infer Selection, infer In]
? _takeSelectionRec<[...Selections, Selection], skipIgnored<In>>
: takeField<skipIgnored<In>> extends [infer Selection, infer In]
? _takeSelectionRec<[...Selections, Selection], skipIgnored<In>>
: void;
type takeSelectionSet<In extends string> = In extends `${'{'}${infer In}`
? _takeSelectionRec<[], skipIgnored<In>>
: void;
type takeVarDefinition<In extends string> = TakeVariable<In, false> extends [
infer Variable,
infer In,
]
? skipIgnored<In> extends `${':'}${infer In}`
? takeType<skipIgnored<In>> extends [infer Type, infer In]
? skipIgnored<In> extends `${'='}${infer In}`
? takeValue<skipIgnored<In>, true> extends [infer DefaultValue, infer In]
? takeDirectives<skipIgnored<In>, true> extends [infer Directives, infer In]
? [
{
kind: Kind.VARIABLE_DEFINITION;
variable: Variable;
type: Type;
defaultValue: DefaultValue;
directives: Directives;
},
In,
]
: void
: void
: takeDirectives<skipIgnored<In>, true> extends [infer Directives, infer In]
? [
{
kind: Kind.VARIABLE_DEFINITION;
variable: Variable;
type: Type;
defaultValue: undefined;
directives: Directives;
},
In,
]
: void
: void
: void
: void;
type _takeVarDefinitionRec<
Definitions extends unknown[],
In extends string,
> = In extends `${')'}${infer In}`
? [Definitions, In]
: takeVarDefinition<In> extends [infer Definition, infer In]
? _takeVarDefinitionRec<[...Definitions, Definition], skipIgnored<In>>
: void;
type takeVarDefinitions<In extends string> = skipIgnored<In> extends `${'('}${infer In}`
? _takeVarDefinitionRec<[], skipIgnored<In>>
: [[], In];
type takeFragmentDefinition<In extends string> = In extends `${'fragment'}${infer In}`
? takeName<skipIgnored<In>> extends [infer Name, infer In]
? takeTypeCondition<skipIgnored<In>> extends [infer TypeCondition, infer In]
? takeDirectives<skipIgnored<In>, true> extends [infer Directives, infer In]
? takeSelectionSet<skipIgnored<In>> extends [infer SelectionSet, infer In]
? [
{
kind: Kind.FRAGMENT_DEFINITION;
name: Name;
typeCondition: TypeCondition;
directives: Directives;
selectionSet: SelectionSet;
},
In,
]
: void
: void
: void
: void
: void;
type TakeOperation<In extends string> = In extends `${'query'}${infer In}`
? [OperationTypeNode.QUERY, In]
: In extends `${'mutation'}${infer In}`
? [OperationTypeNode.MUTATION, In]
: In extends `${'subscription'}${infer In}`
? [OperationTypeNode.SUBSCRIPTION, In]
: void;
type takeOperationDefinition<In extends string> = TakeOperation<In> extends [
infer Operation,
infer In,
]
? takeOptionalName<skipIgnored<In>> extends [infer Name, infer In]
? takeVarDefinitions<skipIgnored<In>> extends [infer VarDefinitions, infer In]
? takeDirectives<skipIgnored<In>, false> extends [infer Directives, infer In]
? takeSelectionSet<skipIgnored<In>> extends [infer SelectionSet, infer In]
? [
{
kind: Kind.OPERATION_DEFINITION;
operation: Operation;
name: Name;
variableDefinitions: VarDefinitions;
directives: Directives;
selectionSet: SelectionSet;
},
In,
]
: void
: void
: void
: void
: takeSelectionSet<skipIgnored<In>> extends [infer SelectionSet, infer In]
? [
{
kind: Kind.OPERATION_DEFINITION;
operation: OperationTypeNode.QUERY;
name: undefined;
variableDefinitions: [];
directives: [];
selectionSet: SelectionSet;
},
In,
]
: void;
type _takeDocumentRec<
Definitions extends unknown[],
In extends string,
> = takeFragmentDefinition<In> extends [infer Definition, infer In]
? _takeDocumentRec<[...Definitions, Definition], skipIgnored<In>>
: takeOperationDefinition<In> extends [infer Definition, infer In]
? _takeDocumentRec<[...Definitions, Definition], skipIgnored<In>>
: [Definitions, In];
type parseDocument<In extends string> = _takeDocumentRec<[], skipIgnored<In>> extends [
[...infer Definitions],
infer _Rest,
]
? Definitions extends []
? never
: {
kind: Kind.DOCUMENT;
definitions: Definitions;
}
: never;
type DocumentNodeLike = {
kind: Kind.DOCUMENT;
definitions: any[];
};
export { ParseDocument as Document, ParseOperation as Operation, ParseType as Type, ParseValue as Value };
/** Private namespace holding our symbols for markers.
*
* @remarks
* Markers are used to indicate, for example, which fragments a given GraphQL document
* is referring to or which fragments a document exposes. This ties into “fragment masking”,
* a process by which the type of a fragment is hidden away until it’s unwrapped, to enforce
* isolation and code-reuse.
*/
declare namespace $tada {
const fragmentRefs: unique symbol;
type fragmentRefs = typeof fragmentRefs;
const fragmentDef: unique symbol;
type fragmentDef = typeof fragmentDef;
const fragmentId: unique symbol;
type fragmentId = typeof fragmentId;
}
interface FragmentDefDecorationLike {
readonly [$tada.fragmentId]: symbol;
kind: Kind.FRAGMENT_DEFINITION;
name: any;
typeCondition: any;
}
interface DocumentDefDecorationLike extends DocumentNode {
[$tada.fragmentDef]?: FragmentDefDecorationLike;
}
type decorateFragmentDef<Document extends DocumentNodeLike> = Document['definitions'][0] extends {
kind: Kind.FRAGMENT_DEFINITION;
name: any;
typeCondition: any;
}
? {
kind: Kind.FRAGMENT_DEFINITION;
name: Document['definitions'][0]['name'];
typeCondition: Document['definitions'][0]['typeCondition'];
readonly [$tada.fragmentId]: unique symbol;
}
: never;
type getFragmentsOfDocumentsRec<Documents> = Documents extends readonly [
infer Document,
...infer Rest,
]
? (Document extends {
[$tada.fragmentDef]?: any;
}
? Exclude<Document[$tada.fragmentDef], undefined> extends infer FragmentDef extends {
kind: Kind.FRAGMENT_DEFINITION;
name: any;
typeCondition: any;
}
? {
[Name in FragmentDef['name']['value']]: FragmentDef;
}
: {}
: {}) &
getFragmentsOfDocumentsRec<Rest>
: {};
type makeFragmentRef<Definition extends FragmentDefDecorationLike> = {
[$tada.fragmentRefs]?: {
[Name in Definition['name']['value']]: Definition[$tada.fragmentId];
};
};
type makeUndefinedFragmentRef<FragmentName extends string> = {
[$tada.fragmentRefs]?: {
[Name in FragmentName]: 'Undefined Fragment';
};
};
type makeFragmentDefDecoration<Definition> = {
[$tada.fragmentDef]?: Definition extends DocumentDefDecorationLike[$tada.fragmentDef]
? Definition
: never;
};
type ObjectLikeType = {
kind: 'OBJECT' | 'INTERFACE' | 'UNION';
name: string;
fields: {
[key: string]: IntrospectionField;
};
};
type _unwrapTypeRec$1<
Type extends IntrospectionTypeRef,
SelectionSet extends
| {
kind: Kind.SELECTION_SET;
}
| undefined,
Introspection extends IntrospectionLikeType,
Fragments extends {
[name: string]: any;
},
> = Type extends IntrospectionNonNullTypeRef
? _unwrapTypeRec$1<Type['ofType'], SelectionSet, Introspection, Fragments>
: Type extends IntrospectionListTypeRef
? Array<unwrapType$1<Type['ofType'], SelectionSet, Introspection, Fragments>>
: Type extends IntrospectionNamedTypeRef
? Introspection['types'][Type['name']] extends ObjectLikeType
? SelectionSet extends {
kind: Kind.SELECTION_SET;
selections: any;
}
? getSelection<
SelectionSet['selections'],
Introspection['types'][Type['name']],
Introspection,
Fragments
>
: unknown
: Introspection['types'][Type['name']]['type']
: unknown;
type unwrapType$1<
Type extends IntrospectionTypeRef,
SelectionSet extends
| {
kind: Kind.SELECTION_SET;
}
| undefined,
Introspection extends IntrospectionLikeType,
Fragments extends {
[name: string]: any;
},
> = Type extends IntrospectionNonNullTypeRef
? _unwrapTypeRec$1<Type['ofType'], SelectionSet, Introspection, Fragments>
: null | _unwrapTypeRec$1<Type, SelectionSet, Introspection, Fragments>;
type isOptionalRec<Directives extends readonly unknown[] | undefined> =
Directives extends readonly [infer Directive, ...infer Rest]
? Directive extends {
kind: Kind.DIRECTIVE;
name: any;
}
? Directive['name']['value'] extends 'include' | 'skip' | 'defer'
? false
: isOptionalRec<Rest>
: isOptionalRec<Rest>
: true;
type getFieldAlias<Node extends FieldNode> = Node['alias'] extends undefined
? Node['name']['value']
: Node['alias'] extends NameNode
? Node['alias']['value']
: never;
type getFragmentSelection<
Node extends {
kind: Kind.FRAGMENT_SPREAD | Kind.INLINE_FRAGMENT;
},
Type extends ObjectLikeType,
Introspection extends IntrospectionLikeType,
Fragments extends {
[name: string]: any;
},
> = Node extends {
kind: Kind.INLINE_FRAGMENT;
selectionSet: any;
}
? getSelection<Node['selectionSet']['selections'], Type, Introspection, Fragments>
: Node extends {
kind: Kind.FRAGMENT_SPREAD;
name: any;
}
? Node['name']['value'] extends keyof Fragments
? Fragments[Node['name']['value']] extends FragmentDefDecorationLike
? makeFragmentRef<Fragments[Node['name']['value']]>
: getSelection<
Fragments[Node['name']['value']]['selectionSet']['selections'],
Type,
Introspection,
Fragments
>
: {}
: {};
type getSpreadSubtype<
Node extends {
kind: Kind.FRAGMENT_SPREAD | Kind.INLINE_FRAGMENT;
},
BaseType extends ObjectLikeType,
Introspection extends IntrospectionLikeType,
Fragments extends {
[name: string]: any;
},
> = Node extends {
kind: Kind.INLINE_FRAGMENT;
typeCondition?: any;
}
? Node['typeCondition'] extends {
kind: Kind.NAMED_TYPE;
name: any;
}
? Introspection['types'][Node['typeCondition']['name']['value']]
: BaseType
: Node extends {
kind: Kind.FRAGMENT_SPREAD;
name: any;
}
? Node['name']['value'] extends keyof Fragments
? Introspection['types'][Fragments[Node['name']['value']]['typeCondition']['name']['value']]
: void
: void;
type getTypenameOfType<Type extends ObjectLikeType> = Type extends {
possibleTypes: any;
}
? Type['possibleTypes']
: Type['name'];
type getSelection<
Selections extends readonly any[],
Type extends ObjectLikeType,
Introspection extends IntrospectionLikeType,
Fragments extends {
[name: string]: any;
},
> = obj<
getFieldsSelectionRec<Selections, Type, Introspection, Fragments> &
getFragmentsSelection<Selections, Type, Introspection, Fragments>
>;
type getFieldsSelectionRec<
Selections extends readonly unknown[],
Type extends ObjectLikeType,
Introspection extends IntrospectionLikeType,
Fragments extends {
[name: string]: any;
},
> = Selections extends readonly [infer Selection, ...infer Rest]
? (Selection extends FieldNode
? isOptionalRec<Selection['directives']> extends true
? {
[Prop in getFieldAlias<Selection>]: Selection['name']['value'] extends '__typename'
? getTypenameOfType<Type>
: unwrapType$1<
Type['fields'][Selection['name']['value']]['type'],
Selection['selectionSet'],
Introspection,
Fragments
>;
}
: {
[Prop in getFieldAlias<Selection>]?: Selection['name']['value'] extends '__typename'
? getTypenameOfType<Type>
: unwrapType$1<
Type['fields'][Selection['name']['value']]['type'],
Selection['selectionSet'],
Introspection,
Fragments
>;
}
: {}) &
getFieldsSelectionRec<Rest, Type, Introspection, Fragments>
: {};
type _getFragmentsSelectionRec<
Selections extends readonly unknown[],
PossibleType extends string,
Type extends ObjectLikeType,
Introspection extends IntrospectionLikeType,
Fragments extends {
[name: string]: any;
},
> = Selections extends [infer Node, ...infer Rest]
? (Node extends FragmentSpreadNode | InlineFragmentNode
? getSpreadSubtype<Node, Type, Introspection, Fragments> extends infer Subtype extends
ObjectLikeType
? PossibleType extends Subtype['name'] | getTypenameOfType<Subtype>
?
| (isOptionalRec<Node['directives']> extends true ? never : {})
| getFragmentSelection<Node, Subtype, Introspection, Fragments>
: {}
: Node extends FragmentSpreadNode
? makeUndefinedFragmentRef<Node['name']['value']>
: {}
: {}) &
_getFragmentsSelectionRec<Rest, PossibleType, Type, Introspection, Fragments>
: {};
type getFragmentsSelection<
Selections extends readonly unknown[],
Type extends ObjectLikeType,
Introspection extends IntrospectionLikeType,
Fragments extends {
[name: string]: any;
},
> = Type extends {
kind: 'UNION' | 'INTERFACE';
possibleTypes: any;
}
? objValues<{
[PossibleType in Type['possibleTypes']]: _getFragmentsSelectionRec<
Selections,
PossibleType,
Type,
Introspection,
Fragments
>;
}>
: Type extends {
kind: 'OBJECT';
name: any;
}
? _getFragmentsSelectionRec<Selections, Type['name'], Type, Introspection, Fragments>
: {};
type getOperationSelectionType<
Definition,
Introspection extends IntrospectionLikeType,
Fragments extends {
[name: string]: any;
},
> = Definition extends {
kind: Kind.OPERATION_DEFINITION;
selectionSet: any;
operation: any;
}
? Introspection['types'][Introspection[Definition['operation']]] extends infer Type extends
ObjectLikeType
? getSelection<Definition['selectionSet']['selections'], Type, Introspection, Fragments>
: {}
: never;
type getFragmentSelectionType<
Definition,
Introspection extends IntrospectionLikeType,
Fragments extends {
[name: string]: any;
},
> = Definition extends {
kind: Kind.FRAGMENT_DEFINITION;
selectionSet: any;
typeCondition: any;
}
? Introspection['types'][Definition['typeCondition']['name']['value']] extends infer Type extends
ObjectLikeType
? getSelection<Definition['selectionSet']['selections'], Type, Introspection, Fragments>
: never
: never;
type getDocumentType<
Document extends DocumentNodeLike,
Introspection extends IntrospectionLikeType,
Fragments extends {
[name: string]: any;
} = {},
> = Document['definitions'] extends readonly [infer Definition, ...infer Rest]
? Definition extends {
kind: Kind.OPERATION_DEFINITION;
}
? getOperationSelectionType<Definition, Introspection, getFragmentMapRec<Rest> & Fragments>
: Definition extends {
kind: Kind.FRAGMENT_DEFINITION;
}
? getFragmentSelectionType<Definition, Introspection, getFragmentMapRec<Rest> & Fragments>
: never
: never;
type getFragmentMapRec<Definitions> = Definitions extends readonly [infer Definition, ...infer Rest]
? (Definition extends {
kind: Kind.FRAGMENT_DEFINITION;
name: any;
}
? {
[Name in Definition['name']['value']]: Definition;
}
: {}) &
getFragmentMapRec<Rest>
: {};
type getInputObjectTypeRec<
InputFields extends readonly unknown[],
Introspection extends IntrospectionLikeType,
> = InputFields extends [infer InputField, ...infer Rest]
? (InputField extends {
name: any;
type: any;
}
? {
[Name in InputField['name']]: unwrapType<InputField['type'], Introspection>;
}
: {}) &
getInputObjectTypeRec<Rest, Introspection>
: {};
type getScalarType<
TypeName extends string,
Introspection extends IntrospectionLikeType,
> = TypeName extends keyof Introspection['types']
? Introspection['types'][TypeName] extends {
kind: 'SCALAR' | 'ENUM';
type: infer IntrospectionValueType;
}
? IntrospectionValueType
: Introspection['types'][TypeName] extends {
kind: 'INPUT_OBJECT';
inputFields: [...infer InputFields];
}
? obj<getInputObjectTypeRec<InputFields, Introspection>>
: never
: unknown;
type _unwrapTypeRec<
TypeRef extends TypeNode,
Introspection extends IntrospectionLikeType,
> = TypeRef extends {
kind: 'NON_NULL';
}
? _unwrapTypeRec<TypeRef['ofType'], Introspection>
: TypeRef extends {
kind: 'LIST';
}
? Array<unwrapType<TypeRef['ofType'], Introspection>>
: TypeRef extends {
name: any;
}
? getScalarType<TypeRef['name'], Introspection>
: unknown;
type unwrapType<Type extends TypeNode, Introspection extends IntrospectionLikeType> = Type extends {
kind: 'NON_NULL';
}
? _unwrapTypeRec<Type['ofType'], Introspection>
: null | _unwrapTypeRec<Type, Introspection>;
type _nwrapTypeRefRec<
Type extends TypeNode,
Introspection extends IntrospectionLikeType,
> = Type extends {
kind: Kind.NON_NULL_TYPE;
}
? _nwrapTypeRefRec<Type['type'], Introspection>
: Type extends {
kind: Kind.LIST_TYPE;
}
? Array<unwrapTypeRef<Type['type'], Introspection>>
: Type extends {
kind: Kind.NAMED_TYPE;
name: any;
}
? getScalarType<Type['name']['value'], Introspection>
: unknown;
type unwrapTypeRef<
Type extends TypeNode,
Introspection extends IntrospectionLikeType,
> = Type extends {
kind: Kind.NON_NULL_TYPE;
}
? _nwrapTypeRefRec<Type['type'], Introspection>
: null | _nwrapTypeRefRec<Type, Introspection>;
type getVariablesRec<
Variables extends readonly unknown[],
Introspection extends IntrospectionLikeType,
> = Variables extends [infer Variable, ...infer Rest]
? (Variable extends {
kind: Kind.VARIABLE_DEFINITION;
variable: any;
type: any;
}
? Variable extends {
defaultValue: undefined;
}
? {
[Name in Variable['variable']['name']['value']]: unwrapTypeRef<
Variable['type'],
Introspection
>;
}
: {
[Name in Variable['variable']['name']['value']]?: unwrapTypeRef<
Variable['type'],
Introspection
>;
}
: {}) &
getVariablesRec<Rest, Introspection>
: {};
type getVariablesType<
Document extends DocumentNodeLike,
Introspection extends IntrospectionLikeType,
> = Document['definitions'][0] extends {
kind: Kind.OPERATION_DEFINITION;
variableDefinitions: any;
}
? obj<getVariablesRec<Document['definitions'][0]['variableDefinitions'], Introspection>>
: {};
/** Abstract configuration type input for your schema and scalars.
*
* @remarks
* This is used either via {@link setupSchema} or {@link initGraphQLTada} to set
* up your schema and scalars.
*
* The `scalars` option is optional and can be used to set up more scalars, apart
* from the default ones (like: Int, Float, String, Boolean).
* It must be an object map of scalar names to their desired TypeScript types.
*
* @param introspection - Introspection of your schema matching {@link IntrospectionQuery}.
* @param scalars - An object type with scalar names as keys and the corresponding scalar types as values.
*/
interface AbstractSetupSchema {
introspection: IntrospectionQuery;
scalars?: ScalarsLike;
}
/** This is used to configure gql.tada with your introspection data and scalars.
*
* @remarks
* You may extend this interface via declaration merging with your {@link IntrospectionQuery}
* data and optionally your scalars to get proper type inference.
* This is done by declaring a declaration for it as per the following example.
*
* Configuring scalars is optional and by default the standard scalrs are already
* defined.
*
* This will configure the {@link graphql} export to infer types from your schema.
* Alternatively, you may call {@link initGraphQLTada} instead.
*
* @param introspection - Introspection of your schema matching {@link IntrospectionQuery}.
* @param scalars - An object type with scalar names as keys and the corresponding scalar types as values.
*
* @example
*
* ```
* import { myIntrospection } from './myIntrospection';
*
* declare module 'gql.tada' {
* interface setupSchema {
* introspection: typeof myIntrospection;
* scalars: {
* DateTime: string;
* Json: any;
* };
* }
* }
* ```
*/
interface setupSchema extends AbstractSetupSchema {}
interface GraphQLTadaAPI<Schema extends IntrospectionLikeType> {
/** Function to create and compose GraphQL documents with result and variable types.
*
* @param input - A string of a GraphQL document.
* @param fragments - An optional list of other GraphQL fragments created with this function.
* @returns A {@link DocumentNode} with result and variables types.
*
* @remarks
* This function creates a {@link DocumentNode} with result and variables types.
* It is used with your schema in {@link setupSchema} to create a result type
* of your queries, fragments, and variables.
*
* You can compose fragments into this function by passing them and a fragment
* mask will be created for them.
* When creating queries, the returned document of queries can be passed into GraphQL clients
* which will then automatically infer the result and variables types.
*
* @example
*
* ```
* import { graphql } from 'gql.tada';
*
* const bookFragment = graphql(`
* fragment BookComponent on Book {
* id
* title
* }
* `);
*
* const bookQuery = graphql(`
* query Book ($id: ID!) {
* book(id: $id) {
* id
* ...BookComponent
* }
* }
* `, [bookFragment]);
* ```
*
* @see {@link readFragment} for how to read from fragment masks.
*/
<
const In extends stringLiteral<In>,
const Fragments extends readonly [...DocumentDefDecorationLike[]],
>(
input: In,
fragments?: Fragments
): getDocumentNode<parseDocument<In>, Schema, getFragmentsOfDocumentsRec<Fragments>>;
}
/** Setup function to create a typed `graphql` document function with.
*
* @remarks
* `initGraphQLTada` accepts an {@link AbstractSetupSchema} configuration object as a generic
* and returns a `graphql` function that may be used to create documents typed using your
* GraphQL schema.
*
* You should use and re-export the resulting function named as `graphql` or `gql` for your
* editor and the TypeScript language server to recognize your GraphQL documents correctly.
*
* @example
*
* ```
* import { initGraphQLTada } from 'gql.tada';
* import { myIntrospection } from './myIntrospection';
*
* export const graphql = initGraphQLTada<{
* introspection: typeof myIntrospection;
* scalars: {
* DateTime: string;
* Json: any;
* };
* }>();
*
* const query = graphql(`{ __typename }`);
* ```
*/
declare function initGraphQLTada<const Setup extends AbstractSetupSchema>(): GraphQLTadaAPI<
mapIntrospection<
matchOr<IntrospectionQuery, Setup['introspection'], never>,
matchOr<ScalarsLike, Setup['scalars'], {}>
>
>;
/** Alias to a GraphQL parse function returning an exact document type.
*
* @param input - A string of a GraphQL document
* @returns A parsed {@link DocumentNode}.
*
* @remarks
* This function accepts a GraphQL document string and parses it, just like
* GraphQL’s `parse` function. However, its return type will be the exact
* structure of the AST parsed in types.
*/
declare function parse<const In extends stringLiteral<In>>(input: In): parseDocument<In>;
type getDocumentNode<
Document extends DocumentNodeLike,
Introspection extends IntrospectionLikeType,
Fragments extends {
[name: string]: any;
} = {},
> = getDocumentType<Document, Introspection, Fragments> extends infer Result
? Result extends never
? never
: TadaDocumentNode<
Result,
getVariablesType<Document, Introspection>,
decorateFragmentDef<Document>
>
: never;
/** A GraphQL `DocumentNode` with attached types for results and variables.
*
* @remarks
* This is a GraphQL {@link DocumentNode} with attached types for results and variables.
* This is used by GraphQL clients to infer the types of results and variables and provide
* type-safety in GraphQL documents.
*
* You can create typed GraphQL documents using the {@link graphql} function.
*
* `Result` is the type of GraphQL results, as returned by GraphQL APIs for a given query.
* `Variables` is the type of variables, as accepted by GraphQL APIs for a given query.
*
* @see {@link https://github.com/dotansimha/graphql-typed-document-node} for more information.
*/
interface TadaDocumentNode<
Result = {
[key: string]: any;
},
Variables = {
[key: string]: any;
},
Decoration = never,
> extends DocumentNode,
DocumentDecoration<Result, Variables>,
makeFragmentDefDecoration<Decoration> {}
/** A utility type returning the `Result` type of typed GraphQL documents.
*
* @remarks
* This accepts a {@link TadaDocumentNode} and returns the attached `Result` type
* of GraphQL documents.
*/
type ResultOf<Document> = Document extends DocumentDecoration<infer Result, infer _>
? Result
: never;
/** A utility type returning the `Variables` type of typed GraphQL documents.
*
* @remarks
* This accepts a {@link TadaDocumentNode} and returns the attached `Variables` type
* of GraphQL documents.
*/
type VariablesOf<Document> = Document extends DocumentDecoration<infer _, infer Variables>
? Variables
: never;
/** Creates a fragment mask for a given fragment document.
*
* @remarks
* When {@link graphql} is used to create a fragment and is spread into another
* fragment or query, their result types will only contain a “reference” to the
* fragment. This encourages isolation and is known as “fragment masking.”
*
* While {@link readFragment} is used to unmask these fragment masks, this utility
* creates a fragment mask, so you can accept the masked data in the part of your
* codebase that defines a fragment.
*
* @example
*
* ```
* import { FragmentOf, graphql, readFragment } from 'gql.tada';
*
* const bookFragment = graphql(`
* fragment BookComponent on Book {
* id
* title
* }
* `);
*
* // May be called with any GraphQL data that contains a spread of `bookFragment`
* const getBook = (data: FragmentOf<typeof bookFragment>) => {
* // Unmasks the fragment and casts to the result type of `bookFragment`
* const book = readFragment(bookFragment, data);
* };
* ```
*
* @see {@link readFragment} for how to read from fragment masks.
*/
type FragmentOf<Document extends DocumentDefDecorationLike> = Exclude<
Document[$tada.fragmentDef],
undefined
> extends infer FragmentDef extends FragmentDefDecorationLike
? makeFragmentRef<FragmentDef>
: never;
type mirrorFragmentTypeRec<Fragment, Data> = Fragment extends (infer Value)[]
? mirrorFragmentTypeRec<Value, Data>[]
: Fragment extends readonly (infer Value)[]
? readonly mirrorFragmentTypeRec<Value, Data>[]
: Fragment extends null
? null
: Fragment extends undefined
? undefined
: Data;
type fragmentOfTypeRec<Document extends DocumentDefDecorationLike> =
| readonly fragmentOfTypeRec<Document>[]
| FragmentOf<Document>
| undefined
| null;
/** Unmasks a fragment mask for a given fragment document and data.
*
* @param _document - A GraphQL document of a fragment, created using {@link graphql}.
* @param fragment - A mask of the fragment, which can be wrapped in arrays, or nullable.
* @returns The unmasked data of the fragment.
*
* @remarks
* When {@link graphql} is used to create a fragment and is spread into another
* fragment or query, their result types will only contain a “reference” to the
* fragment. This encourages isolation and is known as “fragment masking.”
*
* This means that you must use {@link readFragment} to unmask these fragment masks
* and get to the data. This encourages isolation and only using the data you define
* a part of your codebase to require.
*
* @example
*
* ```
* import { FragmentOf, graphql, readFragment } from 'gql.tada';
*
* const bookFragment = graphql(`
* fragment BookComponent on Book {
* id
* title
* }
* `);
*
* const getBook = (data: FragmentOf<typeof bookFragment> | null) => {
* // Unmasks the fragment and casts to the result type of `bookFragment`
* // This is intersected with `| null` in this case, due to the input type.
* const book = readFragment(bookFragment, data);
* };
*
* const bookQuery = graphql(`
* query Book ($id: ID!) {
* book(id: $id) {
* id
* ...BookComponent
* }
* }
* `, [bookFragment]);
*
* const getQuery = (data: ResultOf<typeof bookQuery>) => {
* getBook(data?.book);
* };
* ```
*
* @see {@link readFragment} for how to read from fragment masks.
*/
declare function readFragment<
const Document extends DocumentDefDecorationLike,
const Fragment extends fragmentOfTypeRec<Document>,
const Data,
>(
_document: DocumentDecoration<Data, any> & Document,
fragment: Fragment
): fragmentOfTypeRec<Document> extends Fragment ? unknown : mirrorFragmentTypeRec<Fragment, Data>;
declare const graphql: GraphQLTadaAPI<mapIntrospection<never, {}>>;
export {
type AbstractSetupSchema,
type FragmentOf,
type GraphQLTadaAPI,
type ResultOf,
type TadaDocumentNode,
type VariablesOf,
graphql,
initGraphQLTada,
parse,
type parseDocument,
readFragment,
type setupSchema,
};

@@ -0,2 +1,39 @@

Object.defineProperty(exports, "__esModule", {
value: !0
});
var r = require("@0no-co/graphql.web");
function initGraphQLTada() {
return function graphql(a, e) {
var n = r.parse(a).definitions;
var i = new Set;
for (var t of e || []) {
for (var o of t.definitions) {
if (o.kind === r.Kind.FRAGMENT_DEFINITION && !i.has(o)) {
n.push(o);
i.add(o);
}
}
}
return {
kind: r.Kind.DOCUMENT,
definitions: [ ...n ]
};
};
}
var a = initGraphQLTada();
exports.graphql = a;
exports.initGraphQLTada = initGraphQLTada;
exports.parse = function parse(a) {
return r.parse(a);
};
exports.readFragment = function readFragment(r, a) {
return a;
};
//# sourceMappingURL=gql-tada.js.map

62

package.json
{
"name": "gql.tada",
"description": "The spec-compliant & magical GraphQL query language engine in the TypeScript type system",
"version": "0.0.0",
"version": "1.0.0-beta.0",
"author": "0no.co <hi@0no.co>",

@@ -31,2 +31,5 @@ "source": "./src/index.ts",

"graphql",
"graphql typescript",
"graphql types",
"graphql typegen",
"graphql-js",

@@ -43,3 +46,4 @@ "client-side graphql"

"tabWidth": 2,
"printWidth": 100
"printWidth": 100,
"trailingComma": "es5"
},

@@ -58,28 +62,31 @@ "lint-staged": {

"devDependencies": {
"@changesets/cli": "^2.26.2",
"@changesets/get-github-info": "^0.5.2",
"@rollup/plugin-buble": "^1.0.2",
"@rollup/plugin-commonjs": "^24.0.1",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-sucrase": "^5.0.1",
"@rollup/plugin-terser": "^0.4.0",
"@typescript-eslint/eslint-plugin": "^5.55.0",
"@typescript-eslint/parser": "^5.55.0",
"@vitest/coverage-c8": "^0.29.7",
"dotenv": "^16.0.3",
"eslint": "^8.36.0",
"eslint-config-prettier": "^8.7.0",
"eslint-plugin-prettier": "^4.2.1",
"@0no-co/typescript.js": "5.3.2-2",
"@babel/plugin-transform-block-scoping": "^7.23.4",
"@babel/plugin-transform-typescript": "^7.23.6",
"@changesets/cli": "^2.27.1",
"@changesets/get-github-info": "^0.6.0",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-commonjs": "^25.0.7",
"@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",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-tsdoc": "^0.2.17",
"graphql": "^16.6.0",
"lint-staged": "^13.2.0",
"expect-type": "^0.17.3",
"graphql": "^16.8.1",
"lint-staged": "^15.2.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.8.4",
"rimraf": "^4.4.0",
"rollup": "^3.19.1",
"rollup-plugin-cjs-check": "^1.0.2",
"rollup-plugin-dts": "^5.3.0",
"terser": "^5.16.6",
"typescript": "^5.0.2",
"vitest": "^0.29.7"
"prettier": "^3.1.1",
"rimraf": "^5.0.5",
"rollup": "^4.9.4",
"rollup-plugin-cjs-check": "^1.0.3",
"rollup-plugin-dts": "^6.1.0",
"terser": "^5.26.0",
"typescript": "^5.3.3",
"vitest": "1.1.3"
},

@@ -90,3 +97,4 @@ "publishConfig": {

"scripts": {
"test": "vitest typecheck",
"test": "vitest test",
"bench": "vitest bench --typecheck.enabled=false",
"check": "tsc",

@@ -93,0 +101,0 @@ "lint": "eslint --ext=js,ts .",

<div align="center">
<h2>gql.tada 🎉</h2>
<strong>The spec-compliant & magical GraphQL query language engine in the TypeScript type system</strong>
<h2>gql.tada 🪄</h2>
<strong>Magical GraphQL query engine for TypeScript</strong>
<br />
<br />
<a href="https://github.com/0no-co/gql.tada/actions/workflows/release.yml">
<img alt="CI Status" src="https://github.com/0no-co/gql.tada/actions/workflows/release.yml/badge.svg?branch=main" />
</a>
<a href="https://urql.dev/discord">
<img alt="Discord" src="https://img.shields.io/discord/1082378892523864074?color=7389D8&label&logo=discord&logoColor=ffffff" />
</a>
<a href="https://github.com/0no-co/gql.tada/actions/workflows/release.yml"><img alt="CI Status" src="https://github.com/0no-co/gql.tada/actions/workflows/release.yml/badge.svg?branch=main" /></a>
<a href="https://urql.dev/discord"><img alt="Discord" src="https://img.shields.io/discord/1082378892523864074?color=7389D8&label&logo=discord&logoColor=ffffff" /></a>
<br />

@@ -16,7 +12,105 @@ <br />

**Work in Progress**
`gql.tada` is a GraphQL document authoring library, inferring the result and variables types
of GraphQL queries and fragments in the TypeScript type system. It derives the types for your
GraphQL queries on the fly allowing you to write type-safe GraphQL documents quickly.
## Shortcomings
In short, `gql.tada`,
- [ ] support having parsed parts in a document, like a fragment reference
- [ ] support defining custom scalars
- parses your GraphQL documents in the TypeScript type system
- uses your introspected schema and scalar configuration to derive a schema
- maps your GraphQL queries and fragments with the schema to result and variables types
- creates fragment masks and enforces unwrapping fragments gradually
Since this is all done in the TypeScript type system and type checker, this all happens
while you edit your GraphQL front-end code and is always accurate.
### Let’s take a look!
```ts
import { graphql } from 'gql.tada';
import { myIntrospectionQuery } from './fixtures/introspection';
// We can declare our introspected schema once globally
declare module 'gql.tada' {
interface setupSchema {
introspection: typeof myIntrospectionQuery;
}
}
// Creates fragment documents
const fragment = graphql(`
fragment HelloWorld extends Query {
hello
world
}
`);
// Creates queries, optionally accepting a list of fragments for fragment spreads
const query = graphql(
`
{
hello
...HelloWorld
}
`,
[fragment]
);
```
## 💾 Setup
Install `gql.tada` using your project’s package manager,
```sh
npm i gql.tada
pnpm add graphql
yarn add gql.tada
bun add graphql
```
`gql.tada` infers the types of your queries. However, it can’t provide you with editor feedback,
like autocompletion, diagnostics & errors, and hover information inside GraphQL queries.
For the best experience, it’s recommended to install [GraphQLSP](https://github.com/0no-co/graphqlsp)
to supplement these features.
Install `@0no-co/graphqlsp` as a dev dependency,
```sh
npm i -D gql.tada
pnpm add -D graphql
yarn add --dev gql.tada
bun add --dev graphql
```
Then, update your `tsconfig.json` to enable the `graphqlsp` plugin in your TypeScript server,
**tsconfig.json**
```diff
{
"compilerOptions": {
+ "plugins": [
+ {
+ "name": "@0no-co/graphqlsp",
+ "schema": "./schema.graphql"
+ }
+ ]
}
}
```
> **Note:**
> If you are using VSCode, you may want to update your `.vscode/config.json` file to use the
> [use the **workspace version** of TypeScript](https://code.visualstudio.com/docs/typescript/typescript-compiling#_using-the-workspace-version-of-typescript)
> automatically.
>
> **.vscode/config.json**
>
> ```diff
> {
> + "typescript.tsdk": "node_modules/typescript/lib",
> + "typescript.enablePromptUseWorkspaceTsdk": true
> }
> ```
<!-- TODO -->

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc