我正在为我工作的 Web 应用程序的反应端设置 Jest 和 Enzyme 测试。我遇到了 graphql 文件的问题,当我尝试运行测试时收到此错误
我们使用... react, graphql + urql, babel, webpack
GraphQLError: Syntax Error: Unexpected Name "export"
我相当确定这是我的 graphql 文件的第一行,看起来像这样......
export const sendCohortEmail = `
mutation SendCohortEmail(
$cohortId: ID!, $emailKey: String!
) {
sendCohortEmails(cohortId: $cohortId, emailKey: $emailKey){
cohort {
id
onboardingSentAt
}
errors
}
}
`
我不确定问题是什么,因为我目前已经遵循了大约 100 条指南。我什至不在乎这些是否加载,它们在后端进行了测试,所以就我而言,我可以忽略 graphql 文件,但我似乎也不能这样做。
我在我的 webpack 配置文件中使用 babel-loader 和 graphql-tag/loader。
这是我的 package.json 中的 babel 配置...
"babel": {
"plugins": [
"styled-components",
"@babel/plugin-syntax-dynamic-import",
"@babel/plugin-syntax-import-meta",
"@babel/plugin-proposal-class-properties",
"@babel/plugin-proposal-json-strings",
[
"@babel/plugin-proposal-decorators",
{
"legacy": true
}
],
"@babel/plugin-proposal-function-sent",
"@babel/plugin-proposal-export-namespace-from",
"@babel/plugin-proposal-numeric-separator",
"@babel/plugin-proposal-throw-expressions",
"@babel/plugin-proposal-export-default-from",
"@babel/plugin-proposal-logical-assignment-operators",
"@babel/plugin-proposal-optional-chaining",
[
"@babel/plugin-proposal-pipeline-operator",
{
"proposal": "minimal"
}
],
"@babel/plugin-proposal-nullish-coalescing-operator",
"@babel/plugin-proposal-do-expressions",
"@babel/plugin-proposal-function-bind"
],
"presets": [
[
"@babel/preset-env",
{
"modules": false,
"targets": {
"node": "current"
}
}
],
"@babel/preset-react"
],
"env": {
"production": {
"plugins": [
"transform-react-remove-prop-types",
"@babel/plugin-transform-react-inline-elements",
"@babel/plugin-transform-react-constant-elements"
]
},
"test": {
"plugins": [
"@babel/plugin-transform-modules-commonjs",
"dynamic-import-node",
"@babel/plugin-transform-react-jsx",
"@babel/plugin-proposal-class-properties"
]
}
}
}