简体   繁体   English

如何从nodejs-api-starter获取到react-starter-kit

[英]How to fetch from nodejs-api-starter into react-starter-kit

I am trying out React-Starter-Kit for the first time and loving all the cutting edge features baked in (apollo/graphql-client in particular). 我是第一次尝试使用React-Starter-Kit,并且喜欢其中包含的所有最先进的功能(尤其是apollo / graphql-client)。 A crucial part of any app for me is the database, and for that my understanding is the same author provides nodejs-api-starter which sets up a REST interface for accessing Postgres at localhost:5000 and has a graphql webui at localhost:5000/graphl. 对我而言,任何应用程序的关键部分都是数据库,因此我的理解是同一位作者提供了nodejs-api-starter,它为在localhost:5000访问Postgres设置了REST接口,并在localhost:5000 /具有了graphql webui石墨烯

That is about as far as I have been able to understand of the setup so far. 到目前为止,到目前为止,我已经了解了该设置。 I have changed the frontend code a little bit so a new Component "Counter" is loaded on the home page. 我对前端代码进行了一些更改,以便在主页上加载新的组件“ Counter”。 I need to be able to make a new counter, fetch the latest counter, and increment decrement the counter. 我需要能够创建一个新的计数器,获取最新的计数器,并递增递减计数器。 Write now the component just outputs the 'value' retrieved from the server at 5000. 现在写入,该组件仅输出从服务器以5000取回的“值”。

I do not think I am accessing the 5000 server correctly, do I put the port in this url line somehow? 我认为我无法正确访问5000服务器,是否将端口以某种方式放在此url行中

You can pull the repo down from : https://github.com/Falieson/react-starter-kit-crud-counter-demo 您可以从以下位置拉回仓库: https : //github.com/Falieson/react-starter-kit-crud-counter-demo

This is my first time setting up a nodejs api server, I am used to using MeteorJS which has pub/sub to MongoDB baked in. I am looking forward to the separation the RSK strategy (which seems more industry standard?) provides. 这是我第一次设置Node.js api服务器,我习惯使用MeteorJS,它已将pub / sub移植到MongoDB中。我期待RSK策略(似乎更符合行业标准?)提供的分离。

I've just done setting up the full site with Database from React-Stater-Kit, I'm also a newbie so I understand your frustration. 我刚刚用React-Stater-Kit中的Database设置了整个站点,我还是一个新手,所以我理解您的无奈。

About this question, you don't need the NodeJS-API-Starter, it has enhanced function ( such as Redis cache ) and it's not suited for newbies. 关于这个问题,您不需要NodeJS-API-Starter,它具有增强的功能(例如Redis cache),并且不适合新手。 You should look deeper into the RSK, it already has the DB. 您应该更深入地研究RSK,因为它已经有了DB。 If you ran the boilerplate and played around, change is you'll see file database.sqlite in your folder, it's the database. 如果您运行了样板并进行了播放,更改的地方是您在文件夹中看到了database.sqlite文件,即数据库。 Here are the things you should learn: 这是您应该学习的内容:

  1. Use SequelizeJS to connect the NodeJS server with database. 使用SequelizeJSNodeJS服务器与数据库连接。 Your database can be MySQL/MariaDB, PostgreSQL or SQLite. 您的数据库可以是MySQL / MariaDB,PostgreSQL或SQLite。 The connection is easy and there's tool to auto-generate Models from your database 连接很容易,并且有工具可以从数据库中自动生成模型
  2. How to create GraphQL's Types and Queries. 如何创建GraphQL的类型和查询。 If your queries need to search through the database, import Sequelize's models and use its functions. 如果您的查询需要搜索数据库,请导入Sequelize的模型并使用其功能。
  3. Test your API via GraphQLi 通过GraphQLi测试您的API

Note: if you want to use MongoDB or other NoSQL, try Mongoose instead of Sequelize. 注意:如果要使用MongoDB或其他NoSQL,请尝试使用Mongoose代替Sequelize。

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

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