graphql 有必要吗_为graphql准备好移动开发了吗

graphql 有必要吗

Most web and mobile applications institute client — server communication. Acquired data are used in the app’s internal processes. Nevertheless, you must know that the beginnings were tough and didn’t provide any models of proceedings. Engineers tried to create a standard which would make the manner of communication more legible and easier to implement. Examples of such standards are REST and SOAP. Unfortunately, nothing in the world is perfect. REST is used most frequently being a main player and overtaking slightly older SOAP. However, years of using REST have shown its shortages which arose due to changes in the world of web and mobile applications. Main instigators of those alterations were mobile apps which constitute larger and larger market share.

大多数Web和移动应用程序都会建立客户端-服务器通信。 所获取的数据将在应用程序的内部流程中使用。 但是,您必须知道,起步艰难,没有提供任何诉讼程序模型。 工程师试图创建一个标准,使通信方式更清晰易懂且易于实施。 REST和SOAP是此类标准的示例。 不幸的是,世界上没有什么是完美的。 REST最常被用作主要角色,并取代了稍旧的SOAP。 但是,由于网络和移动应用程序世界的变化,使用REST的多年已经显示出它的不足。 这些改变的主要诱因是构成越来越大市场份额的移动应用程序

进步=新问题 (Progress = new problems)

Mobile devices have become a chief tool for using the internet resources, yet smartphones have limited computing power and memory. Although their efficiency is constantly rising, the level is still much lower than in laptops. Another constraint is the battery that always runs out too soon :). That’s why we want the apps to encumber batteries in the least. After initial analysis, it has been established that a triggering factor can be the amount of uploaded data. We send too much and not use enough of it.

移动设备已成为使用Internet资源的主要工具,而智能手机的计算能力和内存却有限。 尽管它们的效率不断提高,但水平仍然远远低于笔记本电脑。 另一个限制是电池总是会很快用完:)。 这就是为什么我们希望这些应用程序最少消耗电池电量。 经过初步分析,可以确定触发因素可以是上传数据的数量。 我们发送的邮件过多,使用不足。

Somebody had to come up with proper solutions. In 2012 Facebook app had a substantial user flow so the server — client data exchange was extremely large.

必须有人提出适当的解决方案。 2012年,Facebook应用程序拥有大量用户,因此服务器-客户端数据交换量非常大。

Facebook programmers decided to solve the problem by creating a new manner of communication which would limit the amount of sent data.

Facebook程序员决定通过创建一种新的通信方式来解决该问题,该方式将限制发送的数据量。

Appropriable reasons were:

适当的原因是:

  • higher usage of mobile apps

    移动应用程序的使用率更高
  • low power devices

    低功耗设备
  • impaired internet connection which makes it difficult to send larger data files

    互联网连接受损,这使得难以发送较大的数据文件

Technical reasons were:

技术原因是:

  • over-fetching

    过度获取
  • under-fetching

    提取不足
  • alterations generated in API REST

    API REST中生成的更改

GraphQL —新解决方案(GraphQL — new solution)

So, what is this new Facebook tool? Actually, it’s a query language based on a type scheme created with API. Data is presented in the form of a graph — and that’s where the name came from. The solution was published in 2015 as an open source. Today, it’s developed and available in all popular programming environments. As opposed to REST, GraphQL uses one endpoint which provides all the server-side data. Decisions about the number and type of data are transferred to the client-side which means that the app decides what it wants to get from the server in this particular moment.

那么,这个新的Facebook工具是什么? 实际上,这是一种基于使用API​​创建的类型方案的查询语言。 数据以图形的形式呈现-这就是名称的来源。 该解决方案于2015年作为开源发布。 今天,它已经开发并在所有流行的编程环境中可用。 与REST相反,GraphQL使用一个提供所有服务器端数据的端点。 有关数据数量和类型的决策将传输到客户端,这意味着应用程序将决定在此特定时刻从服务器获取什么。

Major REST’s problem is a consistent scheme of acquired data. Example: App displays user’s name, so it downloads data from API. In REST, endpoint response has a consistent number of attributes compatible with the user’s data. In GraphQL, we are able to determine what we need from all the available data reducing the business of the response. In the presented example, what’s downloaded from the server is only the user’s name and nothing else. Using such a solution, programmers don’t have to modify the backend and create a special endpoint to provide only the user’s name.

REST的主要问题是获取数据的一致方案。 示例:应用程序显示用户名,因此它从API下载数据。 在REST中,端点响应具有与用户数据兼容的一致数量的属性。 在GraphQL中,我们能够从所有可用数据中确定我们需要什么,从而减少响应的业务量。 在给出的示例中,从服务器下载的只是用户名,而没有其他内容。 使用这种解决方案,程序员不必修改后端并创建特殊的端点即可仅提供用户名。

Solved technical problems:

解决了技术问题:

  1. Over-fetching

    过度获取

The problem lies in downloading data’s structure which consists of a large number of attributes. We have data that will be used in the application.

问题在于下载包含大量属性的数据结构。 我们有将在应用程序中使用的数据。

  1. Under-fetching

    提取不足

The problem is that downloaded data is insufficient. That’s why we have to send another query to the server and ask for additional data.

问题是下载的数据不足。 这就是为什么我们必须向服务器发送另一个查询并要求其他数据的原因。

In both cases in GraphQL we only download the data we currently need.

在GraphQL中,在这两种情况下,我们仅下载当前需要的数据。

API的变化 (Changes in API)

Created endpoints in REST approach have a defined structure. To download additional data, programmers have to modify existing endpoints or add supplemental ones to fulfill the needs of the client’s layer. Besides, the client’s layer is not resistant to unexpected changes in endpoints which can lead to instability of the app’s operation. This kind of process is an additional burden also for the client’s budget.

REST方法中创建的端点具有定义的结构。 要下载其他数据,程序员必须修改现有端点或添加补充端点,以满足客户层的需求。 此外,客户端的层无法抵抗端点中的意外更改,这可能导致应用程序操作不稳定。 这种过程对于客户的预算也是一个额外的负担。

加起来 (Summing up)

GraphQL approach solves basic problems and is used more and more frequently. Will it substitute the REST approach? Rather not, but it’s a stron alternative showing that some elements can be managed better.

GraphQL方法解决了基本问题,并且越来越多地被使用。 它会替代REST方法吗? 并非如此,但这是一个更可靠的选择,表明可以更好地管理某些元素。

Author: Marcin Starmach, Flutter Developer at Iteo

作者:Iteo的Flutter开发人员Marcin Starmach

翻译自: https://medium.com/@iteo/is-mobile-development-ready-for-graphql-9f5c6cc928a1

graphql 有必要吗

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值