export type List = T | T[]; export interface Definition { query?: Operation; mutation?: Operation; subscription?: Operation; fragments?: List; } export interface FragmentProps { /** * Spread named fragments. */ $spread?: List; /** * Inline fragments. */ $on?: { [typeName: string]: List; }; } export interface Operation extends FragmentProps { /** * Optional operation name. */ $name?: string; /** * Optional variable definitions. * * @example * { * $status: "Int", * $codes: "[String!] = []" * } */ $variables?: Record; /** * Optional directives. * * @example * { * name: '@skip', * args: { if: true } * } */ $directives?: Directives; /** * Optional fields. */ $fields?: ({ [key: string]: FieldValue; } & FragmentProps)[]; /** * Any other selection. */ [key: string]: FieldValue; } export interface Field extends FragmentProps { /** * Alias for the field. */ $alias?: string; /** * Arguments for the field. */ $args?: Args; /** * Directives for the field. */ $directives?: Directives; /** * The content to replace the entire field (including the key). */ $content?: string; /** * The content to replace the body of the field. */ $body?: string; /** * Any other selection. */ [key: string]: FieldValue; } export type FieldValue = boolean | null | number | object | string | undefined | Field | Field[]; export type Args = Record; export type ArgValue = boolean | null | number | string | undefined | ArgValue[] | { /** * @example { $enum: 'DESC' } */ $enum: string | null | undefined; } | { /** * @example { $var: '$keyword' } */ $var: string | null | undefined; } | { /** * @example { $raw: '{}' } */ $raw: string | number | boolean | null | undefined; } | { /** * A flag to keep the value even it is an empty object. */ $keep?: ArgValue; /** * Nested arguments. */ [key: string]: ArgValue; }; export type Directives = List; export interface Directive { /** * Directive name, must start with `@`. Example: `@skip`. */ name: string; /** * Optional directive arguments. */ args?: Args; } export interface FragmentDeclarations { [name: string]: FragmentDefinition; } export interface FragmentDefinition extends FragmentProps { $onType: string; $directives?: Directives; [key: string]: FieldValue; } export interface Options { indent?: number; indentChar?: string; } export declare const generateQuery: (definition: T, options?: Options) => string;