【问题标题】:what would be the correct type for "tools" in EnterpriseInput input?EnterpriseInput 输入中“工具”的正确类型是什么?
【发布时间】:2021-10-22 22:39:06
【问题描述】:
input EnterpriseInput {
    cnpj: String
    name: String
    email: String
    password: String
    tools: Tool
        
}

type Enterprise {
    id: ID!
    cnpj: String!
    name: String!
    email: String!
    password: String!
    tools: [Tool]
    
}

type Tool {
    id: ID!
    name: String!
    brand: String!
    cod: String!
    qnt: Int!
}

type Query {
    enterprises: [Enterprise]
    enterprise( id: ID!): Enterprise
}

type Mutation {
    createEnterprise( input: EnterpriseInput!): Enterprise!
    # updateEnterprise( id: ID!, input: EnterpriseInput!): Enterprise!
    deleteEnterprise( id: ID!): Boolean,

}

控制台上的错误消息:

C:\Users\Elias\code\web\backEnd-gestordeferramentas\node_modules\graphql\type\validate.js:69
抛出新错误(errors.map(函数(错误){
^
错误:EnterpriseInput.tools 的类型必须是 Input Type 但得到:Tool.
在 assertValidSchema (C:\Users\Elias\code\web\backEnd-...

【问题讨论】:

    标签: api types graphql schema apollo


    【解决方案1】:

    在突变中,您不能使用标准的 Object 类型,而必须使用 Input 类型。在输入类型中你必须使用输入类型

    所以不是

    input EnterpriseInput {
    cnpj: String
    name: String
    email: String
    password: String
    tools: Tool      
    }
    

    试试这个

    input ToolInput {
       id: ID!
       name: String!
       brand: String!
       cod: String!
       qnt: Int!
    }
    
    input EnterpriseInput {
      cnpj: String
      name: String
      email: String
      password: String
      tools: ToolInput    
    }
    

    【讨论】:

      猜你喜欢
      • 2022-10-24
      • 2018-07-10
      • 2020-05-22
      • 1970-01-01
      • 1970-01-01
      • 2017-12-19
      • 1970-01-01
      • 2020-01-04
      • 1970-01-01
      相关资源
      最近更新 更多