简体   繁体   中英

Where does `yarn run react` fit into the Relay workflow?

I'm trying to get Relay working with my React Native app and talking to my GraphQL server. I think I'm missing some pieces of understanding.

I'm following the instructions at https://facebook.github.io/relay/docs/relay-modern.html

It details the yarn commands to set up relay and the babel plugin. I added the "relay" script to my package.json like this:

"relay": "relay-compiler --src ./App --schema ./App/Data/schema.graphql"

But, when I run yarn run relay I get

Error: --schema path does not exist: /Users/user/dev/react-native-app/App/Data/schema.graphql.

Yeah. It doesn't exist. Isn't that what this command is supposed to generate? That documentation page doesn't explain what this command outputs, nor what it needs as input. How can I get this command working correctly? Do I really have to hand-write a schema when it already exists on the server?

EDIT, for php

Given that you are generating your schema on a PHP server, you can generate the .graphql file by creating a Node.js script to:


General usage with graphql-js

As far as I know, you effectively need your schema printed in GraphQL language. You can have a look at printSchema for this, to provide it to the relay-compiler.

printSchema will do the JS Object -> Schema Language conversion. If you already have your schema in Schema Language, this is what you need to provide to the relay-compiler.

It may be possible to use directly the JS Object schema, but I don't know how.

For a detailed explanation of the complete setup, you can look at my other answer here .

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