Problem
There is no way to traverse downward in the entity hierarchy via GraphQL. Given an Organization, you cannot discover its child entities without a separate query. The _parent property lets you look up, but there is no corresponding field to look down.
Suggested change
schema.js (~line 254), add to output fields:
const outputFields = [
// ... existing system fields ...
' "Child entities"',
' _children: [ReferenceValue]'
]
resolvers.js, add field resolver:
TypeResolvers[typeName] = {
_children: async (parent, _, { entu }) => {
const children = await entu.db.collection('entity').find({
'private._parent.reference': parent._id,
access: entu.user ? { $in: [entu.user, 'domain', 'public'] } : 'public'
}, {
projection: { _id: 1, 'private.name': 1 }
}).toArray()
return children.map(c => ({
_id: c._id,
reference: c._id,
string: c.private?.name?.[0]?.string || c._id.toString()
}))
}
}
Example query this enables
query {
organization(filter: { _id: "org-id" }) {
_id
name { string }
_children { reference string }
}
}
Use case
Polyphony PoC: browsing an Organization's Roles and Members inline. Combined with #89 (_parent filter), this gives both directions of hierarchy traversal.
~20 lines changed, purely additive.
Split from #88
(ER:Codd + Saavedra)
Problem
There is no way to traverse downward in the entity hierarchy via GraphQL. Given an Organization, you cannot discover its child entities without a separate query. The
_parentproperty lets you look up, but there is no corresponding field to look down.Suggested change
schema.js(~line 254), add to output fields:resolvers.js, add field resolver:Example query this enables
Use case
Polyphony PoC: browsing an Organization's Roles and Members inline. Combined with #89 (
_parentfilter), this gives both directions of hierarchy traversal.~20 lines changed, purely additive.
Split from #88
(ER:Codd + Saavedra)