【问题标题】:Spring Boot GraphQL: Expected type to be a GraphQLInputType, but it wasn'tSpring Boot GraphQL:预期类型是 GraphQLInputType,但它不是
【发布时间】:2022-03-30 11:15:57
【问题描述】:

我正在尝试在 Spring Boot 中设置 GraphQL 端点,当我尝试运行我的应用程序时,我收到以下错误:

Expected type 'Order' to be a GraphQLInputType, but it wasn't! Was a type only permitted for object types incorrectly used as an input type, or vice-versa?

这是我的models.graphqls:

type Order {
    id: String!
    storeOrderId: String
    connectionId: String
}

type Mutation {
    createOrder(order: Order): Order
}

【问题讨论】:

    标签: spring spring-boot graphql graphql-java


    【解决方案1】:

    发生这种情况是因为您尝试使用 type 进行输入,这是不允许的。

    type Order {

    应该是……

    input Order {

    所以整个事情看起来像:

    我正在尝试在 Spring Boot 中设置 GraphQL 端点,当我尝试运行我的应用程序时,我收到以下错误:

    Expected type 'Order' to be a GraphQLInputType, but it wasn't! Was a type only permitted for object types incorrectly used as an input type, or vice-versa?

    这是我的models.graphqls:

    input Order {
        id: String!
        storeOrderId: String
        connectionId: String
    }
    
    type Mutation {
        createOrder(order: Order): Order
    }
    
    

    【讨论】:

      【解决方案2】:

      如果使用input类型后还是不行,这里可能还有其他问题。

      • 输入的 java 类型应该有公共的 getter,
      • 输入的java类型也应该实现Serializable接口

      【讨论】:

        猜你喜欢
        • 2021-01-10
        • 2018-10-02
        • 2018-11-27
        • 2015-04-24
        • 2019-08-14
        • 2018-04-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多