25
loading...
This website collects cookies to deliver better user experience
BookStore <--1:n--> Book <--m:n--> Author
{
__typename: "BookStore",
id: 1,
name: "O'REILLY",
books: [
{
__typename: "Book",
id: 2,
name: "Learning GraphQL",
},
{
__typename: "Book",
id: 3,
name: "Effective TypeScript"
}
]
}
{
__typename: "Author",
id: 9,
name: "Alex Banks",
books: [
{
__typename: "Book",
id: 2,
name: "Learning GraphQL",
}
]
}
{
"Query": {
findBooks({"name": "e"}): [{ref: "Book:2"}, {ref: "Book:3"}],
findBooks({"name": "g"}): [{ref: "Book:2"}]
},
"Book:2": {
id: 2,
name: "Learning GraphQL"
},
"Book:3": {
id: 3,
name: "Effective TypeScript"
}
}
{
"Query": {
findBooks({"name": "e"}): [{ref: "Book:3"}, {ref: "Book:3"}],
// Extra mutation: old data references need to disappear
findBooks({"name": "g"}): []
},
"Book:2": {
id: 2,
// Main mutation: the original intention of the developer
name: "Learning TypeScript"
},
"Book:3": {
id: 3,
name: "Effective TypeScript"
}
}
The "main mutation" above is very simple, and this is the developer's intention in itself. However, "extra mutation" is very troublesome. It is the changes that other existing data in the cache have to make in order to adapt to the new data mutation.
The number of such "extra mutations" is affected by the amount of existing data in the cache and the complexity of the data structure. From a theoretical level, the complexity cannot be limited, and one main mutation can lead to countless extra mutations.
For Apollo Client:
Relay prefers to modify the cache directly: https://relay.dev/docs/guided-tour/updating-data/graphql-mutations/#updater-functions
Since it is known as the react state management framework, does it only support GraphQL? What about REST?
In the next version to be released, the framework can simulate GraphQL base on REST. Even for the REST server, it can be abstracted into GraphQL on the client side, enjoying its powerful language meaning and convenience. This feature is called "GraphQL style, but not GraphQL only", please look forward to it.