CLI Configuration#
The CLI
looks for 3 places of configuration files/property, in this respective order:
gqty.config.cjs
gqty.config.js
gqty
property insidepackage.json
And since it's using cosmiconfig to resolve it, if you are using GQty in a monorepo, having it in the root of your monorepo might be enough 🎉.
Default Config#
The default configuration file, which is automatically generated after the first execution of gqty generate
, should look like this:
/**
* @type {import("@gqty/cli").GQtyConfig}
*/
const config = {
enumsAsStrings: false,
react: true,
scalarTypes: { DateTime: 'string' },
preImport: '',
introspection: {
endpoint: 'SPECIFY_ENDPOINT_OR_SCHEMA_FILE_PATH_HERE',
headers: {},
},
destination: './src/gqty/index.ts',
subscriptions: false,
};
module.exports = config;
Properties#
| Name | Type | Description |
| ---------------------- | --------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| enumsAsStrings | boolean
| Whether to use enums as simple string types, or as the default Object String Enums of TypeScript. |
| react | boolean
| Whether to add the React bindings to the first-generated client. |
| scalarTypes | Record<string,string>
| Mapping of Custom Scalar Types to TypeScript, since by default, any custom scalar will be casted as any
. |
| preImport | string
| Code to be added at the very beginning of the generated schema file
, useful for adding custom imported types in custom scalars. |
| introspection.endpoint | string
| Endpoint from where the introspection of the target GraphQL API, it can be an http
/https
endpoint, or the path of a .gql
GraphQL schema file. |
| introspection.headers | Record<string,string>
| Custom headers to be added to http
/https
introspection, normally for authorization purposes. |
| destination | string
| File destination of the generated client. Keep in mind that the generated schema always will be alongside this destination, but named schema.generated.ts
. |
| subscriptions | boolean
| Whether to add Subscriptions support to the client. |
| transformSchema | (schema: GraphQLSchema, graphql_js: import("graphql")) => Promise<GraphQLSchema> | GraphQLSchema
| Transform the GraphQL Schema before being used to generate the client |
- See JavaScript Output
- See Programmatic Usage
- See Codegen