简体   繁体   English

在 REST API 内部使用 GraphQL 进行数据查询

[英]Using GraphQL inside REST API for data querying

I have an existing Node.js REST API that currently uses pg-promise for querying data from database.我有一个现有的 Node.js REST API 目前使用 pg-promise 从数据库中查询数据。 But instead I want to use GraphQL for querying the data from database.但相反,我想使用 GraphQL 从数据库中查询数据。 So, I want to use GraphQL only internally.所以,我只想在内部使用 GraphQL 。 All tutorials I found show how to build a GraphQL server.我找到的所有教程都展示了如何构建 GraphQL 服务器。 But can I use GraphQL only internally for querying data as well?但是我可以只在内部使用 GraphQL 来查询数据吗?

Thanks!谢谢!

Yes, but you'll still need to set up a graphql server.是的,但您仍需要设置 graphql 服务器。

Databases speak SQL and won't understand graphql directly.数据库说 SQL 并且不会直接理解 graphql。 You need a separate application to receive the graphql and query the database.您需要一个单独的应用程序来接收 graphql 并查询数据库。

+-------------+           +------------------+       +----------+
+ Application +-----------+ Application      +-------+ database +
+             +  graphql  + (graphql server) +  SQL  +          +
+-------------+           +------------------+       +----------+

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

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