Babel 插件反应中继



我正在尝试设置一个 graphql 项目。我已经运行了 GraphQL 服务器并尝试设置中继环境。我已经按照这里的说明进行操作 https://github.com/graphcool/babel-plugin-react-relay 但是当我尝试运行我的项目时,出现以下错误:

Project@1.0.0 启动/用户/JKB/站点/项目 nodemon --watch server --exec babel-node -- server/index.js

[nodemon] 1.11.0
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: /Users/JKB/Sites/project/server/**/*
[nodemon] starting `babel-node server/index.js`
/Users/JKB/Sites/project/node_modules/babel-plugin-react-relay/lib/index.js:27
throw error;
^
Error
at ClientRequest.<anonymous> (/Users/JKB/Sites/project/node_modules/node-fetch/index.js:133:11)
at emitOne (events.js:96:13)
at ClientRequest.emit (events.js:188:7)
at TLSSocket.socketCloseListener (_http_client.js:285:9)
at emitOne (events.js:101:20)
at TLSSocket.emit (events.js:188:7)
at _handle.close (net.js:501:12)
at TCP.done [as _onclose] (_tls_wrap.js:325:7)
at module.exports.loopWhile (/Users/JKB/Sites/project/node_modules/deasync/index.js:72:22)
at exports.default (/Users/JKB/Sites/project/node_modules/babel-plugin-react-relay/lib/index.js:21:26)
[nodemon] app crashed - waiting for file changes before starting...

我有以下 .babelrc

{
    "presets": [ "es2015", "react" ],
    "plugins": [ "react-html-attrs", "react-relay" ]
}

我已经导出了环境变量:
导出GRAPHQL_ENDPOINT="http://localhost:3000/graphql">

以及以下软件包版本:

"babel-relay-plugin": "^0.10.0"
"babel-plugin-react-relay": "^0.10.0"
"react-relay": "^0.10.0"

当我尝试重新安装时,我收到以下警告 - 不确定它们是否相关。

Project@1.0.0 /Users/JKB/Sites/project
├── babel-plugin-react-relay@0.10.0 
└── UNMET PEER DEPENDENCY babel-relay-plugin@0.11.0 invalid
npm WARN react-relay@0.10.0 requires a peer of babel-relay-plugin@0.10.0 but none was installed.
npm WARN Project@1.0.0 No repository field.
➜  project git:(master) ✗ npm install -D babel-relay-plugin      
Project@1.0.0 /Users/JKB/Sites/project
└── UNMET PEER DEPENDENCY babel-relay-plugin@0.11.0
npm WARN react-relay@0.10.0 requires a peer of babel-relay-plugin@0.10.0 but none was installed.
npm WARN Picso@1.0.0 No repository field.
npm ERR! code 1

你不需要babel-plugin-react-relay来设置 GraphQL 服务器。此插件由客户端而不是服务器使用。

你可以在没有这个插件的情况下运行 GraphQL 服务器。但是,要使用中继客户端使用该服务器,您需要配置插件 - 仅在客户端中。

请参阅此存储库中用于中继客户端应用程序的 GraphQL 服务器的完整示例:https://github.com/danielfeelfine/graphql-relay-server。您需要此脚本为 Babel 中继插件生成具有模式内省的 JSON。

最后,这里有一个 Relay 客户端应用程序(使用 React Native(的示例,在这个存储库中使用 GraphQL 服务器:https://github.com/danielfeelfine/react-native-relay。包含配置的 .babelrc babel-relay-plugin您需要使用的内容。

相关内容

  • 没有找到相关文章

最新更新