I have large JSON object returned by my nodejs API server. I want to give users ability to query subset of fields similar to GraphQL but without schema. Object that is returned by API have set of standard fields but also set of any custom fields that users can add to its "custom" property. I looked at GraphQL and as far as i understand it requires descriptor that defines all fields by which you can query. Unfortunately it will not work since "custom" field can have anything. I want for user to send query along with GET request that escribes what fields i want include and what i want to exclude. For example if object has:
{
user: {
age: 25,
weight: 170,
name: "Joe"
},
book: {
title: "Dune",
description: "Space opera",
localtion: {
planet: "Arakis",
population: 100000,
},
heroes: [
{
name: "Duke",
age: 43
},
{
name: "Paul",
age: 16
}
]
}
}
Now if I want everything under user name and book planet name I would send something like:
{'user.name': true, 'book.location.planet': true}
But if I want everything under book except heroes I would send:
{'book': true, 'book.heroes': false}
Anyone knows library that have something close to it?
2
Answers
Here’s an approach
You can try the below logic.