首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >模块生成失败: GraphQLError

模块生成失败: GraphQLError
EN

Stack Overflow用户
提问于 2017-05-29 12:28:20
回答 1查看 1.2K关注 0票数 1

我无法理解错误,我添加了graphq-tag来解析webpack配置文件中的.graphql,如下所示

代码语言:javascript
复制
{
  test: /\.(graphql|gql)$/,
  exclude: /node_modules/,
  loader: 'graphql-tag/loader'
}

下面是我的.graphql文件

代码语言:javascript
复制
import {gql} from 'react-apollo';

const query = gql`
  query {
    userCurrent{
      profile {
      name
    }
    appRoles,
    username,
    authEmail {
      address
    }
    orgs {
      userOrgRoles
      orgId
      name
      orgRoles
    }
    currentOrg {
      orgId
      userOrgRoles
      name
      orgRoles
    }
  }
}`;

export default query;

误差

代码语言:javascript
复制
ERROR in **./src/modules/goin_users/client/graphql_queries/user_graphql_queries.graphql
[2] Module build failed: GraphQLError**
[2]     at syntaxError (/home/sairam/Downloads/goin/goin/node_modules/graphql-tag/bundledParser.js:1349:16)
[2]     at unexpected (/home/sairam/Downloads/goin/goin/node_modules/graphql-tag/bundledParser.js:1043:34)
[2]     at parseDefinition (/home/sairam/Downloads/goin/goin/node_modules/graphql-tag/bundledParser.js:206:10)
[2]     at parseDocument (/home/sairam/Downloads/goin/goin/node_modules/graphql-tag/bundledParser.js:160:23)
[2]     at parse (/home/sairam/Downloads/goin/goin/node_modules/graphql-tag/bundledParser.js:97:11)
[2]     at parseDocument (/home/sairam/Downloads/goin/goin/node_modules/graphql-tag/index.js:125:16)
[2]     at gql (/home/sairam/Downloads/goin/goin/node_modules/graphql-tag/index.js:158:10)
[2]     at Object.module.exports (/home/sairam/Downloads/goin/goin/node_modules/graphql-tag/loader.js:27:18)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-29 13:35:43

您的.graphql文件应该只包含普通查询,而不是javascript代码:

代码语言:javascript
复制
query {
    userCurrent{
      profile {
      name
    }
    appRoles,
    username,
    authEmail {
      address
    }
    orgs {
      userOrgRoles
      orgId
      name
      orgRoles
    }
    currentOrg {
      orgId
      userOrgRoles
      name
      orgRoles
    }
}

然后只需导入它:

代码语言:javascript
复制
import query from './query.graphql';

console.log(query);
// {
//   "kind": "Document",
// ...

graphql-tag加载程序将处理其余部分。

仅在单独的文件中进行简单的查询,就可以直接在您使用的代码编辑器中获得查询高亮显示和自动建议的优势:

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44242515

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档