连接基于`array`,这是设计中继服务器的设计风格指南吗? [英] Connection is based on `array`,is this a design style guide for design a relay server?

查看:118
本文介绍了连接基于`array`,这是设计中继服务器的设计风格指南吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

connection/arrayconnection.js中,似乎所有功能都倾向于与array一起使用.
例如:offsetToCursor是生成游标的唯一方法.这是否意味着我必须遵循其设计模式,还是暗示我在使用array以外的其他东西时应该自己生成Cursor.如果我打算使用Mongodb,我应该使数据库接口像静态数组一样吗?

In connection/arrayconnection.js, It seems all the function is tend to work with array.
For example: offsetToCursor is the only way to generate Cursor. Does this mean its a design pattern i must follow, or imply that i should generate Cursor by myself when using something other than array.If im planning to use Mongodb,should i make the database interface like an static array ?

顺便说一句:
作为Web开发的新手,我有点困惑如何实现合格的中继服务器.
是否有一些设计graphql中继服务器的指南,我是否应该一直沿用graphql-relay-js中的哪个方法,Facebook将其与中继服务器一起使用? mysql还是?
我不确定是否在这里问这个问题是否合适,但有关graphql-relay-js的主题很少出现在网络上.
非常感谢,请原谅我的不礼貌.

BTW:
As a newbie to web develop, im a bit confused how to implement a qualified relay server.
Are there some guide for design a graphql-relay server, should i follow all the way in graphql-relay-js, which Database Facebook used with relay-server ? mysql or ?
Im not sure ask this here is appropriate or not,but the topic for graphql-relay-js is rarely on the web.
Thanks a lot, forgive my impolite.

var PREFIX = 'arrayconnection:';
/**
 * Creates the cursor string from an offset.
*/
export function offsetToCursor(offset: number): ConnectionCursor {
    return base64(PREFIX + offset);
}


其他问题:
也许我从developers.facebook.com/docs/graph-api中得到了一些想法.
似乎应该做一个数组样式缓存来进行分页查找(对此不确定). 但是graph-api看起来与graphql-relay-js有点不同(graph-api仍然是旧的宁静风格的一部分吗?),
graph-api和graphql-relay-js之间是什么关系? graphql-relay-js是在Facebook中设计graphql服务器的通用设计指南吗? 非常感谢!请给我一些提示


Additional question:
Maybe i get some idea from developers.facebook.com/docs/graph-api.
Seems should do an array style cache for pagination lookup( not sure about this). But graph-api looks a bit different from graphql-relay-js (is graph-api still some part of old restful style?),
What is the relationship between graph-api and graphql-relay-js ? Is graphql-relay-js a common design guide for design a graphql server in facebook? Thanks a lot! please give me some hints

推荐答案

如果您希望Relay执行有效的分页,则连接是您的模式可以实现的一种设计模式.如何在后端实现它是实现细节.它可能有类似数组的东西支持,也可能没有(例如Facebook上的无限滚动新闻提要,它由一个非常复杂的后端服务进行排名:这显然没有数组支持).我们提供arrayconnection.js模块,以演示如何 如果您的数据源具有类似数组的性质.如果没有,或者不能有效地转换为它,则最好从头开始实施.

Connection is a design pattern that your schema may implement if you want Relay to perform efficient pagination. How it gets implemented on the backend is an implementation detail. It may be backed by something array-like, or it may not (think about something like the infinite scrolling news feed on Facebook, which is ranked by a terribly sophisticated backend service: this is clearly not backed by an array). We provide the arrayconnection.js module as a way of demonstrating how this can be done if your data source has that array-like nature. If it does not, or cannot be efficiently converted to it, you are better off implementing something from scratch.

光标是不透明的标识符.如果您使用的是数组源或典型的数据库后端(例如MySQL),则可以使用数组索引或某种主键,但是同样,细节是特定于实现的,应选择适合您的后端.唯一的要求是,游标应该对服务器上需要的任何信息进行编码,以便能够返回该点之后(或之前)的下一页结果.

Cursors are opaque identifiers. You could use an array index or some kind of primary key if you are using an array source or a typical database backend (like MySQL), but again the details are implementation-specific and should be chosen to suit your back end. The only requirement is that the cursor should encode whatever information you need on the server to be able to return the next page of results after (or before) that point.

graphql-relay-js只是模块的集合,这些模块提供了一些帮助以JavaScript构建与中继兼容的GraphQL模式.模式为数据提供了统一的接口,但是实际的基础存储可以是您要插入数据的任何内容(MySQL数据库,内存中的对象,某些REST服务).对于简单的示例,请在中继存储库中的 examples目录中查看.为了说明如何将架构放在非传统数据库之前,请

graphql-relay-js is just a collection of modules that provide some helpers for building Relay-compatible GraphQL schemas in JavaScript. The schema provides a uniform interface to your data, but the actual underlying storage can be anything you want to plug into it (a MySQL database, an object in memory, some REST service). For simple examples, look in the examples directory in the Relay repo. As an illustration of how you can put a schema in front of something that is not a traditional database, this is an example of a schema that reads its data out of a Git repo, with the help of indices in Redis and cached data in memcached.

远离 developers.facebook.com/docs/graph-api ;尽管名称中带有图形",但这是完全不同的东西,与 GraphQL 层次查询语言无关中继用途.

Stay away from developers.facebook.com/docs/graph-api; despite the "graph" in the name this is an entirely different thing and has nothing to do with the GraphQL hierarchical query language that Relay uses.

这篇关于连接基于`array`,这是设计中继服务器的设计风格指南吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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