我刚刚开始了一个新的项目,它使用NextJS和graphql-codegen来从我的API生成apollo-react类型。然而,马上它创建了重复的导出变量,我不能构建我的项目,由于typescript错误。关于如何防止codegen创建这些副本有什么想法?
codegen.ts
import type { CodegenConfig } from "@graphql-codegen/cli";
const config: CodegenConfig = {
overwrite: true,
documents: ["src/**/*.tsx"],
schema: process.env.NEXT_PUBLIC_GRAPHQL_ENDPOINT,
generates: {
"./src/graphql/__generated__/": {
preset: "client",
plugins: ["typescript-react-apollo"],
},
},
};
export default config;
codegen error
// ./src/graphql/__generated__/
...
// creates two 'UserDocument' variables
export const UserDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"User"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"userId"}},"type":{"kind":"NamedType","name":{"kind":"Name","value":"ObjectId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"user"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"id"},"value":{"kind":"Variable","name":{"kind":"Name","value":"userId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"email"}},{"kind":"Field","name":{"kind":"Name","value":"image"}},{"kind":"Field","name":{"kind":"Name","value":"hashedPassword"}},{"kind":"Field","name":{"kind":"Name","value":"role"}}]}}]}}]} as unknown as DocumentNode<UserQuery, UserQueryVariables>;
export const UserDocument = gql`
query User($userId: ObjectId) {
user(id: $userId) {
id
name
email
image
hashedPassword
role
}
}
`;
...
1条答案
按热度按时间eimct9ow1#
我最终转储了
generates: { preset: 'client' }
字段,并传入了所有我自己的插件并更新了配置:这似乎工作。