Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 18, 2025

Overview

Fixes #961

The "Copy to cURL" feature now generates working cURL commands for GraphQL mutations with file uploads. Previously, attempting to copy a mutation with file variables would show an error: "This is not currently available with file variables". This implementation follows the GraphQL multipart request spec to generate proper multipart/form-data cURL commands.

Changes

File Upload Support in cURL Generation

Extended the generateCurl function to detect and handle file uploads by:

  • Switching to multipart/form-data format when files are present
  • Generating three multipart fields per the GraphQL spec:
    1. operations: Query and variables with files set to null
    2. map: File index to variable path mapping
    3. File fields: File references using @filename syntax
  • Automatically removing Content-Type header (curl sets it with boundary)
  • Handling nested variable paths (e.g., input.document.file)

Effect Update

Updated the copyAsCurl$ effect to pass resolved file information to the curl generator instead of showing an error.

Example

Before:

❌ Error: This is not currently available with file variables

After:

curl 'https://api.example.com/graphql' \
  -H 'Accept-Encoding: gzip, deflate, br' \
  -H 'Accept: application/json' \
  -H 'Connection: keep-alive' \
  -F 'operations={"query":"mutation($file: Upload!) { uploadFile(file: $file) }","variables":{"file":null}}' \
  -F 'map={"0":["variables.file"]}' \
  -F '[email protected]' \
  --compressed

Features

  • ✅ Single file uploads
  • ✅ Multiple file uploads (arrays)
  • ✅ Nested file variables
  • ✅ Mix of regular and file variables
  • ✅ Compatible with graphql-upload and spec-compliant servers
  • ✅ Maintains backward compatibility for non-file requests

Testing

Added comprehensive test coverage for:

  • Single file upload scenarios
  • Multiple file upload scenarios (arrays)
  • Nested file variable scenarios
  • Verification of correct multipart/form-data structure

Usage Note

Generated cURL commands use relative file paths (@filename.ext). Users should either run the command from the directory containing the file or modify the path to an absolute path (@/path/to/filename.ext).

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • downloads.sentry-cdn.com

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>"copy as curl" does not save the file upload functionality</issue_title>
<issue_description>Describe the bug
If you have a mutation that uploads file(s), successfully within Altair when you choose "copy as curl" a curl command line is generated but when you run it in curl it does not upload the files.

To Reproduce
Steps to reproduce the behavior:

  1. Create a graphql service that accepts uploads.
  2. Create an Altair client mutation, variables and upload file(s)
  3. Check that it works in Altair, and your server is getting the files.
  4. click on "Copy to Curl"
  5. Open an bash window and paste to the command line.
  6. Observe that the command line contains no references to the upload files that you have set.
  7. Run the command line and see that your server does not receive any files.
    Expected behavior
    I expect the "save as curl" command line should behave exactly as Altair does, if it knows where the files are.

Desktop (please complete the following information):

  • OS: Ubuntu hippo 21.04
  • Browser chrome Version 91.0.4472.77 (Official Build) (64-bit)
  • Platform: Chrome extension and snap
  • Version Not sure (about does not work) downloaded yesterday.

Additional context
Add any other context about the problem here.
</issue_description>

Comments on the Issue (you are @copilot in this section)

@imolorhe Yeah @matthewvcarey1 the "Copy to cURL" doesn't support the file upload functionality. It hasn't been updated, so it will be buggy. Thanks for mentioning it. @imolorhe I'll be disabling the "Copy to CURL" functionality when using file input, until it is properly updated with support for that.

Fixes #1600


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@coderabbitai
Copy link

coderabbitai bot commented Oct 18, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI changed the title [WIP] Fix copy as curl to include file uploads Add file upload support to "Copy to cURL" functionality Oct 18, 2025
Copilot finished work on behalf of imolorhe October 18, 2025 14:05
Copilot AI requested a review from imolorhe October 18, 2025 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"copy as curl" does not save the file upload functionality

2 participants