graphql - 使用 graphql API 时出现无效的语法错误
问题描述
通过邮递员访问 Graphql API 时,我也遇到了一些问题。
http://testEnvrironment/restcall/getReports
帖子正文
getReports(id:15){
isApproved
}
}
sample.graphqls 文件的条目是
schema{
query: Query
}
type Query{
getReports(id: Long): PublishedReportInternal
}
type PublishedReportInternal{
sourceReport:ObjectRef
isApproved:Boolean
ignoreOutputFormatId:Boolean
}
type ObjectRef{
id : Long
qualifier : String
}
@Override
public ResponseEntity<Object> getReports(String query) {
ExecutionResult execute = graphQLService.getGraphQL().execute(query);
System.out.println("query::"+query);
System.out.println("execute result...."+execute);
return new ResponseEntity<>(execute, HttpStatus.OK);
}
@Service
public class CustomDataFetcher implements DataFetcher<PublishedReportInternal> {
@Inject
PublishRunReportInternalRestService service;
@Override
public PublishedReportInternal get(DataFetchingEnvironment environment) {
System.out.println("Entered into DataFetcher class...");
String reportId=environment.getArgument("id");
System.out.println("reportId is ::"+reportId);
if(!StringUtils.isEmpty(reportId)) {
return service.getReportById(new Long(reportId));
}
else {
return null;
}
}
}
下面是 GraphQLService 的实现
@Service
public class GraphQLService {
@Value("classpath:sample.graphqls")
private Resource schemaResource;
private GraphQL graphQL;
@Inject
private CustomDataFetcher customDataFetcher;
@PostConstruct
private void loadSchema() throws IOException {
// get the schema
File schemaFile = schemaResource.getFile();
System.out.println(schemaFile.getAbsolutePath());
// parse schema
TypeDefinitionRegistry typeRegistry = new SchemaParser().parse(schemaFile);
RuntimeWiring wiring = buildRuntimeWiring();
GraphQLSchema schema = new SchemaGenerator().makeExecutableSchema(typeRegistry, wiring);
graphQL = GraphQL.newGraphQL(schema).build();
}
private RuntimeWiring buildRuntimeWiring() {
return RuntimeWiring.newRuntimeWiring().type("Query", typeWiring -> typeWiring
.dataFetcher("getReports", customDataFetcher)).build();
}
public GraphQL getGraphQL() {
return graphQL;
}
}
休息端点将是
@POST
@Path(value = "/getReports")
@Consumes
(value = MediaType.APPLICATION_JSON)
@Produces
(value = MediaType.APPLICATION_JSON) ResponseEntity<Object> getReports( String query);
请尝试在这里提供帮助,因为我完全被这个问题所困扰。
我已将以下 jar 用于此 POC
compile files('libs/new/graphiql-spring-boot-starter-5.0.2.jar')
compile files('libs/new/graphql-java-9.2.jar')
compile files('libs/new/graphql-java-servlet-6.1.2.jar')
compile files('libs/new/graphql-java-tools-5.2.4.jar')
compile files('libs/new/graphql-spring-boot-autoconfigure-5.0.2.jar')
compile files('libs/new/graphql-spring-boot-starter-5.0.2.jar')
compile files('libs/new/java-dataloader-2.0.2.jar')
compile files('libs/new/antlr4-runtime-4.7.1.jar')
compile files('libs/new/reactive-streams-1.0.3.jar')
上面的代码片段包含我用来执行此 POC 的所有信息,但在执行此 POC 时,我一直收到“无效语法”错误。请帮助解决此问题。
问候库沙格拉
解决方案
推荐阅读
- android - Windows 上的 adb 别名屏幕截图,Git bash 不起作用
- java - 如何管理 Flyway 的变化发展?
- binary-search-tree - 我想在以下二叉搜索树中找到总和为 12 的所有对
- visual-studio-2019 - Visual Studio 2019 中缺少“在 Microsoft Excel 中打开选择”选项
- php - 使用 Laravel 进行递归更新
- python - 在主窗口工具栏中嵌入带有自定义导航工具栏操作的 matplotlib
- linux - 尝试安装 LMMS 但收到错误“无法获取某些档案,可能运行 apt-get update 或尝试使用 --fix-missing?”
- azure - 使用多个存储帐户配置 Azure SFTP 网关
- c# - 报表设计器如何从左到右将记录“溢出”到第二行
- spring-boot - 套接字保持活动属性