-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Normalized Responses #150
Comments
Here I come with the following API idea. We add one new function const userType = new GraphQLObjectType({
name: 'User',
description: 'User type',
fields: () => ({
name: {
type: new GraphQLNonNull(GraphQLString),
description: 'User name',
},
friends: {
type: userType,
description: 'User friends',
resolve: (user) => {
return find({ id: user.friends });
},
normalize: (friend) => {
return friend.id;
}
}
})
}); For now all GraphQL seems for me similar to serialization and I assume it would be cool to have a possibility of deserialization with existing schema. What for? Purpose is the same you described in Relay. We always need to store some data in the cache on the client. But the problem is that we need to store deserialized data to be able to easily manage it and update with some server responses. On the other hand developers always want to minimize the amount of data which is passed between client and server. Lets assume that we've batched a few different queries in one request and run them agains GraphQL schema. After it we would have some deep data structures which probably we cannot merge. If we normalize them before sending we can merge all the responses and send them as one plain data structure. Than we merge this result with data on the client and are able to run Same GraphQL queries to get data in appropriate form. Sorry for my bad English and pure explanation I hope you can get the idea behind this. |
Normalized responses require a lot more than just adding a method to normalization. It requires different validation rules and changes the shape of the result which requires specific handling by clients. This is something we eventually want to do, but the implicates are large so we need a more comprehensive proposal. |
I would write my full usecase of using this in a few days. I hope it would be helpful. |
Hi, @leebyron! You can check my solution: prepare GraphQL schema and normalize. |
Closing this aging issue. FYI, this is still something on the long term plan. Validation rules are necessary to account for a scenario where the same object may appear in two places in a normalized response with illegal overlapping fields. That is, an extension to http://facebook.github.io/graphql/#sec-Field-Selection-Merging As you also discovered, you need some unique identifier to perform the normalization from. That must also end up in a final proposal. I'm excited to share more details on this soon, as I've been thinking about it quite a bit. |
@leebyron Did your thoughts on this amount to much in the end? Any further conclusions? |
Normalisation would be an insanely useful feature. |
You can give graphql-normalizr a try |
If you want to do normalization and denormalization of GrapqhQL responses we developed graphql-norm for that purpose. It could be used to build client-side caching or returning normalized responses from the server-side. |
For your inspiration: https://page.hyoo.ru/#!=uhgyst_zfa8t3 |
Please read the following comment.
The text was updated successfully, but these errors were encountered: