'InvalidSyntaxException passing GraphQL query parameters
Trying to implements the code to be able to execute the following graphql query:
query FIND_BY_BATCHID_LIMIT {
findByBatchIdAndLimit(batch_id: 10, limit: 5) {
id
first_name
last_name
}
}
So the following implementation:
query.graphqls
type Query {
findByBatchIdAndLimit(batch_id: Int!, limit: Int!): [RawEntity]
}
Repository and Query
@Repository
public interface RawRepository extends JpaRepository<RawEntity, Integer> {
@Query(value = "SELECT * FROM rawdata where batch_id = :batch_id LIMIT :limit", nativeQuery = true)
List<RawEntity> findByBatchIdAndLimit(Integer batch_id, Integer limit);
}
@Component
public class Query implements GraphQLQueryResolver {
@Autowired
private RawRepository repository;
public List<RawEntity> findByBatchIdAndLimit(Integer batch_id, Integer limit) {
return repository.findByBatchIdAndLimit(batch_id, limit);
}
}
But getting a:
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [graphql.kickstart.tools.SchemaParser]: Factory method 'schemaParser' threw exception; nested exception is graphql.parser.InvalidSyntaxException: Invalid Syntax : offending token '!' at line 46 column 11
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653)
... 139 common frames omitted
Caused by: graphql.parser.InvalidSyntaxException: Invalid Syntax : offending token '!' at line 46 column 11
While the following finder implementation work:
query.graphqls
type Query {
findByLimit(limit: Int!): [RawEntity]
}
Repository and Query
@Repository
public interface RawRepository extends JpaRepository<RawEntity, Integer> {
@Query(value = "SELECT * FROM rawdata LIMIT :limit", nativeQuery = true)
List<RawEntity> findByLimit(Integer limit);
}
@Component
public class Query implements GraphQLQueryResolver {
@Autowired
private RawRepository repository;
public List<RawEntity> findByLimit(Integer limit) {
return repository.findByLimit(limit);
}
}
query FIND_BY_LIMIT {
findByLimit(limit: 5) {
id
first_name
last_name
}
}
So might be the way I'm passing the batch_id, limit params, but googling, sounds the way to pass params.
Any ideas ?
Solution 1:[1]
Solved. The issue came from the Voyager dependency:
pom.xml when the question was raised:
<!-- GraphQL -->
<dependency>
<groupId>com.graphql-java-kickstart</groupId>
<artifactId>graphql-spring-boot-starter</artifactId>
<version>${graphql.version}</version>
</dependency>
<!-- Voyager-->
<dependency>
<groupId>com.graphql-java-kickstart</groupId>
<artifactId>voyager-spring-boot-autoconfigure</artifactId>
<version>${voyager.version}</version>
<scope>runtime</scope>
</dependency>
Working pom:
<!-- GraphQL -->
<dependency>
<groupId>com.graphql-java-kickstart</groupId>
<artifactId>graphql-spring-boot-starter</artifactId>
<version>${graphql.version}</version>
</dependency>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Hey StackExchange |