mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
I had to trick neo4j-graphql-js to return disabled and deleted fields by default on any neo4j node. If disabled is not queried, then we don't have it in our middleware and we're not able to filter it.
30 lines
920 B
JavaScript
30 lines
920 B
JavaScript
import cloneDeep from 'lodash/cloneDeep'
|
|
|
|
const _includeFieldsRecursively = (selectionSet, includedFields) => {
|
|
if (!selectionSet) return
|
|
includedFields.forEach((includedField) => {
|
|
selectionSet.selections.unshift({
|
|
kind: 'Field',
|
|
name: { kind: 'Name', value: includedField }
|
|
})
|
|
})
|
|
selectionSet.selections.forEach((selection) => {
|
|
_includeFieldsRecursively(selection.selectionSet, includedFields)
|
|
})
|
|
}
|
|
|
|
const includeFieldsRecursively = (includedFields) => {
|
|
return (resolve, root, args, context, resolveInfo) => {
|
|
const copy = cloneDeep(resolveInfo)
|
|
copy.fieldNodes.forEach((fieldNode) => {
|
|
_includeFieldsRecursively(fieldNode.selectionSet, includedFields)
|
|
})
|
|
return resolve(root, args, context, copy)
|
|
}
|
|
}
|
|
|
|
export default {
|
|
Query: includeFieldsRecursively(['id', 'disabled', 'deleted']),
|
|
Mutation: includeFieldsRecursively(['id', 'disabled', 'deleted'])
|
|
}
|