doushi1912
2016-04-01 21:35
浏览 45

GraphQL和中继的概念

I am trying to build a GraphQL endpoints in golang.

I have been following these blogs Learn Golang + GraphQL + Relay #1 for implementation of graphQl in golang and I have successfully built simple endpoints of GraphQL.

There are few concepts that are still unclear to me as how can I build a pagination endpoints using graphQl, Also methods like

//How to build endpoints for fetching data from this query
friends.first(1){
   cursor,
   node {
      name
   }
}

//or this query
friends.last(1){
   cursor,
   node {
      name
   }
}

Introducing Relay and GraphQL

As, I am from Angular Background this Relay concept are still very confusing to me. How relay works in facilitating the communication between clients and server.

Please provide some example using Node or anything which make these concepts more clear

图片转代码服务由CSDN问答提供 功能建议

我正在尝试在 golang 中构建 GraphQL端点

我一直在关注这些博客学习Golang + GraphQL + Relay#1 golang 中实现 graphQl 的方法,我已经成功构建了 GraphQL

我仍然不清楚一些概念,因为如何使用 graphQl 构建分页端点,

  //如何构建用于从此查询中获取数据的端点的方法
friends.first(1){
光标,
节点{
名称
  } 
} 
 
 //或此查询
friends.last(1){
光标,
节点{
名称
} 
} 
   
  
 

”介绍Relay和GraphQL“

我来自 Angular ,此 Relay 概念是 直到让我非常困惑 中继如何在促进客户端与服务器之间的通信中发挥作用。

请提供一些使用Node的示例或使这些概念更清晰的任何示例

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • donglin7979 2016-04-05 13:27
    已采纳

    Pagination is never an easy question and not one explicitly solved by GraphQL. GraphQL provides a data fetching framework, how that framework is used to do things (like pagination) is up to the developer.

    The Relay team has attempted to standardize pagination with the cursor connection specification for GraphQL. The cursor connection specification is not unique to Relay and can be used with Angular, the main goal of the specification is to provide a standardized way to work with large collections from a GraphQL server. The main thing to note about this specification is that with every object there is an associated cursor. This associated cursor allows the client to resume pagination from any point in the collection.

    If you are interested in implementing the Relay specification I encourage you to read Sashko Stubailo's Understanding pagination: REST, GraphQL, and Relay where he explains the motivation behind the Relay connection specification and explains how to implement it.

    To see the connection specification in action, take a look at the example SWAPI GraphQL API which implements the Relay specification in GraphQL. I encourage you to open the documentation window and browse the PeopleConnection. Note how they implement both edges and people fields.

    If cursor pagination is too complicated for you to use/implement, you could always expose a traditional limit/offset pagination for your GraphQL API. The interface would probably look something like this:

    {
      friends(limit: 5, offset: 20) {
        name
      }
    }
    

    Finally, the query you provided is from a very early technical preview of GraphQL and does not actually conform to the specification (source). A more appropriate query (as mentioned by Hafiz) would be:

    {
      friends(first: 1) {
        cursor
        node {
          name
        }
      }
    }
    

    There are two great talks from React Europe 2015 that I also recommend you watch which talk more about GraphQL without Relay.

    点赞 打赏 评论

相关推荐 更多相似问题