Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for GraphQL multipart request #12

Open
srekapalli opened this issue Jul 29, 2019 · 9 comments
Open

Add support for GraphQL multipart request #12

srekapalli opened this issue Jul 29, 2019 · 9 comments
Assignees
Labels
status: future consideration The issue will be considered at a future date type: enhancement New feature or request

Comments

@srekapalli
Copy link

Trying to make GraphQL multipart request work as per this specification https://github.com/jaydenseric/graphql-multipart-request-spec , but receiving error when I send a multipart request. Is Multipart request supported now in Micronaut/GraphQL extension ?

Error:
/string - Failed to convert argument [string] for value [null] due to: Cannot deserialize instance of java.lang.String out of START_OBJECT token
at [Source: UNKNOWN; line: -1, column: -1]] using codec: io.micronaut.jackson.codec.JsonMediaTypeCodec@439d545c

---- Logs ----

21:52:10.675 [nioEventLoopGroup-1-8] DEBUG i.m.h.s.netty.RoutingInBoundHandler - Matching route POST - /graphql
21:52:10.675 [nioEventLoopGroup-1-8] DEBUG i.m.h.s.netty.RoutingInBoundHandler - Matched route POST - /graphql to controller class io.micronaut.configuration.graphql.GraphQLController
21:52:10.676 [nioEventLoopGroup-1-8] DEBUG i.m.context.DefaultBeanContext - Resolved existing bean [io.micronaut.http.server.netty.FormDataHttpContentSubscriberFactory@5eeaaf88] for type [interface io.micronaut.http.server.netty.HttpContentSubscriberFactory] and qualifier [Content-Type: multipart/form-data;boundary=------------------------e67f840163e3fadc]
21:52:10.678 [nioEventLoopGroup-1-8] DEBUG i.m.c.beans.DefaultBeanIntrospector - No BeanIntrospection found for bean type: class java.lang.String
21:52:10.678 [nioEventLoopGroup-1-8] DEBUG io.micronaut.core.reflect.ClassUtils - Cannot instantiate type [class java.lang.String] without reflection. Attempting reflective instantiation
21:52:10.678 [nioEventLoopGroup-1-8] DEBUG i.m.context.DefaultBeanContext - Resolved existing bean [io.micronaut.jackson.bind.JacksonBeanPropertyBinder@69626e28] for type [interface io.micronaut.core.bind.BeanPropertyBinder] and qualifier [null]
21:52:10.678 [nioEventLoopGroup-1-8] DEBUG i.m.context.DefaultBeanContext - Registering singleton bean io.micronaut.http.server.exceptions.ConversionErrorHandler@246a6496 for type [<ConversionErrorException,Object> io.micronaut.http.server.exceptions.ExceptionHandler] using bean key <ConversionErrorException,Object> io.micronaut.http.server.exceptions.ConversionErrorHandler
21:52:10.678 [nioEventLoopGroup-1-8] DEBUG i.m.context.DefaultBeanContext - Registering singleton bean io.micronaut.http.server.exceptions.ConversionErrorHandler@246a6496 for type [<ConversionErrorException,Object> io.micronaut.http.server.exceptions.ExceptionHandler] using bean key <ConversionErrorException,Object> io.micronaut.http.server.exceptions.ConversionErrorHandler
21:52:10.679 [nioEventLoopGroup-1-8] DEBUG i.m.context.DefaultBeanContext - Registering singleton bean io.micronaut.http.server.exceptions.ConversionErrorHandler@246a6496 for type [<ConversionErrorException,Object> io.micronaut.http.server.exceptions.ExceptionHandler] using bean key <ConversionErrorException,Object> io.micronaut.http.server.exceptions.ConversionErrorHandler
21:52:10.679 [nioEventLoopGroup-1-8] DEBUG i.m.context.DefaultBeanContext - Resolved existing bean [io.micronaut.http.server.exceptions.ConversionErrorHandler@246a6496] for type [interface io.micronaut.http.server.exceptions.ExceptionHandler] and qualifier [<ConversionErrorException,Object>]
21:52:10.679 [nioEventLoopGroup-1-8] DEBUG i.m.h.s.netty.RoutingInBoundHandler - Encoding emitted response object [ /string - Failed to convert argument [string] for value [null] due to: Cannot deserialize instance of `java.lang.String` out of START_OBJECT token
 at [Source: UNKNOWN; line: -1, column: -1]] using codec: io.micronaut.jackson.codec.JsonMediaTypeCodec@439d545c
