dotansimha / dotansimha/graphql-code-generator

Unable to use the schema in ts as eslint doesn't pick up the `require` option

Open
#7,027 0 comments 0 reactions 0 assignees View on GitHub
core
Dominant language
TypeScript
Stars
11.3k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
23

Description

**Describe the bug**
I'm unable to use the schema in typescript as the eslint plugin [graphql-eslint](https://github.com/dotansimha/graphql-eslint) seems not to pickup the `require` option.

**To Reproduce**
Steps to reproduce the behavior:
my `schema.ts`:
```ts
import { makeExecutableSchema } from '@graphql-tools/schema';
import { typeDefs, resolvers } from './routes';
import { auditDirective } from './directives/audit';

const { auditDirectiveTransformer, auditDirectiveTypeDefs } = auditDirective('audit');
let schema = makeExecutableSchema({
typeDefs: [...auditDirectiveTypeDefs, ...typeDefs],
resolvers,
});
schema = auditDirectiveTransformer(schema);

export default schema;
```

`.graphqlrc`
```yml
schema:
- 'src/schema.ts*'
extensions:
codegen:
require:
- ts-node/register
generates:
./src/types/generated-graphql-types.ts:
hooks:
afterOneFileWrite:
- prettier --write
plugins:
- typescript
- typescript-resolvers
- add:
content: "import { PartialDeep } from 'type-fest';"
config:
optionalInfoArgument: true
useIndexSignature: true
contextType: ../request-context#RequestContext
defaultMapper: PartialDeep<{T}>
noSchemaStitching: true
nonOptionalTypename: false
makeResolverTypeCallable: true
skipTypename: false
```

`eslintrc.js`
```js
module.exports = {
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint'],
extends: ['plugin:@typescript-eslint/recommended', 'plugin:prettier/recommended'],
ignorePatterns: ['src/types/generated-graphql-types.ts'],
overrides: [
{
files: ['*.ts'],
processor: '@graphql-eslint/graphql',
extends: ['plugin:prettier/recommended'],
},
{
files: ['*.graphql'],
parser: '@graphql-eslint/eslint-plugin',
plugins: ['@graphql-eslint'],
rules: {
'prettier/prettier': 'error',
'@graphql-eslint/avoid-typename-prefix': 'error',
'@graphql-eslint/executable-definitions': 'error',
'@graphql-eslint/fields-on-correct-type': 'error',
'@graphql-eslint/fragments-on-composite-type': 'error',
'@graphql-eslint/known-argument-names': 'error',
'@graphql-eslint/known-directives': 'error',
'@graphql-eslint/known-fragment-names': 'error',
'@graphql-eslint/known-type-names': 'error',
'@graphql-eslint/lone-anonymous-operation': 'error',
'@graphql-eslint/lone-schema-definition': 'error',
'@graphql-eslint/naming-convention': 'error',
'@graphql-eslint/no-anonymous-operations': 'error',
'@graphql-eslint/no-case-insensitive-enum-values-duplicates': 'error',
'@graphql-eslint/no-fragment-cycles': 'error',
'@graphql-eslint/no-operation-name-suffix': 'error',
'@graphql-eslint/no-undefined-variables': 'error',
'@graphql-eslint/no-unused-fragments': 'error',
'@graphql-eslint/no-unused-variables': 'error',
'@graphql-eslint/one-field-subscriptions': 'error',
'@graphql-eslint/overlapping-fields-can-be-merged': 'error',
'@graphql-eslint/possible-fragment-spread': 'error',
'@graphql-eslint/possible-type-extension': 'error',
'@graphql-eslint/provided-required-arguments': 'error',
'@graphql-eslint/require-deprecation-reason': 'error',
'@graphql-eslint/scalar-leafs': 'error',
'@graphql-eslint/strict-id-in-types': 'error',
'@graphql-eslint/unique-argument-names': 'error',
'@graphql-eslint/unique-directive-names': 'error',
'@graphql-eslint/unique-directive-names-per-location': 'error',
'@graphql-eslint/unique-enum-value-names': 'error',
'@graphql-eslint/unique-field-definition-names': 'error',
'@graphql-eslint/unique-input-field-names': 'error',
'@graphql-eslint/unique-operation-types': 'error',
'@graphql-eslint/unique-type-names': 'error',
'@graphql-eslint/unique-variable-names': 'error',
'@graphql-eslint/value-literals-of-correct-type': 'error',
'@graphql-eslint/variables-are-input-types': 'error',
'@graphql-eslint/variables-in-allowed-position': 'error',
},
},
{
files: ['*.ts/*.graphql'],
rules: {
'prettier/prettier': 'off',
},
},
],
};
```

**Expected behavior**
Ability to use the schema in ts with eslint as well

**Environment:**

- OS:
- `@graphql-codegen/cli`: 2.2.2
- NodeJS: 16.13.0

**Additional context**
Apologies if you feel this is not the right repo to raise a ticket, it's very borderline between this and the graphql-eslint one

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.