【问题标题】:How to create a generic Pagination Connections schema in GraphQL如何在 GraphQL 中创建通用分页连接模式
【发布时间】:2020-10-20 19:45:37
【问题描述】:

GraphQL 相对较新。我有一个关于如何使分页的连接样式在模式中可重用的问题。

例如)如果我有这样的架构

type SomeEdge {
    node: SomeNodeView // This can be different for different use cases.
}

type SomeConnection {
    metaInfo: MetaInfo
    edges: SomeEdge // this can be different for different use cases.
}
// But the overall structure remains the same.

有没有办法在 GraphQL 中处理这个有点通用?

这是迄今为止我在网上搜索时发现的最接近的 (https://github.com/graphql/graphql-spec/issues/190)

我将它与 Typescript 一起使用。

【问题讨论】:

    标签: typescript pagination graphql


    【解决方案1】:

    GraphQL 没有泛型类型——GraphQL 中没有语法支持做你想做的事情。

    如果您使用 SDL 构建架构,则可以使用 string interpolation(假设您使用的是纯字符串而不是 .graphql 文件)或使用像 graphql-s2s 这样的库,它允许您使用非标准语法然后将其编译为标准 SDL。

    或者,您可以使用代码优先库来构建您的架构。大多数,比如 TypeGraphQL,都有support for creating generic types

    【讨论】:

      猜你喜欢
      • 2018-01-18
      • 2020-09-30
      • 2018-01-24
      • 2019-05-25
      • 2016-11-02
      • 2020-07-15
      • 2015-04-08
      • 2017-06-02
      • 2019-04-17
      相关资源
      最近更新 更多