我正在使用 graphql 代码生成器来获取我生成的文件:
npx graphql-codegen --config libs/codegen.yml
在这个文件中我确实有
export const AddDataDocument = gql`
mutation addData($input: AddDataInput!) {
addData(input: $input) {
id
}
}`;
这给了我 gql 文档。
在我的测试中(使用supertest
),我正在做:
const query = `
mutation addData($input: AddDataInput!) {
addData(input: $input) {
id
}
}`
request(app.getHttpServer())
.post('/graphql')
.send({
operationName: null,
query,
variables: { input: addDataInput }
})
我不想手动编写突变。我想使用我生成的模式文件。但不幸的是,定义了一个 gql,就像本文开头提到的那样。
是否可以生成要在我的 中使用的东西send()
?
request(app.getHttpServer())
.post('/graphql')
.send({
operationName: null,
query: AddDataDocument, // <-- but this is not working as it is a gql document
variables: { input: addDataInput }
})
代码生成.yml
overwrite: true
schema: "apps/backend/src/app/**/*.graphql"
generates:
libs/generated/generated.ts:
documents: "libs/**/*.graphql"
plugins:
- "typescript"
- "typescript-operations"
- "typescript-react-apollo"
config:
withHooks: true
withComponent: false
withHOC: false