Skip to content

Instantly share code, notes, and snippets.

@itsmepetrov
Last active July 3, 2016 12:37
Show Gist options
  • Save itsmepetrov/1bcc35d10c970a1af196576b91622f30 to your computer and use it in GitHub Desktop.
Save itsmepetrov/1bcc35d10c970a1af196576b91622f30 to your computer and use it in GitHub Desktop.
Normalize deep nested query with normalizr
import { Schema, arrayOf, normalize } from "normalizr"
const input = {
id: 100,
title: 'Playing with normalizr',
text: 'Normalize deep nested query with normalizr',
likes: {
total: 1,
page: 1,
limit: 10,
users: [{
id: 1,
name: 'Anton Petrov'
}]
}
}
var user = new Schema('users')
var post = new Schema('posts')
post.define({
likes: {
users: arrayOf(user)
}
})
const result = normalize(input, post)
console.log(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment