Enhancing GraphQL File Uploads in Laravel: How to Send Additional Variables via postman

  1. Open Postman and create a new request.
  2. Set the request method to “POST” and the URL to your GraphQL API endpoint.
  3. Click on the “Body” tab and select the “form-data” option.
  4. Add a new key-value pair with the key as “operations” and the value as a JSON string containing the GraphQL query and the variables you want to send.For example

    { 
        "query": "mutation ($file: Upload!, $fileName: String!) { uploadFile(file: $file, fileName: $fileName) { id } }", 
        "variables": { 
            "file": null, 
            "fileName": "file-name-here.ext" 
        } 
    }

    Note that the “file” variable is of type Upload! and the “fileName” is a regular variable.

  5. Add another key-value pair with the key as “map” and the value as a JSON string containing the mapping of the “file” variable to the actual file you want to upload.For example:

    { "0": ["variables.file"] }

    Note that the “0” key represents the index of the file you want to upload, and the value is an array containing the path to the “file” variable.

  6. Click on the “Choose Files” button next to the “map” field and select the file you want to upload.
  7. Click on the “Send” button to send the request.

Your GraphQL API should now receive the GraphQL query along with the additional variable and the file upload.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.