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

Extension to bring back file upload support #638

Open
jasonkuhrt opened this issue Jan 1, 2024 · 7 comments
Open

Extension to bring back file upload support #638

jasonkuhrt opened this issue Jan 1, 2024 · 7 comments

Comments

@jasonkuhrt
Copy link
Owner

Perceived Problem

Loss of file upload support #400

Ideas / Proposed Solution(s)

  • need an extension system (tbd)
@jasonkuhrt
Copy link
Owner Author

Can someone please share the requirements for file uploads at runtime? I've never done it myself.

@ThallesP
Copy link

Can someone please share the requirements for file uploads at runtime? I've never done it myself.

hi, wdym by requirements? dependencies?

@jasonkuhrt
Copy link
Owner Author

jasonkuhrt commented May 17, 2024

Hey, I mean what does the implementation of file uploads need to do. Knowing details about that will help drive the extension design, because we'll know what kinds of knobs and levers need to be exposed.

@onionhammer
Copy link

onionhammer commented May 17, 2024

For one thing, you have to change the type of request that's made from normal JSON data to multipart/form-data, you need to replace files in the payload with a reference to the file, etc, which means recursively searching the body for files.

It's not that hard, just fiddly to get everything 100%. See this code for reference:

https://github.com/lynxtaa/awesome-graphql-client/blob/a3ecec2fdd3b72b005268a24b2364dd647dc6efd/packages/awesome-graphql-client/src/AwesomeGraphQLClient.ts#L83

Written by @lynxtaa

which uses https://www.npmjs.com/package/extract-files

Spec: https://github.com/jaydenseric/graphql-multipart-request-spec

@jasonkuhrt
Copy link
Owner Author

Thanks, I'll check those links out when the time comes.

you need to replace files in the payload

what would "payload" be and what would "files in payload" mean? Does recursively searching the body mean the graphql document selection set?

@onionhammer
Copy link

By payload, I mean the object being POSTed;

i.e. https://github.com/jaydenseric/graphql-multipart-request-spec?tab=readme-ov-file#file-list

You can see the variables get swapped out for nulls, then a map is appended to the form data with the variables that were present in that list, but the shape of variables likely isn't known, so you have to search it for File objects.

@ThallesP
Copy link

Thanks, I'll check those links out when the time comes.

you need to replace files in the payload

what would "payload" be and what would "files in payload" mean? Does recursively searching the body mean the graphql document selection set?

Yep, also please accept a Readable stream from node or the web api, loading the entire file in memory using a Buffer should be optional and not the only way.

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

No branches or pull requests

3 participants