Add module graphql_compose_file_upload

Created on 13 February 2025, 11 days ago

Problem/Motivation

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.

Remaining tasks

- Testing
- Update docs on https://github.com/drupal-graphql-compose/documentation

API changes

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
    }
  }
} 

How to send a multipart file with curl

# 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

Feature request
Status

Active

Version

2.2

Component

Code

Created by

🇬🇷Greece TheodorosPloumis Greece

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024