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

Receive custom variables while uploading a file on server #78

Open
dg92 opened this issue Jun 30, 2020 · 2 comments
Open

Receive custom variables while uploading a file on server #78

dg92 opened this issue Jun 30, 2020 · 2 comments

Comments

@dg92
Copy link

dg92 commented Jun 30, 2020

Is there a way to get variables that are passed other than a file related stuff in the ctx object?

I have a mutation
mutation upload($file: Upload!, $entityId: String!) { uploadFile(file: $file, entityId: $entityId) { publicURL } }

I am passing entityId but when I try to look for it in ctx.params it's just a stream obj and ctx.meta contain file meta. I also need to get entityId. Is there a way to get that?

@shawnmcknight

@dg92 dg92 changed the title Get custom variables while uploading a file Receive custom variables while uploading a file on server Jun 30, 2020
@shawnmcknight
Copy link
Member

The short answer is that this is not supported today. Since passed streams in moleculer must be the entirety of ctx.params, there is no mechanism to pass additional params. The only way to pass additional data is via ctx.meta, which is not ideal due to the built-in merging of meta for all future action calls and lack of validation of meta.

@icebob We've hit this limitation on streams recently ourselves. We did not hit it within our use of moleculer-apollo-server but rather in regular passing of streams between moleculer services. In our scenario the best solution we found was to use meta to pass additional arguments, write a custom hook to validate the meta and use broker.call to initiate the call to avoid merging meta within the moleculer context. This was not ideal.

Do you think it might be reasonable to support another mechanism for passing a stream between services rather than as the entirety of ctx.params and allow for other params to still be passed through?

The only other alternatives I can come up with for this specific problem would be to augment meta further, either putting all additional args into ctx.meta.$args or simply destructuring them all directly into ctx.meta, but neither is ideal for the aforementioned reasons.

@icebob
Copy link
Member

icebob commented Jul 1, 2020

I understand the issue. Currently, there is no better option. To change the stream sending logic, we should change the protocol which is a big breaking change. In the protocol, likewise, the transporter uses the params field to transfer the stream binary data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants