- Issue created by @TheodorosPloumis
- Merge request !110Issue #3506449 | Initial commit for module graphql_compose_file_upload by theodorosploumis → (Open) created by TheodorosPloumis
Create a new module that is able is upload files through a GraphQL mutation.
The file on the input must be from a multipart form (Multipart HTTP Request). See more at https://github.com/jaydenseric/graphql-multipart-request-spec.
- Testing
- Update docs on https://github.com/drupal-graphql-compose/documentation
New GraphQL mutation:
# Example. Upload a file to the field "field_files" with settings from node type "event"
mutation ($file: Upload!) {
fileUpload(
file: $file,
metadata: {
field_name: "field_my_file",
entity_type: NODE,
entity_bundle: "event"
}
) {
errors
results {
entity_bundle
entity_type
id
values
}
}
}
# Create file
curl https://example.com/graphql \
-F operations='{ "query": "fileUploadMutation ($file: Upload!) { fileUpload( file: $file, metadata: { field_name: \"field_files\", entity_type: NODE, entity_bundle: \"event\" } ) { errors results { entity_bundle entity_type id values } }}", "variables": { "file": null }}' \
-F map='{ "0": ["variables.file"] }' \
-F 0=@/path/to/myfile.pdf
# Create image
curl https://example.com/graphql \
-F operations='{ "query": "mutation ($file: Upload!) { fileUpload( file: $file, metadata: { field_name: \"field_files\", entity_type: NODE, entity_bundle: \"event\" } ) { errors results { entity_bundle entity_type id values } }}", "variables": { "file": null }}' \
-F map='{ "0": ["variables.file"] }' \
-F 0=@/path/to/myimage.jpeg
Active
2.2
Code