【问题标题】:Graphql input type of array of objects [duplicate]对象数组的Graphql输入类型[重复]
【发布时间】:2019-07-09 17:52:57
【问题描述】:

我有这个架构:

type Preference{
    _id: ID!
    uID: ID!
    preferences: [Category!]!
}

type Category{
    name: String!
    subcategories: [String]!
}

type RootMutation{
    createPreference(perferenceInput: PerferenceInput) : Preference
}

input PerferenceInput{
    uID: String!
    preferences: [Category!]!
}

schema {    
    query: RootQuery
    mutation: RootMutation
}

type RootQuery {
    preferences: [Preference!]!
    category: [Category!]!
}

但是 Graphql 给了我一个错误,指出:message": "The type of PerferenceInput.preferences must be Input Type but got: [Category].", 我追溯到与 graphql 无法解析 [Category] 数组有关。

我需要将此数组作为 Preference 对象内的嵌套数组,但不知何故,graphql 无法解析它。那么,如何将 Category 数组作为输入类型传递?

【问题讨论】:

  • 这个问题被问了很多。您不能使用需要输入对象类型的对象类型(即作为参数)。更详细的解释可以找到here

标签: javascript node.js express graphql express-graphql


【解决方案1】:

这是众所周知的 GraphQL 限制。

您不能使用常规 GraphQLObjectTypes 作为 GraphQLInputObjectType 字段的类型 - 您必须使用另一个 GraphQLInputObjectType

您不能在架构中混合输入和输出类型。输入和输出类型有不同的类型范围。

【讨论】:

    猜你喜欢
    • 2018-09-19
    • 2018-08-15
    • 2019-10-14
    • 2019-10-15
    • 2012-08-29
    • 2019-02-26
    • 1970-01-01
    • 2020-03-02
    • 2020-09-30
    相关资源
    最近更新 更多