How to query GraphQL SPQR

258 views Asked by At

I've read https://github.com/leangen/graphql-spqr-spring-boot-starter But I'm still a bit confused how to map what's in my code to what I need to query in my GraphQL request.

@Named
@GraphQLApi
public class TradeService {
@GraphQLQuery
    public List<Trade> getTrades() {
        return tradeDao.findAll();
    }

I have the above code. I'm new to GraphQL but I think the query needs to look like this, where getTrades is the name of the method I want to call, and tradeId is the field I want retrieved.

 {
getTrades{
    tradeId
}

}

And my hope would be I'd get back a list of Trades. However, I just get "Query failed to validate". Not sure if the issue is with my code (if I'm missing something to register that method mabye?) or if the graphQL query is wrong

1

There are 1 answers

0
Steve On

@GraphQLQuery(name="getTrades") is what I needed. I think I could have omitted this if I had the -parameters compiler arg set.