【问题标题】:GraphQL Java is expecting query parameterGraphQL Java 期待查询参数
【发布时间】:2021-05-13 13:50:11
【问题描述】:

我正在使用以下库在 Spring Boot 中实现基本的 GraphQL 应用程序。

    <dependency>
        <groupId>com.graphql-java-kickstart</groupId>
        <artifactId>graphql-spring-boot-starter</artifactId>
        <version>7.1.0</version>
    </dependency>

我的 graphqls 文件如下所示。

# The Root Query for the application
type Query {
    bankAccount(id:String!): BankAccount!
}

type BankAccount{
    id: String!
    name :String!
    currency : Currency!
}

enum Currency{
    TRY,
    AUD
}

我创建了 BankAccountResolver


@Component
public class BankAccountResolver implements GraphQLQueryResolver {

    public BankAccount bankAccount(String id) {
        return BankAccount.builder().currency(Currency.TRY).name("My Account").id(id).build();
    }

}

当我这样要求邮递员时。获取错误请求异常

我检查了服务器日志,并且请求正在尝试解析查询参数,这对 graphql 应用程序没有意义。感谢任何帮助。

210209 21:07:23.456 ERROR  [{}] [nio-8071-exec-1] g.k.s.AbstractGraphQLHttpServlet         : Error executing GraphQL request!
graphql.GraphQLException: Query parameter not found in GET request
    at graphql.kickstart.servlet.GraphQLGetInvocationInputParser.getGraphQLInvocationInput(GraphQLGetInvocationInputParser.java:35)
    at graphql.kickstart.servlet.HttpRequestHandlerImpl.handle(HttpRequestHandlerImpl.java:36)
    at graphql.kickstart.servlet.AbstractGraphQLHttpServlet.doRequest(AbstractGraphQLHttpServlet.java:148)
    at graphql.kickstart.servlet.AbstractGraphQLHttpServlet.doRequestAsync(AbstractGraphQLHttpServlet.java:138)
    at graphql.kickstart.servlet.AbstractGraphQLHttpServlet.doGet(AbstractGraphQLHttpServlet.java:164)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:645)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:750)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

【问题讨论】:

    标签: java spring-boot graphql-java


    【解决方案1】:

    我找到了原因。我正在发送 GET 请求,因为它是一种查询类型。但实际上我应该发送 POST 请求,如下所示

    【讨论】:

      猜你喜欢
      • 2020-09-09
      • 2021-01-14
      • 2021-02-02
      • 2021-04-03
      • 1970-01-01
      • 2017-09-27
      • 2017-11-14
      • 1970-01-01
      • 2023-01-26
      相关资源
      最近更新 更多