UNPKG

@gqty/cli

Version:

Interactive codegen for GQty

99 lines (98 loc) 3.2 kB
import { type ScalarsEnumsHash, type Schema } from 'gqty'; import type { GraphQLField, GraphQLSchema } from 'graphql'; import * as graphql from 'graphql'; import { type GQtyConfig } from './config'; import * as deps from './deps'; export type SupportedFrameworks = 'react' | 'solid-js'; export interface GenerateOptions { /** * The endpoint to use for the `queryFetcher` function */ endpoint?: string; /** * Customize the TypeScript types for scalars. * * You can use the `preImport` option to import / define custom types. * * @example * ```json * scalarTypes: { * DateTime: "string", * } * ``` */ scalarTypes?: Exclude<deps.typescriptPlugin.TypeScriptPluginConfig['scalars'], string>; /** * Prepend code to the schema file, useful with the `scalarTypes` option. */ preImport?: string; /** * Generate React Client code * * @deprecated Use `frameworks` instead. */ react?: boolean; /** * Frontend framework integrations to be included. */ frameworks?: Array<SupportedFrameworks>; /** * Generated enum styles. * * 1. assertion: Enums will be generated as `const assertion` style objects. * 2. const: Enums will be prefixed with the `const` keyword. * 3. enum: Enums will be generated as TypeScript enums. * 4. string: Enums will be generated as string unions. * * @default "enum" */ enumStyle?: 'assertion' | 'const' | 'enum' | 'string'; /** * @deprecated Use `enumStyle` instead. * * Define enums as string types instead of enums objects * * @default false */ enumsAsStrings?: boolean; /** * @deprecated Use `enumStyle` instead. * * Define enums as const types instead of enums objects * * @default false */ enumsAsConst?: boolean; /** * Generate subscriptions client with target package * * @default false */ subscriptions?: boolean | string; /** * Generate Javascript code instead of TypeScript * * @default false */ javascriptOutput?: boolean; /** * Transform the GraphQL Schema before being used to generate the client */ transformSchema?: (schema: GraphQLSchema, graphql_js: typeof graphql) => Promise<GraphQLSchema> | GraphQLSchema; } export interface TransformSchemaOptions { /** * Get a field in which every argument is optional, if this functions return * "true", gqty will _always__ ignore it's arguments, and you won't be able to * specify them */ ignoreArgs?: (type: GraphQLField<unknown, unknown>) => boolean; } export declare function generate(schema: GraphQLSchema, { enumsAsConst, enumsAsStrings, enumStyle, introspection, endpoint, javascriptOutput: isJavascriptOutput, preImport, react, frameworks, scalarTypes, subscriptions, transformSchema, }?: GQtyConfig, { ignoreArgs }?: TransformSchemaOptions): Promise<{ clientCode: string; schemaCode: string; javascriptSchemaCode: string; generatedSchema: Schema; scalarsEnumsHash: ScalarsEnumsHash; isJavascriptOutput: boolean; }>;