@gqlts/runtime
Version:
Gqlts runtime client
85 lines (64 loc) • 2.09 kB
text/typescript
type Impossible<K extends keyof any> = {
[P in K]: never;
};
// The secret sauce! Provide it the type that contains only the properties you want,
// and then a type that extends that type, based on what the caller provided
// using generics.
export type NoExtraProperties<T, U extends T = T> = U & Impossible<Exclude<keyof U, keyof T>>;
/////////////////////////
export interface ExecutionResult<TData = { [key: string]: any }> {
errors?: ReadonlyArray<Error>;
// TS_SPECIFIC: TData. Motivation: https://github.com/graphql/graphql-js/pull/2490#issuecomment-639154229
data?: TData | null;
}
// TYPE MAP ////////////
// the type of types.json object
export interface ArgMap<keyType = number> {
[arg: string]: [keyType, string] | [keyType] | undefined;
}
export type CompressedField<keyType = number> = [type: keyType, args?: ArgMap<keyType>];
// export type Field = [string] | [string, ArgMap]
export interface CompressedFieldMap<keyType = number> {
[field: string]: CompressedField<keyType> | undefined;
}
export type CompressedType<keyType = number> = CompressedFieldMap<keyType>;
export interface CompressedTypeMap<keyType = number> {
scalars: Array<keyType>;
types: {
[type: string]: CompressedType<keyType>;
};
}
// normal types
export type Field<keyType = number> = {
type: keyType;
args?: ArgMap<keyType>;
};
export interface FieldMap<keyType = number> {
[field: string]: Field<keyType> | undefined;
}
export type Type<keyType = number> = FieldMap<keyType>;
export interface TypeMap<keyType = number> {
scalars: Array<keyType>;
types: {
[type: string]: Type<keyType> | undefined;
};
}
// LINKED TYPE ////////////
export interface LinkedArgMap {
[arg: string]: [LinkedType, string] | undefined;
}
export interface LinkedField {
type: LinkedType;
args?: LinkedArgMap;
}
export interface LinkedFieldMap {
[field: string]: LinkedField | undefined;
}
export interface LinkedType {
name: string;
fields?: LinkedFieldMap;
scalar?: string[];
}
export interface LinkedTypeMap {
[type: string]: LinkedType | undefined;
}