You could include a path argument on the field and then use something like lodash's get to transform the JSON item according to the provided path:
const resolvers = {
Instance: {
tags: (instance, args) => {
return _.get(instance.tags, args.path)
},
},
}
You could apply any number of arbitrary transformations this way to customize the returned JSON object. But, since you're returning a scalar, there is no way to just provide a selection set for the field.
Folks often feel they need to use a JSON scalar simply because the data they are working with is a map. However, a map can easily be transformed into an array, which can easily be represented in your schema without a JSON scalar. So you can just turn this:
{
"foo": {
"propA": "A",
"propA": "B"
},
"bar": {
"propA": "A"
"propA": "B"
}
}
into this:
[
{
"tagName": "foo",
"propA": "A",
"propA": "B"
},
{
"tagName": "bar",
"propA": "A",
"propA": "B"
}
]