Java Graphql返回枚举集合
我想使用Java Graphql返回枚举集合,java,spring-boot,graphql,Java,Spring Boot,Graphql,我想使用graphql返回枚举的所有值。 我有模式: schema { query: Query } type Query { getDataTypes: [DictionaryType] } enum DictionaryType{ RISK SALES_CHANNEL PERSON_TYPE } 我们有普通的java枚举: public enum DictionaryType { RISK, SALES_CHANNEL, PE
graphql
返回枚举的所有值。
我有模式
:
schema {
query: Query
}
type Query {
getDataTypes: [DictionaryType]
}
enum DictionaryType{
RISK
SALES_CHANNEL
PERSON_TYPE
}
我们有普通的java枚举:
public enum DictionaryType {
RISK,
SALES_CHANNEL,
PERSON_TYPE
}
和控制器
配置:
public class DictionaryController {
@Value("classpath:items.graphqls")
private Resource schemaResource;
private GraphQL graphQL;
private final DictionaryService dictionaryService;
@PostConstruct
public void loadSchema() throws IOException {
File schemaFile = schemaResource.getFile();
TypeDefinitionRegistry registry = new SchemaParser().parse(schemaFile);
RuntimeWiring wiring = buildWiring();
GraphQLSchema schema = new SchemaGenerator().makeExecutableSchema(registry, wiring);
graphQL = GraphQL.newGraphQL(schema).build();
}
private RuntimeWiring buildWiring() {
DataFetcher<Set<DictionaryType>> fetcher3 = dataFetchingEnvironment -> {
return dictionaryService.getDictionaryTypes();
};
return RuntimeWiring.newRuntimeWiring().type("Query", typeWriting ->
typeWriting
.dataFetcher("getDataTypes", fetcher3))
.build();
}
@PostMapping("getDataTypes")
public ResponseEntity<Object> getDataTypes(@RequestBody String query) {
ExecutionResult result = graphQL.execute(query);
return new ResponseEntity<Object>(result, HttpStatus.OK);
}
}
我得到“errorType”:“InvalidSyntax”,
作为响应。这是一个无效的查询,因为大括号中没有内容(即
{}
)。您的模式建议查询应该简单得多:
{ getDataTypes }
{getDataTypes}
有效,谢谢。
{ getDataTypes }