用GraphQL替换REST调用 [英] Replacing REST calls with GraphQL

查看:81
本文介绍了用GraphQL替换REST调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近阅读了GraphQL相对于Rest API的优点(和缺点).

I've recently read about the advantages (and disatvanteges) of GraphQL over Rest API.

我正在开发一个使用几个不同的Rest API和Soap服务的网页.这些服务中的某些服务是依赖的,这意味着Rest1的结果将作为参数传递给Rest2,Rest2将作为最终返回值传递给Soap服务.

I am developing a webpage that consumes several different Rest APIs and Soap services. Some of those services are dependent, meaning that a result from Rest1 will be passed as a parameter to Rest2 which will be passed to Soap service for a final return value.

据我了解,GraphQL处理多个数据源和查询嵌套,但是我还不知道它能否处理那些嵌套的依赖查询.

From what I understood, GraphQL deals with multiple data sources and query nesting, but I have not yet understood if it will handle those nested dependent queries.

任何使用过GraphQL依赖的几个数据源的人都可以告诉我是否可以做到吗?我的项目应该在2周内完成,花时间学习和设置GraphQL并最终不使用它,因为它不支持我的案子,这对我来说是一个很大的失败.

Can anyone that worked with several data sources that are dependent with GraphQL tell me if it can be done? My project should be up in 2 weeks and investing time in learning and setting up GraphQL and ending up not using it because it's not supporting my case would be a big failure for me.

注意:API和服务不是我的,我是从外部来源使用它们

推荐答案

我假设您尚未设置GraphQL服务器.完成后,您将看到这并不难.因此,建议您首先设置自己的服务器.Egghead课程"构建GraphQL服务器"使我开始学习,但这是不是免费的.

I'm assuming you haven't yet setup a GraphQL server. Once you do, you can see how this isn't too difficult. So, I'd recommend you setup your own server first. The Egghead Course, "Build a GraphQL Server" got me started, but it's not free.

从本质上讲,您将设置架构,然后定义如何使用数据进行解析.解决后,您可以设置一个快速服务器来查询数据库,或者可以访问REST接口,或者访问SOAP接口.只要您按照定义的模式返回数据,如何取回数据就由您决定.

In essence, you'll be setting up your schema then defining how to resolve with data. When you resolve, you can setup an express server to query a database, or you can hit a REST interface, or hit your SOAP interface. How you retrieve the data is up to you, so long as you return it in compliance with your defined schema.

希望如此.模拟一个迷你应用程序进行演示是可能的,但是由于我没有方便,这是我能提供的最佳建议.

Hope that makes sense. Mocking up a mini app to demonstrate is possible, but since I don't have one handy, this is the best advice I can offer.

这篇关于用GraphQL替换REST调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