-
Hi, In this example, trying to follow the docs, I only want to pass the exact same object I receive from the GraphQL API to the frontend - with a console.log firing in the resolver (once I get that working I will start to manipulate the values, but this is just trying to get the basics working). Would really appreciate some help as I am struggling for some reason... Resolvers:
GraphQL query (shortened to relevant bits):
When this query fires, the console.log correctly shows but the parent object does not actually contains the "recipe_ingredients" property I am referring to so the resolver returns undefined - crashing the app. console.log response:
Any ideas what could potentially be wrong here? Do I need to do something with the args as the recipe_ingredients property is ordered on the backend (just guessing here) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
The docs do mention this around here: https://formidable.com/open-source/urql/docs/graphcache/computed-queries/#resolve Do you have some details on what you're trying to achieve? I see that you want to basically write |
Beta Was this translation helpful? Give feedback.
-
I also want to leave an explanation here separately regarding this:
I've previously mentioned that One the one hand, this object can never be the original part of the query response at that place for two reasons. The cache won't have access to it anymore by the time it's reading a query. Caching data and reading it back are two separate processes. A normalised cache handles any query so it never retains access to the original data after writing it to the cache, so therefore the resolvers won't receive it either; because it may be any given query if we went by the original data, which doesn't match the query that's currently read from cache. In other words: For any given query and response from the server, there are multiple queries and responses that the cache can then assemble, independent of the query that has actually been sent to the API. That's why reading and writing are independent. So the other question then is, why is the |
Beta Was this translation helpful? Give feedback.
The docs do mention this around here: https://formidable.com/open-source/urql/docs/graphcache/computed-queries/#resolve
I haven't quite looked at the specific line to link to but the tl;dr is that
parent
is only the object as it's been assembled to from previous fields. So you don't want to use it directly most of the time. The explanation for that is simple: Any entity has a potential countless number of fields, some even taking arguments. The cache structure is an implementation detail so it's not possible to return all that the cache has in a meaningful form.Do you have some details on what you're trying to achieve? I see that you want to basically write
cache.resolve(parent, 'recipe_…