I am working with Apollo's Graphql React Client.
I would like to have some "default values" that queries return when they fail to fetch the data, for example, when offline.
I know that I can check if an error occured and populate it manually, but this means that I will have to do it and sync the data between each component that uses the useQuery hook with intersecting results.
I was unable to find anything, but is there some way/best practice to do it?
Thank you
Related
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
It looks like its possible to cancel pending requests via client.stop() but the documentation is not showing us a solution when we use apollo client hooks where we have no client.
How to stop pending requests using apollo client hooks ?
Struggled for days and made a proof of concept that finally works.
I have explained the code below and here is my POC - Github source code.
Explaination:
Step – 1:
Create a middleware that holds the logic to track and cancel duplicate request via ReactJS context API – cancelRequest.tsx (complete source code)
Step – 2:
Generate namespace UUID and pass it using requestTrackerId via query context as below.
context:{
requestTrackerId: uuidNameSpace('LOGIN', RequestNameSpace)
}
Refer source code - Line 32
Step – 3:
Finally, wiring all the middleware and setup it up as funnel layers using from API of Apollo GraphQL client and set queryDeduplication to false.
Mechanism of action:
When ever more than one request originates from the same mutation query, each query is tagged to its requestTrackerId which remains same to that particular query and different for other queries.
Using UUID library namespace is generated for each query (Read the code). With this ID the middleware associates each query to its namespace generated ID and stores in a cache object.
Subsequent incoming request are looked up using the cache object. If there’s an ongoing request which is not yet completed, it will be aborted immediately using AbortController javascript API and this request is replaced with new request.
Libraries used
UUID – Used to create unique request tracker ID and prevent namespace
collision for multiple request from same component.
ReactJS – No intro needed i guess?
Apollo GraphQL – Follow the link to know more..
Hope this answer helps. Happy coding
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.
I'm using GraphQL (Spring Boot, Kotlin), and I have a specific issue with headers.
We need the client to send three pieces of information that we combine to retrieve internal sensitive data. That data is then used inside resolver codes.
Getting the headers from rest is as easy as #RequestHeader, but in GraphQL it has proved quite challenging. Is there a way I can save the headers to check for the three pieces of information I need?
I looked closely at spring security, but I can't figure out how to get a custom method to work in my method chain, much less save the headers in a way that I can access them from the domain layer.
I could always simply request the auth as a GraphQL type, but that puts a fairly high burden on the client and complicates the schema.
Any and all feedback is welcome.
GraphQL has a FetchDataEnvironment. You can use it by passing FetchDataEnvironment as the last variable in any resolver/query. Then, just call
environment.getContext<GraphQLEnvironentClass>().getHttpServletRequest.headers()
To anyone in the future - I'm sorry this code isn't exact, but your strong typing in your IDE will show you what I mean.
I have created a graphql server that send data to client and show results to react component using relay. If i want't to get data from different sources( different server or different DB) I have to change my resolve function and put there the code that get data with ajax for example?
Correct.
All you need to do is to resolve to the right source,
You can either return a value or a promise for a value.