我正在使用图形码发生器工具生成graphql类型和钩子,出于某种原因,它生成了一个schema.ts文件,在该文件中,下面的导入一直放在第197行,而不是放在顶部:
import { IntrospectionQuery } from 'graphql';因此,对投诉的反应显然是:
src/graphql/generated/schema.ts
Line 197:1: Import in body of module; reorder to top import/first下面是schema.ts文件的一部分:
…
export type SendEmMutation = { __typename?: 'Mutation', sendPasswordResetEmail: { __typename?: 'SuccessResponse', success: boolean } };
import { IntrospectionQuery } from 'graphql';
export default {
"__schema": {
"queryType": {
"name": "Query"
},
"mutationType": {
…codegen.yml文件:
overwrite: true
schema: ${GRAPHQL_ENDPOINT}
documents: '**/*.{gql,graphql}'
generates:
src/graphql/generated/schema.ts:
plugins:
- 'typescript'
- 'typescript-operations'
- 'urql-introspection'
- 'typescript-urql'
config:
withHooks: true
./graphql.schema.json:
plugins:
- 'introspection'Package.json
"devDependencies": {
"@graphql-codegen/cli": "2.11.8",
"@graphql-codegen/introspection": "2.2.1",
"@graphql-codegen/typescript": "2.7.3",
"@graphql-codegen/typescript-operations": "2.5.3",
"@graphql-codegen/typescript-urql": "^3.6.4",
"@graphql-codegen/urql-introspection": "2.2.1",脚本npm run codegen通过运行此文件(在package.json中的脚本中) "graphql-codegen -require dotenv/config“生成该文件。
当然,我可以手动从第197行移除导入,并将其放在顶部;但是为什么它要在第197行附近添加导入呢?我不希望每次运行npm run codegen脚本时都需要手动操作。任何帮助都将不胜感激,谢谢。
注意,我在前端使用URQL客户端,在后端使用阿波罗服务器。
发布于 2022-10-20 09:27:53
我是查莉,来自行会,致力于GraphQL代码生成器。
您是对的;对于某些指针,urql-introspection插件的输出可能被视为无效。
但是,请知道我们建议不要提交代码格式化程序(例如:更漂亮的代码),也不要从代码格式化器中排除所有由codegen生成的文件。
https://stackoverflow.com/questions/73591352
复制相似问题