Commit 866a2965 authored by aleclofabbro's avatar aleclofabbro
Browse files

wip

parent 600faa2c
......@@ -9,8 +9,9 @@ export function defaultGraphFieldResolver(): ResolverFn<any, any, Context, any>
if (!context.$graph) {
context.$graph = {
qObj: {
type: 'Query',
__typename: 'Query',
query: undefined,
directives: {},
traverse: [],
alias: 'Query',
select: [],
......@@ -36,11 +37,12 @@ export function defaultGraphFieldResolver(): ResolverFn<any, any, Context, any>
if (isTop || ['_rel', '_subj', '_obj'].includes(fieldName)) {
parentQ.traverse.push(
...__typenames.map<GraphQueryObj>((typename) => ({
...__typenames.map<GraphQueryObj>((__typename) => ({
traverse: [],
select: [],
query: args?.query[typename],
type: typename,
directives: {},
query: args?.query[__typename],
__typename,
alias: `${info.path.key}`,
}))
)
......
import { GraphQuery } from '../types'
export const buildQuery = (root: GraphQuery) => {
return root.qObj.traverse.reduce((resultStages, gqo) => {
if (!(gqo.select.length || gqo.select.length)) {
return resultStages
}
const stages = [
{ $match: { $and: [{ __typename: gqo.__typename }, gqo.query.match] } },
{ $limit: gqo.query.page.limit || 15 },
]
return [...resultStages, ...stages]
}, [] as any[])
}
......@@ -14,8 +14,15 @@ export type GraphQuery = {
}
export type GraphQueryObj = {
type: string
query: any
__typename: string
query: {
match: any
page: {
limit?: number
after?: string | ObjectID
}
}
directives: Record<string, any>
select: Selection[]
traverse: GraphQueryObj[]
alias: string
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment