[英]InvalidSyntaxException passing GraphQL query parameters
Trying to implements the code to be able to execute the following graphql query:尝试实现能够执行以下 graphql 查询的代码:
query FIND_BY_BATCHID_LIMIT {
findByBatchIdAndLimit(batch_id: 10, limit: 5) {
id
first_name
last_name
}
}
So the following implementation:所以下面的实现:
query.graphqls查询.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查询.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.所以可能是我传递 batch_id、限制参数的方式,但谷歌搜索听起来是传递参数的方式。
Any ideas?有任何想法吗?
Solved.解决了。 The issue came from the Voyager dependency:
问题来自 Voyager 依赖项:
pom.xml when the question was raised: pom.xml 提出问题时:
<!-- 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:工作pom:
<!-- GraphQL -->
<dependency>
<groupId>com.graphql-java-kickstart</groupId>
<artifactId>graphql-spring-boot-starter</artifactId>
<version>${graphql.version}</version>
</dependency>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.