简体   繁体   English

中继现代-什么是database.js,有必要吗?

[英]Relay Modern- what is database.js and is it necessary?

In the Relay Modern example app todo-modern there is a file called database.js. 在Relay Modern示例应用程序todo-modern有一个名为database.js的文件。 Is this file necessary in all Relay Modern apps? 所有Relay Modern应用程序都需要此文件吗? If not, how do you define {nodeInterface, nodeField} without it? 如果没有,如何不定义{nodeInterface, nodeField} It seems to have all of these getter functions that I don't understand the point of. 我似乎不了解所有这些吸气剂功能。

I'm finding that there is not enough documentation or examples of Relay Modern. 我发现中继现代没有足够的文档或示例。 It is quite frustrating. 真令人沮丧。

This isn't clearly stated in the documentation, but schema.js and database.js are for the purposes of mocking a remote server service running GraphQL. 文档中没有明确说明这一点,但是schema.js和database.js用于模拟运行GraphQL的远程服务器服务。 I already have a PHP backend running a GraphQL server, so here's what I had to do: 我已经有一个运行GraphQL服务器的PHP后端,所以这是我必须做的:

  1. Install the npm package get-graphql-schema globally. 全局安装npm软件包get-graphql-schema
  2. Add an npm script to my package.json: "generate-graphql": "get-graphql-schema http://0.0.0.0:8000/graphql > ./App/Data/schema.graphql" . 在我的package.json中添加一个npm脚本: "generate-graphql": "get-graphql-schema http://0.0.0.0:8000/graphql > ./App/Data/schema.graphql" Obviously, change the local endpoint to your server's graphql endpoint, and change the output to where you want your schema to exist 显然,将本地终结点更改为服务器的graphql终结点,并将输出更改为希望模式存在的位置
  3. Run npm run generate-graphql which generates the schema 运行npm run generate-graphql生成模式
  4. Add an npm script to use the new schema to build necessary generated files: "relay:build": "relay-compiler --src ./App --schema ./App/Data/schema.graphql" . 添加一个npm脚本以使用新架构来构建必要的生成文件: "relay:build": "relay-compiler --src ./App --schema ./App/Data/schema.graphql" Again, change endpoints as necessary. 同样,根据需要更改端点。
  5. Run this new script. 运行此新脚本。 You should be good to go! 你应该很好走!

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

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