我正在使用graphql-spqr-spring-boot-starter(https://github.com/leangen/graphql-spqr-spring-boot-starter)将GraphQL添加到项目中,并且需要添加文件上传。 graphql-spring-boot upload binary看起来很有希望,但最终没有奏效。任何帮助将不胜感激。
我能说的最好的是处理多部分表单数据时出现问题。
这就是我要发送到服务器的内容。
标题:
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: http://localhost:3000/
Content-Type: multipart/form-data; boundary=---------------------------17929897828310
Origin: http://localhost:3000
Content-Length: 591
Connection: keep-alive
身体:
-----------------------------17929897828310
Content-Disposition: form-data; name="operations"
{"operationName":null,"variables":{"file":null},"query":"mutation ($file: Upload!) {\n singleUpload(file: $file) {\n id\n filename\n mimetype\n path\n __typename\n }\n}\n"}
-----------------------------17929897828310
Content-Disposition: form-data; name="map"
{"1":["variables.file"]}
-----------------------------17929897828310
Content-Disposition: form-data; name="1"; filename="xx.txt"
Content-Type: text/plain
xx
-----------------------------17929897828310--
我可以看到graphql.GraphQL parseAndValidate引发异常,因为executionInput.getQuery()返回空值。
private PreparsedDocumentEntry parseAndValidate(ExecutionInput executionInput, GraphQLSchema graphQLSchema, InstrumentationState instrumentationState) {
log.debug("Parsing query: '{}'...", executionInput.getQuery());
GraphQL.ParseResult parseResult = this.parse(executionInput, graphQLSchema, instrumentationState);
java.lang.NullPointerException: null
at org.antlr.v4.runtime.CharStreams.fromString(CharStreams.java:222) ~[antlr4-runtime-4.7.2.jar:4.7.2]
at org.antlr.v4.runtime.CharStreams.fromString(CharStreams.java:212) ~[antlr4-runtime-4.7.2.jar:4.7.2]
at graphql.parser.Parser.parseDocument(Parser.java:28) ~[graphql-java-11.0.jar:?]
at graphql.parser.Parser.parseDocument(Parser.java:21) ~[graphql-java-11.0.jar:?]
at graphql.GraphQL.parse(GraphQL.java:544) ~[graphql-java-11.0.jar:?]
at graphql.GraphQL.parseAndValidate(GraphQL.java:520) ~[graphql-java-11.0.jar:?]
at graphql.GraphQL.lambda$parseValidateAndExecute$4(GraphQL.java:509) ~[graphql-java-11.0.jar:?]
at graphql.execution.preparsed.NoOpPreparsedDocumentProvider.get(NoOpPreparsedDocumentProvider.java:11) ~[graphql-java-11.0.jar:?]
at graphql.GraphQL.parseValidateAndExecute(GraphQL.java:505) ~[graphql-java-11.0.jar:?]
at graphql.GraphQL.executeAsync(GraphQL.java:489) ~[graphql-java-11.0.jar:?]
at graphql.GraphQL.execute(GraphQL.java:420) ~[graphql-java-11.0.jar:?]
at io.leangen.graphql.spqr.spring.web.servlet.DefaultGraphQLExecutor.execute(DefaultGraphQLExecutor.java:23) ~[graphql-spqr-spring-boot-autoconfigure-0.0.4.jar:?]
at io.leangen.graphql.spqr.spring.web.servlet.DefaultGraphQLExecutor.execute(DefaultGraphQLExecutor.java:11) ~[graphql-spqr-spring-boot-autoconfigure-0.0.4.jar:?]
at io.leangen.graphql.spqr.spring.web.GraphQLController.executeGet(GraphQLController.java:84) ~[graphql-spqr-spring-boot-autoconfigure-0.0.4.jar:?]