GraphQL endpoint for file download - graphql

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!

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).

BoĊĦtjan Cigan mentions here some solutions and gives details about using GraphQL as a proxy with Minio. The backend would ask Mino to generate a temporary link that can be sent back to the browser for direct access.
This is a valid solution for many use cases.

Related

I am using open-telemetry in go, how can I keep the tracerId of gin and grpc the same?

I am a go newbie, I am using otelgin and otelgprc in open-telemetry/opentelemetry-go-contrib to track microservice links, currently my project uses gin for api-gateway and then gin routes in to call grpc services.
But I was never able to pass the tracerId from otelgin to otelgrpc, so two tracers are generated for one request.
If someone can help me with this problem it would be great, thanks.
I expect to be able to pass tracerId from gin to grpc, using only one tracerId, instead of generating two links.
If more information is needed, I can add it, thanks again.
In otelgin middleware, the traceable context is propagated through ginContext.Request.Context(). So you can pass on this request context instead of ginContext to your gRPC client to propagate trace.

Can't I create a rest API in the apollo-server?

It is currently being developed using mysql-prisma-apollo server-nexus, and it is necessary to receive row data post using the REST API, not the GrqphQL statement currently developed. You want to process raw data passed to the post in Path (for example,/api/data/status). Is there a way to create a RestAPI on the apollo-server?
The apollo-server runs in a node environment, so you are able to use any http client you want.
Example:
axios
node-fetch

How to use REST API with FaunaDB?

I have created a collection in my Fauna database. I also made an index that returns all the data in that collection. I want to know if there is a way to get JSON REST API to work with this data. What I mean by this is I want a URL that I can 'GET' using XMLHttpRequest and then parse into JSON.
You might say that Fauna is "HTTP native". All of the language drivers (JS, C#, Python, etc.) are built on top of http requests. That is, there are no special connections or connection-pools to maintain. You can get pretty far with using the JS driver in the browser, for example, without using a server.
But to answer your question more directly, there are many ways to serve a REST API, and it is going to depend on how you want to serve the API.
Examples
AWS
Here is a blog post on how to set up a REST API with AWS App Runner, for example.
https://fauna.com/blog/deploying-a-rest-api-with-aws-app-runner-and-fauna
Vercel and Netlify
There are also some example apps on github that demonstrate using a REST API with
Vercel:
https://github.com/vercel/next.js/tree/canary/examples/with-cookie-auth-fauna
Or Netlify:
https://github.com/netlify/netlify-faunadb-example
Both of which host serverless functions for you to create a REST API.

How do you configure AWS API Gateway HTTP GET to return the BASE64 string as binary data?

I am trying to send binary data from my AWS Lambda function as a response to an AWS Gateway GET Method that DOES NOT use Lambda Proxy integration. I have tried all sorts of variations but still can't make it work, although I feel like I am close.
My API Gateway HTTP request is returning:
But what I want is is the actual binary data:
I did attempt using a mapping template, but was unsuccessful due to my lack of understanding the templating syntax/behavior(I tried $util.base64Decode($input.body) but that produced a server error).
But I wasn't sure if that was even necessary since I have the content handling set to Convert to binary.
I ran into this problem but I used a proxy url. Make sure to enable Binary Media Types. Also do not forget to deploy your changes, simply saving is not enough. Also make sure you have the correct content type in the header with client sending the payload.

how to use the proxy service without tryit tool in wso2 esb?

I am learning and working on building some wso2 sample prototypes.
I have created a proxy service and tried using it with the tryit tool inside.
But i don't know how to use it externally. i mean how to send data to the proxy service because in API there is a endpoint created where the request is sent.
Is there anything like link to request or how to use it externally in some application.
You can use SOAP UI. Please check the article.
The easiest way to call Your proxy service is to use some Rest Client on Your Browser. I use Add-On in Firefox (RestClient i think). U can create there whole request (json, xml), add headers, Authentications or Content Type. It should helps U to call any services in wso2.

Resources