@marceloverdijk
Copy link
Collaborator

Hi @srekapalli, multipart requests are indeed not (yet) supported.
Currently only the Serving over HTTP specs are implemented.

I will look into this and consider supporting the multipart spec. Do you know if other graphql implementations implement this https://github.com/jaydenseric/graphql-multipart-request-spec spec?

@sflahave
Copy link

@marceloverdijk - It looks like GraphQL-Java-Kickstart added support for that spec:
graphql-java-kickstart/graphql-java-servlet#102

@marceloverdijk
Copy link
Collaborator

Correct graphql-java-kickstart/graphql-java-servlet does indeed support it. I was wondering if other implementations like graphqljs or the express module also support it or not, to see if that spec is widely adopted.

@marceloverdijk marceloverdijk added this to the 1.2.0 milestone Jul 29, 2019
@marceloverdijk
Copy link
Collaborator

After initial investigation Micronaut currently does not support retrieving the parts of multipart request. At least not in the sense needed to implement the https://github.com/jaydenseric/graphql-multipart-request-spec.

Micronaut does support retrieving parts, but only if the part names are known upfront, which we don't know for https://github.com/jaydenseric/graphql-multipart-request-spec.

micronaut-projects/micronaut-core#1957 is created to provide a way to retrieve the parts. Until then https://github.com/jaydenseric/graphql-multipart-request-spec cannot be implemented unfortunately.

@marceloverdijk marceloverdijk removed this from the 1.2.0 milestone Jul 30, 2019
@marceloverdijk marceloverdijk added this to the 1.3.0 milestone Aug 2, 2019
@marceloverdijk
Copy link
Collaborator

Support for retrieving multiparts is scheduled for Micronaut Core 1.3.0 (see micronaut-projects/micronaut-core#1957). We have to wait for that before we can implement https://github.com/jaydenseric/graphql-multipart-request-spec in micronaut-graphql.

@marceloverdijk
Copy link
Collaborator

Support for retrieving multiparts is now added to Micronaut Core and will be part of Micronaut 1.3.0.

However, there is another Micronaut Core issue pending to implement this feature in Micronaut GraphqL: micronaut-projects/micronaut-core#1971 as we currently cannot distinguish the routes.

@marceloverdijk
Copy link
Collaborator

Note micronaut-projects/micronaut-core#1971 has been released as part of Micronaut Core 1.2.1.
As soon as we get closer to a Micronaut Core 1.3.0 release I will start implementing the multipart support in the Micronaut GraphQL module as all building blocks are available now.

@marceloverdijk marceloverdijk changed the title Support for GraphQL multipart request Add support for GraphQL multipart request Sep 19, 2019
@marceloverdijk marceloverdijk removed this from the 1.3.0 milestone Jan 17, 2020
@marceloverdijk
Copy link
Collaborator

Putting this on hold to consider whether to add non-official GraphQL spec related functionality or not.

@ilopmar ilopmar added status: future consideration The issue will be considered at a future date type: enhancement New feature or request labels Jul 13, 2020
@artipop
Copy link

artipop commented May 12, 2023

Hi there!
For those looking for a solution, a very basic implementation of the spec can be found here - https://gist.github.com/artipop/725c9a574c3cf0dc7b66e2061c5f4eca.
You can add an Upload scalar to the RuntimeWiring:

RuntimeWiring runtimeWiring = RuntimeWiring.newRuntimeWiring()
        .scalar(CompletedFileUploadScalar.UPLOAD_SCALAR)
        ...
        .build();

and then get CompletedFileUpload in your DataFetcher like this:

CompletedFileUpload file = environment.getArgument("file");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: future consideration The issue will be considered at a future date type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants