Commit f6b13edb authored by aleclofabbro's avatar aleclofabbro
Browse files

query filter : renames match argument field names

parent 6b1fe695
...@@ -126,3 +126,48 @@ fragment FollowFrag on Follows { ...@@ -126,3 +126,48 @@ fragment FollowFrag on Follows {
} }
*/ */
/**
{
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
...@@ -32,7 +32,7 @@ export const buildMongoPipeline = (docS: DocumentSelection, notTop?: boolean) => ...@@ -32,7 +32,7 @@ export const buildMongoPipeline = (docS: DocumentSelection, notTop?: boolean) =>
field.lookups.forEach((fieldLookup, index) => { field.lookups.forEach((fieldLookup, index) => {
const $match = { $and: [{ __typename: fieldLookup.__typename }] as any[] } 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) { if (!index) {
mainLookup.pipeline = [ mainLookup.pipeline = [
...@@ -71,3 +71,18 @@ export const buildMongoPipeline = (docS: DocumentSelection, notTop?: boolean) => ...@@ -71,3 +71,18 @@ export const buildMongoPipeline = (docS: DocumentSelection, notTop?: boolean) =>
// return stages // 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
}
}
Supports Markdown
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