GraphQL Java 需要查询参数

GraphQL Java is expecting query parameter

我正在 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)

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