简体   繁体   中英

Babel plugin react relay

I am trying to setup a graphql project. I already have the GraphQL server running and trying to setup a relay environment. 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:

Project@1.0.0 start /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

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

and I have exported the environment variable:
export 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. This plugin are used by the client not the server.

You can run the GraphQL server without this plugin. 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 . You need this script to generate a JSON with schema introspection for Babel Relay Plugin .

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 . The .babelrc containing the configuration for babel-relay-plugin what you need to use.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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