graphql-norm | Normalization and denormalization of GraphQL responses | GraphQL library
kandi X-RAY | graphql-norm Summary
kandi X-RAY | graphql-norm Summary
Responses from graphql servers may contain the same logical object several times. Consider for example a response from a blog server that contains a person object both as an author and a commenter. Both person objects have the same ID and are of the same GraphQL type so they are logically the same object. However, since they appear in two different parts of the response they need to be duplicated. When we want to store several GraphQL responsese the problem of duplication amplifies, as many respones may contain the same object. When we later want to update an object, it can be difficult to find all the places where the update needs to happen because there are multiple copies of the same logical object. This package solves these problems by using normalization and denormalization. A basic description of normalization (in this context) is that it takes a tree and flattens it to a map where each object will be assigned an unique ID which is used as the key in the map. Any references that an object holds to other objects will be exhanged to an ID instead of an object reference. The process of denormalizaton goes the other way around, starting with a map and producing a tree. The normalizr library does a good job of explaining this. In fact, this package is very similar to normalizr, but it was specifically designed to work with GraphQL so it does not require hand-coded normalization schemas. Instead it uses GraphQL queries to determine how to normalize and denormalize the data. Normalization and denormalization is useful for a number of scenarios but the main usage is probably to store and update a client-side GraphQL cache without any duplication problems. For example, Relay and Apollo use this approach for their caches. So the main use-case for this library is probably to build your own client-side cache where you get full control of the caching without loosing the benefit of normalization.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of graphql-norm
graphql-norm Key Features
graphql-norm Examples and Code Snippets
Community Discussions
Trending Discussions on graphql-norm
QUESTION
I have a GraphQL and Express project with these existing routes:
...ANSWER
Answered 2019-Jun-06 at 09:13After a few good hours of searching left and right I found a viable solution.
Luckily there is a formatResponse
that you can use: https://github.com/apollographql/apollo-server/blob/master/packages/apollo-server-core/src/graphqlOptions.ts#L43
The updated code looks like:
QUESTION
The Query.data
object of react-apollo
provides data in a nested form, like so:
ANSWER
Answered 2018-Jul-30 at 19:24You should be able to read the flattened data in the cache with client.readFragment()
Have a look at the documentation here: https://www.apollographql.com/docs/react/advanced/caching.html#readfragment
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install graphql-norm
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page