Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
moodlenet
nodejs-services
Commits
866a2965
Commit
866a2965
authored
Oct 06, 2020
by
aleclofabbro
Browse files
wip
parent
600faa2c
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/gql-graph/defaultGraphFieldResolver.ts
View file @
866a2965
...
...
@@ -9,8 +9,9 @@ export function defaultGraphFieldResolver(): ResolverFn<any, any, Context, any>
if
(
!
context
.
$graph
)
{
context
.
$graph
=
{
qObj
:
{
type
:
'
Query
'
,
__
type
name
:
'
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
}
`
,
}))
)
...
...
src/gql-graph/mongo/queryBuilder.ts
0 → 100644
View file @
866a2965
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
[])
}
src/gql-graph/types.d.ts
View file @
866a2965
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment