dotansimha / dotansimha/graphql-code-generator

@graphql-codegen/add plugin doesn’t respect order when using codegen.ts

Open
#8,732 0 comments 5 reactions 0 assignees View on GitHub
stage/0-issue-prerequisites
Dominant language
TypeScript
Stars
11.3k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
23

Description

### Which packages are impacted by your issue?

@graphql-codegen/add

### Describe the bug

Using codegen.ts with add does not respect the order of plugins.

Example codegen.ts:
``` 'src/': {
preset: 'near-operation-file',
presetConfig: { baseTypesPath: 'src/services/api/generated.ts' },
plugins: [
{
add: {
content: `
/* eslint-disable */
/**
*
* THIS FILE IS AUTOGENERATED, DO NOT EDIT IT!
*
* instead, edit one of the .graphql files in this project and run
*
* npm run graphql-codegen
*
* for this file to be re-created
*/
`,
},
},
'typescript-operations',
{
'typescript-rtk-query': {
importBaseApiFrom: 'src/services/api/baseApi',
exportHooks: true,
overrideExisting: true,
},
},
],
},
```

Output:
```
import * as Types from '../../src/services/api/generated';

import { api } from 'src/services/api/baseApi';

/* eslint-disable */
/**
*
* THIS FILE IS AUTOGENERATED, DO NOT EDIT IT!
*
* instead, edit one of the .graphql files in this project and run
*
* npm run graphql-codegen
*
* for this file to be re-created
*/
```

However when I convert to codegen.yml the order of plugins is respected.

### Your Example Website or App

no website

### Steps to Reproduce the Bug or Issue

1. Generate a codegen with add plugin and other plugins using `codegen.ts`

### Expected behavior

As a user I expect the plugin ordering to be respected w.r.t when add plugin prepends

### Screenshots or Videos

_No response_

### Platform

- OS: macOS
- NodeJS: 16
- `graphql` version: 15.8.0
- `@graphql-codegen/add`: "^3.2.3",
- `@graphql-codegen/cli`: "2.16.1",
- `@graphql-codegen/client-preset`: "1.2.3",
- `@graphql-codegen/introspection`: "2.2.3",
- `@graphql-codegen/near-operation-file-preset`: "^2.4.4",
- `@graphql-codegen/typed-document-node`: "^2.3.10",
- `@graphql-codegen/typescript-resolvers`: "^2.7.10",
- `@graphql-codegen/typescript-rtk-query`: "^2.3.7",

### Codegen Config File
```ts
import type { CodegenConfig } from '@graphql-codegen/cli'

const config: CodegenConfig = {
overwrite: true,
schema: "SCHEMA",
documents: ['./src/pages/dashboard/*.graphql'],
generates: {
'src/services/api/generated.ts': {
plugins: ['typescript'],
config: {
maybeValue: 'T',
},
},
'src/': {
preset: 'near-operation-file',
presetConfig: { baseTypesPath: 'src/services/api/generated.ts' },
plugins: [
{
add: {
content: `
/* eslint-disable */
/**
*
* THIS FILE IS AUTOGENERATED, DO NOT EDIT IT!
*
* instead, edit one of the .graphql files in this project and run
*
* npm run graphql-codegen
*
* for this file to be re-created
*/
`,
},
},
'typescript-operations',
{
'typescript-rtk-query': {
importBaseApiFrom: 'src/services/api/baseApi',
exportHooks: true,
overrideExisting: true,
},
},
],
},
'./graphql.schema.json': {
plugins: ['introspection'],
},
},
}

export default config
```

### Additional context

_No response_

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.