【问题标题】:How to expose Scalar Types with GraphQL ruby gem如何使用 GraphQL ruby​​ gem 公开标量类型
【发布时间】:2017-09-06 05:41:08
【问题描述】:

我正在创建一个项目来围绕现有 API 实现 GraphQL,并且我正在尝试添加新的标量类型(分别为 idtitle)以围绕我的查询提供结构。

这是我的目标查询架构:

query{
  allPlaylists {
    id 
    title
  }
}

我已阅读 gem 的 documentation regarding Scalar Types,但不清楚我应该在哪里放置新的 ScalarType 定义。

这是我的查询的 sn-p,我的完整仓库也是 saved on GitHub:

// query_type.rb

Types::QueryType = GraphQL::ObjectType.define do
  name "Query"
  # Add root-level fields here.
  # They will be entry points for queries on your schema.

  field :allPlaylists, types.String do
    description "Playlists that belong to the user"
    resolve ->(obj, args, ctx) {
      Playlist.all.map { |x| x }
    }
  end
end

如您所见,我目前只定义了allPlaylists root-level 查询。

尽管文档对此相当不清楚,但我确实计划在我找到解决方案后提交 PR 以帮助澄清这一点。或者,如果有任何工作示例我可以参考,我将非常欢迎。

【问题讨论】:

    标签: ruby graphql


    【解决方案1】:

    根据clarification from the gem contributors 的一些说法,定义对象类型是这项工作的正确工具,而不是缩放器类型

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-28
      • 1970-01-01
      • 2020-08-04
      • 2020-02-09
      • 2021-05-11
      • 2021-05-14
      • 2020-05-16
      相关资源
      最近更新 更多