简体   繁体   English

Babel插件React Relay

[英]Babel plugin react relay

I am trying to setup a graphql project. 我正在尝试设置一个graphql项目。 I already have the GraphQL server running and trying to setup a relay environment. 我已经在运行GraphQL服务器并尝试设置中继环境。 I have followed the instructions from here https://github.com/graphcool/babel-plugin-react-relay but when I try and run my project I get the following error: 我已经按照这里的说明https://github.com/graphcool/babel-plugin-react-relay,但是当我尝试运行我的项目时,出现以下错误:

Project@1.0.0 start /Users/JKB/Sites/Project nodemon --watch server --exec babel-node -- server/index.js Project@1.0.0开始/ Users / JKB / Sites / Project 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...

I have the following .babelrc 我有以下.babelrc

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

and I have exported the environment variable: 并且我已经导出了环境变量:
export GRAPHQL_ENDPOINT="http://localhost:3000/graphql" 出口GRAPHQL_ENDPOINT =“ http:// localhost:3000 / graphql”

and the following package versions: 以及以下软件包版本:

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

When I try to reinstall I get the following warnings - not sure if they are related.. 当我尝试重新安装时,收到以下警告-不知道它们是否相关。

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

You don't need a babel-plugin-react-relay to setup the GraphQL server. 您不需要babel-plugin-react-relay来设置GraphQL服务器。 This plugin are used by the client not the server. 该插件由客户端而非服务器使用。

You can run the GraphQL server without this plugin. 您可以在没有此插件的情况下运行GraphQL服务器。 However, for consuming that server with a Relay client, you need to configure the plugin - only in the client. 但是,要通过中继客户端使用该服务器,您需要配置插件-仅在客户端中。

See a full example of GraphQL server for Relay client apps in this repository: https://github.com/danielfeelfine/graphql-relay-server . 在此存储库中查看用于中继客户端应用程序的GraphQL服务器的完整示例: https : //github.com/danielfeelfine/graphql-relay-server You need this script to generate a JSON with schema introspection for Babel Relay Plugin . 您需要此脚本来为Babel Relay Plugin生成带有模式自省的JSON。

And finally, here an example of Relay client app (using React Native), consuming the GraphQL server, in this repository: https://github.com/danielfeelfine/react-native-relay . 最后,这是此存储库中使用GraphQL服务器的Relay客户端应用程序示例(使用React Native): https : //github.com/danielfeelfine/react-native-relay The .babelrc containing the configuration for babel-relay-plugin what you need to use. .babelrc包含需要使用的babel-relay-plugin的配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM