This example demonstrates uploading files via the GraphQL Upload spec.
Try running it:
cd examples/file_uploads
bundle install
foreman start
This example is headless, but you can verify the stitched schema is running by querying a field from each graph location:
curl -X POST http://localhost:3000 \
-H 'Content-Type: application/json' \
-d '{"query":"{ gateway remote }"}'
Now try submitting a multipart form upload with a file attachment, per the spec. The response will echo the uploaded file contents:
curl http://localhost:3000 \
-H 'Content-Type: multipart/form-data' \
-F operations='{ "query": "mutation ($file: Upload!) { gateway upload(file: $file) }", "variables": { "file": null } }' \
-F map='{ "0": ["variables.file"] }' \
-F 0=@file.txt
This workflow has:
- Submitted a multipart form to the stitched gateway.
- The gateway server unpacked the request using apollo_upload_server.
- Stitching delegated the
upload
field to its appropraite subgraph location. HttpExecutable
has re-encoded the subgraph request into a multipart form.- The subgraph location has recieved, unpacked, and resolved the uploaded file.