0

Graphql SPQR 到目前为止运行良好,但在下载/上传文件时,文档不多。有人可以告诉我他/她是否已经使用 SPQR 实现了下载或上传文件。我曾尝试写下我的 GraphqlController,但大多数时候都会出现此错误:

The type of member "EMPTY" belonging to org.springframework.http.ResponseEntity<org.springframework.core.io.Resource> is missing generic type parameters and can not be mapped. For details and possible solutions see https://github.com/leangen/graphql-spqr/wiki/Errors#ambiguous-member-type

pom.xml 依赖

<dependency>
        <groupId>com.graphql-java</groupId>
        <artifactId>graphiql-spring-boot-starter</artifactId>
        <version>4.0.0</version>
    </dependency>
    <dependency>
        <groupId>io.leangen.graphql</groupId>
        <artifactId>spqr</artifactId>
        <version>0.11.2</version>
    </dependency>

    <dependency>
        <groupId>com.graphql-java-kickstart</groupId>
        <artifactId>graphql-java-tools</artifactId>
        <version>5.6.0</version>
    </dependency>

Graphql控制器

@RestController
public class GraphqlController {
private final GraphQL graphQL;

@Autowired
public GraphqlController(QueryResolver queryResolver, MutationResolver mutationResolver) {
    GraphQLSchema schema = new GraphQLSchemaGenerator().withResolverBuilders(
            // Resolve by annotations
            new AnnotatedResolverBuilder(),
            // Resolve public methods inside root package
            new PublicResolverBuilder("com.example"))

            .withOperationsFromSingleton(queryResolver, QueryResolver.class)
            .withOperationsFromSingleton(mutationResolver, MutationResolver.class)
            // using TypeToken

            .withOperationBuilder(new DefaultOperationBuilder(DefaultOperationBuilder.TypeInference.LIMITED))
            .withValueMapperFactory(new JacksonValueMapperFactory()).generate();

    graphQL = GraphQL.newGraphQL(schema).build();
}

@PostMapping(value = "/graphql", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public Map<String,Object> execute(@RequestBody Map<String, String> request, HttpServletRequest raw) throws GraphQLException {

    ExecutionResult executionResult = graphQL.execute(ExecutionInput.newExecutionInput().query(request.get("query"))
            .operationName(request.get("operationName")).context(raw).build());
    return executionResult.toSpecification();

}

}

查询解析器

@Override
@GraphQLQuery(name = "downloadFile")
public ResponseEntity<Resource> download(ResolutionEnvironment env) throws Exception {
    // This method could not register
    return null;
}
4

0 回答 0