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
f6b13edb
Commit
f6b13edb
authored
Oct 14, 2020
by
aleclofabbro
Browse files
query filter : renames match argument field names
parent
6b1fe695
Changes
2
Hide whitespace changes
Inline
Side-by-side
generate_data/populate.js
View file @
f6b13edb
...
...
@@ -125,4 +125,49 @@ fragment FollowFrag on Follows {
}
}
*/
\ No newline at end of file
*/
/**
{
graph(query:{User:{_or:[{username:{_gt:"Y"}},{username:{_eq:"Aaliyah.Berge46"}}]}}) {
... on User {
...UserFrag
}
}
}
fragment UserFrag on User {
username
followsAndKnows: _rel {
# ... on Follows {
# ...FollowFrag
# }
... on Knows {
_obj (query:{User:{username:{_lt:"B"}}}){
... on User {
username
}
}
}
}
}
# fragment FollowFrag on Follows {
# user: _obj {
# ... on User {
# username
# knows: _rel {
# ... on Knows {
# knows: _obj {
# ... on User {
# username
# }
# }
# }
# }
# }
# }
# }
*/
\ No newline at end of file
src/gql-graph/mongo/buildMongoPipeline.ts
View file @
f6b13edb
...
...
@@ -32,7 +32,7 @@ export const buildMongoPipeline = (docS: DocumentSelection, notTop?: boolean) =>
field
.
lookups
.
forEach
((
fieldLookup
,
index
)
=>
{
const
$match
=
{
$and
:
[{
__typename
:
fieldLookup
.
__typename
}]
as
any
[]
}
fieldLookup
.
match
&&
$match
.
$and
.
push
(
fieldLookup
.
match
)
fieldLookup
.
match
&&
$match
.
$and
.
push
(
renameMatchFields
(
fieldLookup
.
match
)
)
if
(
!
index
)
{
mainLookup
.
pipeline
=
[
...
...
@@ -71,3 +71,18 @@ export const buildMongoPipeline = (docS: DocumentSelection, notTop?: boolean) =>
// return stages
// }
}
function
renameMatchFields
(
match
:
any
):
any
{
if
(
Array
.
isArray
(
match
))
{
return
match
.
map
((
_
)
=>
renameMatchFields
(
_
))
}
else
if
(
'
object
'
===
typeof
match
)
{
return
Object
.
entries
(
match
).
reduce
((
_
,
[
key
,
val
])
=>
{
return
{
...
_
,
[
key
.
replace
(
/^_/
,
'
$
'
)]:
renameMatchFields
(
val
),
}
},
{})
}
else
{
return
match
}
}
Write
Preview
Supports
Markdown
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