luckystones
luckystones

Reputation: 371

GraphQL Java is expecting query parameter

I am implementing basic GraphQL application in Spring Boot by using following library.

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

my graphqls file looks like this.

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

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

enum Currency{
    TRY,
    AUD
}

And I created BankAccountResolver


@Component
public class BankAccountResolver implements GraphQLQueryResolver {

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

}

When I requested in postman like this. Getting Bad Request Exception

enter image description here

I checked server logs and request is being tried to parse query parameter which doesn't make sense for graphql application. Any help is appreciated thanks.

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)

Upvotes: 2

Views: 4099

Answers (1)

luckystones
luckystones

Reputation: 371

I found the reason. I was sending GET request since its a query type. But actually i was supposed to send POST request as shown below enter image description here

Upvotes: 6

Related Questions