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
261cbb76
Commit
261cbb76
authored
Oct 06, 2020
by
aleclofabbro
Browse files
renaming stuff
parent
24ec7e11
Changes
11
Hide whitespace changes
Inline
Side-by-side
graphql/schema.graphql
View file @
261cbb76
interface
Glyph
{
_
id
:
ID
!
id
:
ID
!
}
input
StringMatch
{
eq
:
String
gt
:
String
lt
:
String
input
StringMatch
Input
{
_
eq
:
String
_
gt
:
String
_
lt
:
String
}
input
Page
Arg
{
input
Page
Input
{
limit
:
Int
after
:
ID
}
...
...
@@ -14,70 +14,69 @@ input PageArg {
# Knows
union
Knower
=
User
union
Knowable
=
User
input
KnowSubjectQuery
{
User
:
UserQuery
input
Know
s
SubjectQuery
Input
{
User
:
UserQuery
Input
}
input
KnowObjectQuery
{
User
:
UserQuery
input
Know
s
ObjectQuery
Input
{
User
:
UserQuery
Input
}
input
KnowsQuery
{
and
:
[
KnowsQuery
!]
or
:
[
KnowsQuery
!]
_page
:
PageArg
input
KnowsQuery
Input
{
_
and
:
[
KnowsQuery
Input
!]
_
or
:
[
KnowsQuery
Input
!]
id
:
[
ID
!]
}
type
Knows
implements
Glyph
{
_
id
:
ID
!
_subj
(
query
:
KnowSubjectQuery
):
[
Knower
!]!
_obj
(
query
:
KnowObjectQuery
):
[
Knowable
!]!
id
:
ID
!
_subj
(
query
:
Know
s
SubjectQuery
Input
,
page
:
PageInput
):
[
Knower
!]!
_obj
(
query
:
Know
s
ObjectQuery
Input
,
page
:
PageInput
):
[
Knowable
!]!
}
# Follows
union
Follower
=
User
union
Followable
=
User
input
FollowObjectQuery
{
User
:
UserQuery
input
FollowObjectQuery
Input
{
User
:
UserQuery
Input
}
input
FollowSubjectQuery
{
User
:
UserQuery
input
FollowSubjectQuery
Input
{
User
:
UserQuery
Input
}
input
FollowsQuery
{
and
:
[
FollowsQuery
!]
or
:
[
FollowsQuery
!]
_page
:
PageArg
input
FollowsQuery
Input
{
_
and
:
[
FollowsQuery
Input
!]
_
or
:
[
FollowsQuery
Input
!]
id
:
[
ID
!]
}
type
Follows
implements
Glyph
{
_
id
:
ID
!
_subj
(
query
:
FollowSubjectQuery
):
[
Follower
!]!
_obj
(
query
:
FollowObjectQuery
):
[
Followable
!]!
id
:
ID
!
_subj
(
query
:
FollowSubjectQuery
Input
,
page
:
PageInput
):
[
Follower
!]!
_obj
(
query
:
FollowObjectQuery
Input
,
page
:
PageInput
):
[
Followable
!]!
}
# User
input
UserQuery
{
and
:
[
UserQuery
!]
or
:
[
UserQuery
!]
_id
:
ID
username
:
StringMatch
_page
:
PageArg
input
UserQueryInput
{
_and
:
[
UserQueryInput
!]
_or
:
[
UserQueryInput
!]
id
:
[
ID
!]
username
:
StringMatchInput
}
input
UserRelationQuery
{
Follows
:
FollowsQuery
Knows
:
KnowsQuery
input
UserRelationQuery
Input
{
Follows
:
FollowsQuery
Input
Knows
:
KnowsQuery
Input
}
union
UserRelation
=
Knows
|
Follows
type
User
implements
Glyph
{
_
id
:
ID
!
_rel
(
query
:
UserRelationQuery
):
[
UserRelation
!]!
id
:
ID
!
_rel
(
query
:
UserRelationQuery
Input
,
page
:
PageInput
):
[
UserRelation
!]!
username
:
String
!
}
# Main
type
Query
{
user
(
query
:
UserQuery
):
[
User
!]!
user
(
query
:
UserQuery
Input
):
[
User
!]!
}
input
CreateUserInput
{
...
...
src/gql-graph/mongo/mappers.ts
View file @
261cbb76
import
{
ObjectID
}
from
'
mongodb
'
import
{
GqlNode
,
GqlRelation
,
ShallowEntity
}
from
'
../types
'
export
type
MongoNode
<
T
extends
GqlNode
>
=
Omit
<
T
,
'
_
id
'
|
'
_rel
'
>
&
{
_id
:
ObjectID
}
export
type
MongoRelation
<
T
extends
GqlRelation
>
=
Omit
<
T
,
'
_
id
'
|
'
_subj
'
|
'
_obj
'
>
&
{
export
type
MongoNode
<
T
extends
GqlNode
>
=
Omit
<
T
,
'
id
'
|
'
_rel
'
>
&
{
_id
:
ObjectID
}
export
type
MongoRelation
<
T
extends
GqlRelation
>
=
Omit
<
T
,
'
id
'
|
'
_subj
'
|
'
_obj
'
>
&
{
_id
:
ObjectID
_obj
:
ObjectID
_subj
:
ObjectID
}
export
const
toMongoNode
=
<
N
extends
GqlNode
>
(
node
:
ShallowEntity
<
N
>
|
Omit
<
ShallowEntity
<
N
>
,
'
_
id
'
>
gql_
node
:
ShallowEntity
<
N
>
|
Omit
<
ShallowEntity
<
N
>
,
'
id
'
>
):
MongoNode
<
N
>
=>
{
const
_id
=
'
_
id
'
in
node
?
new
ObjectID
(
node
.
_
id
)
:
new
ObjectID
()
const
_id
=
'
id
'
in
gql_
node
?
new
ObjectID
(
gql_
node
.
id
)
:
new
ObjectID
()
const
mongo_node
=
Object
.
entries
(
node
).
reduce
(
(
_mongo_node
,
[
key
,
val
])
=>
{
if
([
'
_
id
'
,
'
_rel
'
].
includes
(
key
))
{
return
_mongo_node
const
mongo_node
=
Object
.
entries
(
gql_
node
).
reduce
(
(
constructing
_mongo_node
,
[
key
,
val
])
=>
{
if
([
'
id
'
,
'
_rel
'
].
includes
(
key
))
{
return
constructing
_mongo_node
}
return
{
...
_mongo_node
,
...
constructing
_mongo_node
,
[
key
]:
val
,
}
},
...
...
src/gql-graph/mongo/queryBuilder.ts
View file @
261cbb76
import
{
GraphQuery
}
from
'
../types
'
import
{
GraphQuery
,
GraphQueryObj
}
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
[])
return
_buildUnionQuery
([
root
.
qObj
])
}
const
_buildUnionQuery
=
(
qObjs
:
GraphQueryObj
[])
=>
{
// const groupedTraversesByAlias = traversingGQObj.traverse.reduce((_grouped, groupingQObj) => {
// const slots = _grouped[groupingQObj.alias] || (_grouped[groupingQObj.alias] = [])
// slots.push(groupingQObj)
// return groupingQObj
// }, {} as Record<string, GraphQueryObj[]>)
const
stages
:
any
[]
=
[]
// const stages = [
// {
// $match: { $and: [{ __typename: { $in: qObjs.map((_) => _.__typename) } }, gqo.query.match] },
// },
// ...getTraverse,
// { $limit: gqo.query.page?.limit || 15 },
// ]
return
qObjs
.
map
((
qObj
)
=>
qObj
.
traverse
.
reduce
((
resultStages
,
traversingGQObj
)
=>
{
if
(
!
(
traversingGQObj
.
select
.
length
||
traversingGQObj
.
traverse
.
length
))
{
return
resultStages
}
return
[...
resultStages
,
...
stages
]
},
[]
as
any
[])
)
}
src/gql-graph/types.d.ts
View file @
261cbb76
...
...
@@ -3,7 +3,7 @@ import { ObjectID } from 'mongodb'
export
type
ShallowEntity
<
T
>
=
Omit
<
T
,
'
_rel
'
>
export
type
ShallowRelation
<
T
>
=
Omit
<
T
,
'
_obj
'
|
'
_subj
'
>
export
type
GqlType
=
{
_
id
:
string
;
__typename
:
string
}
export
type
GqlType
=
{
id
:
string
;
__typename
:
string
}
export
type
GqlNode
=
GqlType
&
{
_rel
:
any
[]
}
export
type
GqlRelation
=
GqlType
&
{
_obj
:
any
;
_subj
:
any
}
...
...
src/gql/graphql.schema.json
View file @
261cbb76
...
...
@@ -14,7 +14,7 @@
"description"
:
null
,
"fields"
:
[
{
"name"
:
"
_
id"
,
"name"
:
"id"
,
"description"
:
null
,
"args"
:
[],
"type"
:
{
...
...
@@ -63,12 +63,12 @@
},
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"StringMatch"
,
"name"
:
"StringMatch
Input
"
,
"description"
:
null
,
"fields"
:
null
,
"inputFields"
:
[
{
"name"
:
"eq"
,
"name"
:
"
_
eq"
,
"description"
:
null
,
"type"
:
{
"kind"
:
"SCALAR"
,
...
...
@@ -78,7 +78,7 @@
"defaultValue"
:
null
},
{
"name"
:
"gt"
,
"name"
:
"
_
gt"
,
"description"
:
null
,
"type"
:
{
"kind"
:
"SCALAR"
,
...
...
@@ -88,7 +88,7 @@
"defaultValue"
:
null
},
{
"name"
:
"lt"
,
"name"
:
"
_
lt"
,
"description"
:
null
,
"type"
:
{
"kind"
:
"SCALAR"
,
...
...
@@ -114,7 +114,7 @@
},
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"Page
Arg
"
,
"name"
:
"Page
Input
"
,
"description"
:
null
,
"fields"
:
null
,
"inputFields"
:
[
...
...
@@ -187,7 +187,7 @@
},
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"KnowSubjectQuery"
,
"name"
:
"Know
s
SubjectQuery
Input
"
,
"description"
:
null
,
"fields"
:
null
,
"inputFields"
:
[
...
...
@@ -196,7 +196,7 @@
"description"
:
null
,
"type"
:
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"UserQuery"
,
"name"
:
"UserQuery
Input
"
,
"ofType"
:
null
},
"defaultValue"
:
null
...
...
@@ -208,7 +208,7 @@
},
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"KnowObjectQuery"
,
"name"
:
"Know
s
ObjectQuery
Input
"
,
"description"
:
null
,
"fields"
:
null
,
"inputFields"
:
[
...
...
@@ -217,7 +217,7 @@
"description"
:
null
,
"type"
:
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"UserQuery"
,
"name"
:
"UserQuery
Input
"
,
"ofType"
:
null
},
"defaultValue"
:
null
...
...
@@ -229,12 +229,12 @@
},
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"KnowsQuery"
,
"name"
:
"KnowsQuery
Input
"
,
"description"
:
null
,
"fields"
:
null
,
"inputFields"
:
[
{
"name"
:
"and"
,
"name"
:
"
_
and"
,
"description"
:
null
,
"type"
:
{
"kind"
:
"LIST"
,
...
...
@@ -244,7 +244,7 @@
"name"
:
null
,
"ofType"
:
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"KnowsQuery"
,
"name"
:
"KnowsQuery
Input
"
,
"ofType"
:
null
}
}
...
...
@@ -252,7 +252,7 @@
"defaultValue"
:
null
},
{
"name"
:
"or"
,
"name"
:
"
_
or"
,
"description"
:
null
,
"type"
:
{
"kind"
:
"LIST"
,
...
...
@@ -262,7 +262,7 @@
"name"
:
null
,
"ofType"
:
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"KnowsQuery"
,
"name"
:
"KnowsQuery
Input
"
,
"ofType"
:
null
}
}
...
...
@@ -270,12 +270,20 @@
"defaultValue"
:
null
},
{
"name"
:
"
_page
"
,
"name"
:
"
id
"
,
"description"
:
null
,
"type"
:
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"PageArg"
,
"ofType"
:
null
"kind"
:
"LIST"
,
"name"
:
null
,
"ofType"
:
{
"kind"
:
"NON_NULL"
,
"name"
:
null
,
"ofType"
:
{
"kind"
:
"SCALAR"
,
"name"
:
"ID"
,
"ofType"
:
null
}
}
},
"defaultValue"
:
null
}
...
...
@@ -290,7 +298,7 @@
"description"
:
null
,
"fields"
:
[
{
"name"
:
"
_
id"
,
"name"
:
"id"
,
"description"
:
null
,
"args"
:
[],
"type"
:
{
...
...
@@ -314,7 +322,17 @@
"description"
:
null
,
"type"
:
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"KnowSubjectQuery"
,
"name"
:
"KnowsSubjectQueryInput"
,
"ofType"
:
null
},
"defaultValue"
:
null
},
{
"name"
:
"page"
,
"description"
:
null
,
"type"
:
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"PageInput"
,
"ofType"
:
null
},
"defaultValue"
:
null
...
...
@@ -349,7 +367,17 @@
"description"
:
null
,
"type"
:
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"KnowObjectQuery"
,
"name"
:
"KnowsObjectQueryInput"
,
"ofType"
:
null
},
"defaultValue"
:
null
},
{
"name"
:
"page"
,
"description"
:
null
,
"type"
:
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"PageInput"
,
"ofType"
:
null
},
"defaultValue"
:
null
...
...
@@ -421,7 +449,7 @@
},
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"FollowObjectQuery"
,
"name"
:
"FollowObjectQuery
Input
"
,
"description"
:
null
,
"fields"
:
null
,
"inputFields"
:
[
...
...
@@ -430,7 +458,7 @@
"description"
:
null
,
"type"
:
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"UserQuery"
,
"name"
:
"UserQuery
Input
"
,
"ofType"
:
null
},
"defaultValue"
:
null
...
...
@@ -442,7 +470,7 @@
},
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"FollowSubjectQuery"
,
"name"
:
"FollowSubjectQuery
Input
"
,
"description"
:
null
,
"fields"
:
null
,
"inputFields"
:
[
...
...
@@ -451,7 +479,7 @@
"description"
:
null
,
"type"
:
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"UserQuery"
,
"name"
:
"UserQuery
Input
"
,
"ofType"
:
null
},
"defaultValue"
:
null
...
...
@@ -463,12 +491,12 @@
},
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"FollowsQuery"
,
"name"
:
"FollowsQuery
Input
"
,
"description"
:
null
,
"fields"
:
null
,
"inputFields"
:
[
{
"name"
:
"and"
,
"name"
:
"
_
and"
,
"description"
:
null
,
"type"
:
{
"kind"
:
"LIST"
,
...
...
@@ -478,7 +506,7 @@
"name"
:
null
,
"ofType"
:
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"FollowsQuery"
,
"name"
:
"FollowsQuery
Input
"
,
"ofType"
:
null
}
}
...
...
@@ -486,7 +514,7 @@
"defaultValue"
:
null
},
{
"name"
:
"or"
,
"name"
:
"
_
or"
,
"description"
:
null
,
"type"
:
{
"kind"
:
"LIST"
,
...
...
@@ -496,7 +524,7 @@
"name"
:
null
,
"ofType"
:
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"FollowsQuery"
,
"name"
:
"FollowsQuery
Input
"
,
"ofType"
:
null
}
}
...
...
@@ -504,12 +532,20 @@
"defaultValue"
:
null
},
{
"name"
:
"
_page
"
,
"name"
:
"
id
"
,
"description"
:
null
,
"type"
:
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"PageArg"
,
"ofType"
:
null
"kind"
:
"LIST"
,
"name"
:
null
,
"ofType"
:
{
"kind"
:
"NON_NULL"
,
"name"
:
null
,
"ofType"
:
{
"kind"
:
"SCALAR"
,
"name"
:
"ID"
,
"ofType"
:
null
}
}
},
"defaultValue"
:
null
}
...
...
@@ -524,7 +560,7 @@
"description"
:
null
,
"fields"
:
[
{
"name"
:
"
_
id"
,
"name"
:
"id"
,
"description"
:
null
,
"args"
:
[],
"type"
:
{
...
...
@@ -548,7 +584,17 @@
"description"
:
null
,
"type"
:
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"FollowSubjectQuery"
,
"name"
:
"FollowSubjectQueryInput"
,
"ofType"
:
null
},
"defaultValue"
:
null
},
{
"name"
:
"page"
,
"description"
:
null
,
"type"
:
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"PageInput"
,
"ofType"
:
null
},
"defaultValue"
:
null
...
...
@@ -583,7 +629,17 @@
"description"
:
null
,
"type"
:
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"FollowObjectQuery"
,
"name"
:
"FollowObjectQueryInput"
,
"ofType"
:
null
},
"defaultValue"
:
null
},
{
"name"
:
"page"
,
"description"
:
null
,
"type"
:
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"PageInput"
,
"ofType"
:
null
},
"defaultValue"
:
null
...
...
@@ -623,12 +679,12 @@
},
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"UserQuery"
,
"name"
:
"UserQuery
Input
"
,
"description"
:
null
,
"fields"
:
null
,
"inputFields"
:
[
{
"name"
:
"and"
,
"name"
:
"
_
and"
,
"description"
:
null
,
"type"
:
{
"kind"
:
"LIST"
,
...
...
@@ -638,7 +694,7 @@
"name"
:
null
,
"ofType"
:
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"UserQuery"
,
"name"
:
"UserQuery
Input
"
,
"ofType"
:
null
}
}
...
...
@@ -646,7 +702,7 @@
"defaultValue"
:
null
},
{
"name"
:
"or"
,
"name"
:
"
_
or"
,
"description"
:
null
,
"type"
:
{
"kind"
:
"LIST"
,
...
...
@@ -656,7 +712,7 @@
"name"
:
null
,
"ofType"
:
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"UserQuery"
,
"name"
:
"UserQuery
Input
"
,
"ofType"
:
null
}
}
...
...
@@ -664,12 +720,20 @@
"defaultValue"
:
null
},
{
"name"
:
"
_
id"
,
"name"
:
"id"
,
"description"
:
null
,
"type"
:
{
"kind"
:
"SCALAR"
,
"name"
:
"ID"
,
"ofType"
:
null
"kind"
:
"LIST"
,
"name"
:
null
,
"ofType"
:
{
"kind"
:
"NON_NULL"
,
"name"
:
null
,
"ofType"
:
{
"kind"
:
"SCALAR"
,
"name"
:
"ID"
,
"ofType"
:
null
}
}
},
"defaultValue"
:
null
},
...
...
@@ -678,17 +742,7 @@
"description"
:
null
,
"type"
:
{