Reputation: 11
I am trying to download an excel file with the API written in GraphQL springboot. I am able to create the excel file from the database. Now , I want to return it to the user when the user hits the API. I want to download it and not save it.
Below is my resolver code -
@QueryMapping(DOWNLOAD_EXCEL) public ResponseEntity downloadExcel (@Argument ("type") FileType type , @Argument ("input") ERequest request){ String fileName= "data.xlsx"; ByteArrayInputStream exelData = service.downloadExcel(type, request); InputStreamResource file= new InputStreamResource(exelData); ResponseEntity body= ResponseEntity.ok() .header(HttpHeaders.CONTENT_DISPOSITION,"attachment; filename = " +fileName) .contentType(MediaType.parseMediaType("application/vnd.ms-excel")).body(file); return body; }
Below is my graphql.schema
DownloadExcel(type: FileType, input: Request): BinaryData @auth(permissions:"DtvServices:Read")
scalar BinaryData
I have also implemented scalar BinaryData
Below is my GraphQLConfiguration
@Bean public GraphQL getGraphQL(CommonConfiguration config) { InputStream schemaStream = getClass().getClassLoader().getResourceAsStream("schema.graphqls"); TypeDefinitionRegistry typeRegistry = new SchemaParser().parse(Objects.requireNonNull(Utility.getFile(config.getGraphQlSchemaConfig()))); var wiring = buildRuntimeWiring(); GraphQLSchema schema = new SchemaGenerator().makeExecutableSchema(typeRegistry, wiring); return GraphQL.newGraphQL(schema).build(); }
private RuntimeWiring buildRuntimeWiring() {
return RuntimeWiring.newRuntimeWiring()
.directive(SECURED_DIRECTIVE, new AuthDirectiveWiring(permissionConfiguration))
.scalar(GraphQLScalarType.newScalar().name("BinaryData").coercing(new BinaryDataCoercing()).build())
.build();
}
It still gives me the error errors=[There is no scalar implementation for the named 'BinaryData' scalar type]
Any help on this would be highly valuable. I am stuck on this for a week now.
Thanks
Upvotes: 1
Views: 143