UNPKG

@gqty/cli

Version:

## Visit [https://gqty.dev/docs/cli/codegen](https://gqty.dev/docs/cli/codegen)

76 lines (75 loc) 2.34 kB
import { type ScalarsEnumsHash, type Schema } from 'gqty/Schema'; import type { GraphQLField, GraphQLSchema } from 'graphql'; import * as graphql from 'graphql'; import { type GQtyConfig } from './config'; 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?: Record<string, string>; /** * Prepend code to the schema file, useful with the `scalarTypes` option. */ preImport?: string; /** * Generate React Client code */ react?: boolean; /** * Define enums as string types instead of enums objects * * @default false */ enumsAsStrings?: boolean; /** * 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, { endpoint, enumsAsConst, enumsAsStrings, introspection, javascriptOutput, preImport, react, scalarTypes, subscriptions, transformSchema, }?: GQtyConfig, { ignoreArgs }?: TransformSchemaOptions): Promise<{ clientCode: string; schemaCode: string; javascriptSchemaCode: string; generatedSchema: Schema; scalarsEnumsHash: ScalarsEnumsHash; isJavascriptOutput: boolean; }>;