Is it possible to trigger a file download in a browser from the GraphQL endpoint on an apollo-server-express
application?
I have the endpoint written in a standard express app.get
function (see below) but I would like to make use of the GraphQL context for file download and so I'm wondering if it's possible to cause a download from a GraphQL endpoint.
Here's a bare-bones example of what I have on the express end in the app.get
function:
app.get('/download-batch/:batchId', async (req, res) => {
res.send(new Buffer('test'));
});
Any help would me much appreciated. Thanks!
the Graphql responses JSON format only if you like to download files in the front end you can implement another app like express to upload and download files from/to it.
Your GraphQL endpoint can be found on the dashboard. It will look something like: https://example.us-west-2.aws.cloud.dgraph.io/cloud . If you open up the docs tab on the right side, you'll see that GraphQL playground has pulled all the possible resolvers that our server supports.
Our GraphQL server still provides a mutation for uploading files, but the mutation is only used to setup a file upload. The actual file upload is done through a dedicated endpoint. We can accomplish this by returning presigned upload URLs from our mutations.
GraphQL is typically served over HTTP via a single endpoint which expresses the full set of capabilities of the service. This is in contrast to REST APIs which expose a suite of URLs each of which expose a single resource.
Yes, but you would be required to create a custom endpoint for that. You can't use the existing endpoint which you are using for making requests. Using the custom endpoint, you have to add a middleware and process the data into a buffer or whatever format you need. But it would not be recommended. That would again become one more endpoint instead which you can write an API to serve that.(After all graphql is built mainly on the focus of single endpoint).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With