我有查询类型
Types::QueryType = GraphQL::ObjectType.define do
name 'Query'
field :allProjects, function: Resolvers::Projects
end
Run Code Online (Sandbox Code Playgroud)
像这样的解析器
require 'search_object/plugin/graphql'
module Resolvers
class Projects
include SearchObject.module(:graphql)
type !types[Types::ProjectType]
scope { Project.all }
ProjectFilter = GraphQL::InputObjectType.define do
name 'ProjectFilter'
argument :OR, -> { types[ProjectFilter] }
argument :description_contains, types.String
argument :title_contains, types.String
end
option :filter, type: ProjectFilter, with: :apply_filter
option :first, type: types.Int, with: :apply_first
option :skip, type: types.Int, with: :apply_skip
def apply_first(scope, value)
scope.limit(value)
end
def apply_skip(scope, value)
scope.offset(value)
end
def apply_filter(scope, value)
branches = normalize_filters(value).reduce …Run Code Online (Sandbox Code Playgroud) 我想创建一个不在 ActiveRecord 中的 MentionType。当查询 SummaryCommentType 时,我想返回 MentionType 。但我不知道该怎么做。
我对 graphql 完全陌生。对不起我的英语不好。
这是我的代码
module Types
class MentionType < Types::BaseObject
field :id, Integer, null: false
field :name, String, null: false
end
end
module Types
class SummaryCommentType < Types::BaseObject
field :id, Integer, null: false
field :summary_id, Integer, null: false
field :comment_status, Integer, null: false
field :curator_id, Integer, null: true
field :curator, CuratorType, null: true
field :total_like, Integer, null: true
field :total_dislike, Integer, null: true
field :comment_desc, String, null: true
field :parent_comment_key, Integer, null: …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 ActionCable 和graphql-rubygem 来实现 GraphQL 订阅。
我从这个链接中发现,需要创建客户端需要订阅的 GraphQL 通道。通常,在ActionCable中,我们会在动作stream_from中需要通道subscribed。但是,链接中的示例指定了execute带参数的方法。这个方法什么时候会被执行呢?
此外,该文档还说明了See Apollo Client or Relay Modern客户端的使用情况。是否必须使用其中任何一种,或者我可以使用 CoffeeScript 来订阅和更新 UI 吗?
ruby ruby-on-rails graphql graphql-subscriptions graphql-ruby
是否有可能在 graphql-ruby 模式中将 Hash 定义为 Type 字段?在我的数据结构中有一个多语言字符串类型,它由作为键的语言代码和相应的文本组成。目前提供了 2 种语言,例如:
{
"en" : "hello",
"de" : "hallo"
}
Run Code Online (Sandbox Code Playgroud)
所以构建这样的类型就足够了:
{
"en" : "hello",
"de" : "hallo"
}
Run Code Online (Sandbox Code Playgroud)
提供字符串到字符串映射的类型如何?例如,相应的打字稿界面如下所示:
title: {
[language: string]: string;
}
Run Code Online (Sandbox Code Playgroud)
更进一步,就像一个递归节点:
export interface NodeDescription {
name: string
children?: {
[childrenCategory: string]: NodeDescription[];
}
}
Run Code Online (Sandbox Code Playgroud)
有没有办法在一个字段中使用它作为 graphql-ruby 模式中的 Types::NodeDescriptionType ?
我正在构建一个 GraphQL API。返回联合/接口类型字段时,是否可以让服务器告诉我对象类型?即像这样的东西
{
search(text: "an") {
... on Human {
__type
name
height
}
... on Droid {
__type
name
primaryFunction
}
... on Starship {
name
length
}
}
}
// or even better
{
search(text: "an") {
__type // <--- even though it's a Union query, everything has a type right? :/
... on Human {
name
height
}
... on Droid {
name
primaryFunction
}
... on Starship {
name
length
}
}
}
Run Code Online (Sandbox Code Playgroud)
哪个会返回
{ …Run Code Online (Sandbox Code Playgroud)