Upload files to a Graphql endpoint using HURL

Oct 2, 2024

Engineering

fda cybersecurity compliance
fda cybersecurity compliance
fda cybersecurity compliance

Hurl is an amazing tool that makes API testing simple and efficient. It’s very developer-friendly and easy to use. However, there are some limitations when it comes to uploading files to a GraphQL endpoint. This article will guide you through the process of uploading files to a GraphQL endpoint using Hurl.

Understanding the GraphQL File Upload Format

GraphQL follows a specific format for uploading files. The details of this specification are described in the GraphQL multipart request specification.

Limitations of Hurl for File Uploads

Hurl supports multi-part form data as a text body but does not support sending external files directly. However, you can use multipart-form-data to upload files to a GraphQL endpoint.

Example of Uploading a File to a GraphQL Endpoint Using Hurl:

Below is an example of how to upload a file to a GraphQL endpoint using Hurl:

Explanation

In the example above, we are uploading a file called basic.json to a GraphQL endpoint. The request is defined using multipart/form-data, where:

  • Operations: Contains the GraphQL mutation and variables.

  • Map: Maps the file upload to the corresponding variable in the GraphQL request.

  • 0: Represents the actual file to be uploaded (basic.json).

Conclusion

With the example above, you can easily upload files to a GraphQL endpoint using Hurl. Remember to adjust the GRAPHQL_EP, API_KEY, and projectId placeholders according to your setup.

Trusted by 100+ Organizations

See your SBOM Done Right

Interlynk automates SBOMs, manages open source risks, monitors,
suppliers, and prepares you for the post-quantum era, all in one trusted platform.

NO SPAM, PROMISE!

See your SBOM Done Right

Interlynk automates SBOMs, manages open source risks, monitors suppliers, and prepares you for the post-quantum era, all in one trusted platform.

NO SPAM, PROMISE!

See your SBOM Done Right

Interlynk automates SBOMs, manages open source risks, monitors suppliers, and prepares you for the post-quantum era, all in one trusted platform.