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
6181a1b3
Commit
6181a1b3
authored
Oct 05, 2020
by
aleclofabbro
Browse files
there you go
parent
ef3c0200
Changes
8
Hide whitespace changes
Inline
Side-by-side
graphql/schema.graphql
View file @
6181a1b3
...
...
@@ -14,66 +14,81 @@ input PageArg {
after
:
ID
}
# Knows
union
Knower
=
User
union
Knowable
=
User
input
KnowsFilter
{
and
:
[
KnowsFilter
!]
or
:
[
KnowsFilter
!]
_subj
:
[
UserFilter
!]
_obj
:
[
UserFilter
!]
input
KnowSubjectQuery
{
User
:
UserQuery
}
input
KnowObjectQuery
{
User
:
UserQuery
}
input
KnowsQuery
{
and
:
[
KnowsQuery
!]
or
:
[
KnowsQuery
!]
_page
:
PageArg
}
type
Knows
implements
Glyph
{
_id
:
ID
!
_subj
:
[
Knower
!]!
_obj
:
[
Knowable
!]!
_subj
(
query
:
KnowSubjectQuery
)
:
[
Knower
!]!
_obj
(
query
:
KnowObjectQuery
)
:
[
Knowable
!]!
}
# Follows
union
Follower
=
User
union
Followable
=
User
input
FollowsFilter
{
and
:
[
FollowsFilter
!]
or
:
[
FollowsFilter
!]
_subj
:
[
UserFilter
!]
_obj
:
[
UserFilter
!]
input
FollowObjectQuery
{
User
:
UserQuery
}
input
FollowSubjectQuery
{
User
:
UserQuery
}
input
FollowsQuery
{
and
:
[
FollowsQuery
!]
or
:
[
FollowsQuery
!]
_page
:
PageArg
}
type
Follows
implements
Glyph
{
_id
:
ID
!
_subj
:
[
Follower
!]!
_obj
:
[
Followable
!]!
_subj
(
query
:
FollowSubjectQuery
)
:
[
Follower
!]!
_obj
(
query
:
FollowObjectQuery
)
:
[
Followable
!]!
}
input
UserFilter
{
and
:
[
UserFilter
!]
or
:
[
UserFilter
!]
# User
input
UserQuery
{
and
:
[
UserQuery
!]
or
:
[
UserQuery
!]
_id
:
ID
username
:
StringMatch
_rel
:
[
UserRelationFilter
!]
_page
:
PageArg
}
input
UserRelationFilter
{
alias
:
String
!
f
ollows
:
Follows
Filt
er
k
nows
:
Knows
Filt
er
input
UserRelationQuery
{
F
ollows
:
Follows
Qu
er
y
K
nows
:
Knows
Qu
er
y
}
union
UserRelation
=
Knows
|
Follows
type
User
implements
Glyph
{
_id
:
ID
!
_rel
(
page
:
PageArg
):
[
UserRelation
!]!
_rel
(
query
:
UserRelationQuery
):
[
UserRelation
!]!
username
:
String
!
}
# Main
type
Query
{
user
(
match
:
User
Filt
er
):
[
User
!]!
@
graphEntry
user
(
query
:
User
Qu
er
y
):
[
User
!]!
@
graphEntry
da
:
Query
!
}
input
UserInput
{
input
Create
UserInput
{
username
:
String
!
}
type
Mutation
{
createUser
(
user
:
UserInput
!):
User
!
createUser
(
user
:
Create
UserInput
!):
User
!
}
enum
Role
{
...
...
src/gql/graphql.schema.json
View file @
6181a1b3
...
...
@@ -187,48 +187,54 @@
},
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"Know
sFilt
er"
,
"name"
:
"Know
SubjectQu
er
y
"
,
"description"
:
null
,
"fields"
:
null
,
"inputFields"
:
[
{
"name"
:
"
and
"
,
"name"
:
"
User
"
,
"description"
:
null
,
"type"
:
{
"kind"
:
"LIST"
,
"name"
:
null
,
"ofType"
:
{
"kind"
:
"NON_NULL"
,
"name"
:
null
,
"ofType"
:
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"KnowsFilter"
,
"ofType"
:
null
}
}
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"UserQuery"
,
"ofType"
:
null
},
"defaultValue"
:
null
},
}
],
"interfaces"
:
null
,
"enumValues"
:
null
,
"possibleTypes"
:
null
},
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"KnowObjectQuery"
,
"description"
:
null
,
"fields"
:
null
,
"inputFields"
:
[
{
"name"
:
"
o
r"
,
"name"
:
"
Use
r"
,
"description"
:
null
,
"type"
:
{
"kind"
:
"LIST"
,
"name"
:
null
,
"ofType"
:
{
"kind"
:
"NON_NULL"
,
"name"
:
null
,
"ofType"
:
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"KnowsFilter"
,
"ofType"
:
null
}
}
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"UserQuery"
,
"ofType"
:
null
},
"defaultValue"
:
null
},
}
],
"interfaces"
:
null
,
"enumValues"
:
null
,
"possibleTypes"
:
null
},
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"KnowsQuery"
,
"description"
:
null
,
"fields"
:
null
,
"inputFields"
:
[
{
"name"
:
"
_subj
"
,
"name"
:
"
and
"
,
"description"
:
null
,
"type"
:
{
"kind"
:
"LIST"
,
...
...
@@ -238,7 +244,7 @@
"name"
:
null
,
"ofType"
:
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"
UserFilt
er"
,
"name"
:
"
KnowsQu
er
y
"
,
"ofType"
:
null
}
}
...
...
@@ -246,7 +252,7 @@
"defaultValue"
:
null
},
{
"name"
:
"
_obj
"
,
"name"
:
"
or
"
,
"description"
:
null
,
"type"
:
{
"kind"
:
"LIST"
,
...
...
@@ -256,7 +262,7 @@
"name"
:
null
,
"ofType"
:
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"
UserFilt
er"
,
"name"
:
"
KnowsQu
er
y
"
,
"ofType"
:
null
}
}
...
...
@@ -302,7 +308,18 @@
{
"name"
:
"_subj"
,
"description"
:
null
,
"args"
:
[],
"args"
:
[
{
"name"
:
"query"
,
"description"
:
null
,
"type"
:
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"KnowSubjectQuery"
,
"ofType"
:
null
},
"defaultValue"
:
null
}
],
"type"
:
{
"kind"
:
"NON_NULL"
,
"name"
:
null
,
...
...
@@ -326,7 +343,18 @@
{
"name"
:
"_obj"
,
"description"
:
null
,
"args"
:
[],
"args"
:
[
{
"name"
:
"query"
,
"description"
:
null
,
"type"
:
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"KnowObjectQuery"
,
"ofType"
:
null
},
"defaultValue"
:
null
}
],
"type"
:
{
"kind"
:
"NON_NULL"
,
"name"
:
null
,
...
...
@@ -393,48 +421,54 @@
},
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"Follow
sFilt
er"
,
"name"
:
"Follow
ObjectQu
er
y
"
,
"description"
:
null
,
"fields"
:
null
,
"inputFields"
:
[
{
"name"
:
"
and
"
,
"name"
:
"
User
"
,
"description"
:
null
,
"type"
:
{
"kind"
:
"LIST"
,
"name"
:
null
,
"ofType"
:
{
"kind"
:
"NON_NULL"
,
"name"
:
null
,
"ofType"
:
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"FollowsFilter"
,
"ofType"
:
null
}
}
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"UserQuery"
,
"ofType"
:
null
},
"defaultValue"
:
null
},
}
],
"interfaces"
:
null
,
"enumValues"
:
null
,
"possibleTypes"
:
null
},
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"FollowSubjectQuery"
,
"description"
:
null
,
"fields"
:
null
,
"inputFields"
:
[
{
"name"
:
"
o
r"
,
"name"
:
"
Use
r"
,
"description"
:
null
,
"type"
:
{
"kind"
:
"LIST"
,
"name"
:
null
,
"ofType"
:
{
"kind"
:
"NON_NULL"
,
"name"
:
null
,
"ofType"
:
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"FollowsFilter"
,
"ofType"
:
null
}
}
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"UserQuery"
,
"ofType"
:
null
},
"defaultValue"
:
null
},
}
],
"interfaces"
:
null
,
"enumValues"
:
null
,
"possibleTypes"
:
null
},
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"FollowsQuery"
,
"description"
:
null
,
"fields"
:
null
,
"inputFields"
:
[
{
"name"
:
"
_subj
"
,
"name"
:
"
and
"
,
"description"
:
null
,
"type"
:
{
"kind"
:
"LIST"
,
...
...
@@ -444,7 +478,7 @@
"name"
:
null
,
"ofType"
:
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"
UserFilt
er"
,
"name"
:
"
FollowsQu
er
y
"
,
"ofType"
:
null
}
}
...
...
@@ -452,7 +486,7 @@
"defaultValue"
:
null
},
{
"name"
:
"
_obj
"
,
"name"
:
"
or
"
,
"description"
:
null
,
"type"
:
{
"kind"
:
"LIST"
,
...
...
@@ -462,7 +496,7 @@
"name"
:
null
,
"ofType"
:
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"
UserFilt
er"
,
"name"
:
"
FollowsQu
er
y
"
,
"ofType"
:
null
}
}
...
...
@@ -508,7 +542,18 @@
{
"name"
:
"_subj"
,
"description"
:
null
,
"args"
:
[],
"args"
:
[
{
"name"
:
"query"
,
"description"
:
null
,
"type"
:
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"FollowSubjectQuery"
,
"ofType"
:
null
},
"defaultValue"
:
null
}
],
"type"
:
{
"kind"
:
"NON_NULL"
,
"name"
:
null
,
...
...
@@ -532,7 +577,18 @@
{
"name"
:
"_obj"
,
"description"
:
null
,
"args"
:
[],
"args"
:
[
{
"name"
:
"query"
,
"description"
:
null
,
"type"
:
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"FollowObjectQuery"
,
"ofType"
:
null
},
"defaultValue"
:
null
}
],
"type"
:
{
"kind"
:
"NON_NULL"
,
"name"
:
null
,
...
...
@@ -567,7 +623,7 @@
},
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"User
Filt
er"
,
"name"
:
"User
Qu
er
y
"
,
"description"
:
null
,
"fields"
:
null
,
"inputFields"
:
[
...
...
@@ -582,7 +638,7 @@
"name"
:
null
,
"ofType"
:
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"User
Filt
er"
,
"name"
:
"User
Qu
er
y
"
,
"ofType"
:
null
}
}
...
...
@@ -600,7 +656,7 @@
"name"
:
null
,
"ofType"
:
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"User
Filt
er"
,
"name"
:
"User
Qu
er
y
"
,
"ofType"
:
null
}
}
...
...
@@ -627,24 +683,6 @@
},
"defaultValue"
:
null
},
{
"name"
:
"_rel"
,
"description"
:
null
,
"type"
:
{
"kind"
:
"LIST"
,
"name"
:
null
,
"ofType"
:
{
"kind"
:
"NON_NULL"
,
"name"
:
null
,
"ofType"
:
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"UserRelationFilter"
,
"ofType"
:
null
}
}
},
"defaultValue"
:
null
},
{
"name"
:
"_page"
,
"description"
:
null
,
...
...
@@ -662,40 +700,26 @@
},
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"UserRelation
Filt
er"
,
"name"
:
"UserRelation
Qu
er
y
"
,
"description"
:
null
,
"fields"
:
null
,
"inputFields"
:
[
{
"name"
:
"alias"
,
"description"
:
null
,
"type"
:
{
"kind"
:
"NON_NULL"
,
"name"
:
null
,
"ofType"
:
{
"kind"
:
"SCALAR"
,
"name"
:
"String"
,
"ofType"
:
null
}
},
"defaultValue"
:
null
},
{
"name"
:
"follows"
,
"name"
:
"Follows"
,
"description"
:
null
,
"type"
:
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"Follows
Filt
er"
,
"name"
:
"Follows
Qu
er
y
"
,
"ofType"
:
null
},
"defaultValue"
:
null
},
{
"name"
:
"
k
nows"
,
"name"
:
"
K
nows"
,
"description"
:
null
,
"type"
:
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"Knows
Filt
er"
,
"name"
:
"Knows
Qu
er
y
"
,
"ofType"
:
null
},
"defaultValue"
:
null
...
...
@@ -752,11 +776,11 @@
"description"
:
null
,
"args"
:
[
{
"name"
:
"
page
"
,
"name"
:
"
query
"
,
"description"
:
null
,
"type"
:
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"
PageArg
"
,
"name"
:
"
UserRelationQuery
"
,
"ofType"
:
null
},
"defaultValue"
:
null
...
...
@@ -820,11 +844,11 @@
"description"
:
null
,
"args"
:
[
{
"name"
:
"
match
"
,
"name"
:
"
query
"
,
"description"
:
null
,
"type"
:
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"User
Filt
er"
,
"name"
:
"User
Qu
er
y
"
,
"ofType"
:
null
},
"defaultValue"
:
null
...
...
@@ -874,7 +898,7 @@
},
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"UserInput"
,
"name"
:
"
Create
UserInput"
,
"description"
:
null
,
"fields"
:
null
,
"inputFields"
:
[
...
...
@@ -914,7 +938,7 @@
"name"
:
null
,
"ofType"
:
{
"kind"
:
"INPUT_OBJECT"
,
"name"
:
"UserInput"
,
"name"
:
"
Create
UserInput"
,
"ofType"
:
null
}
},
...
...
src/gql/resolvers/query/index.ts
View file @
6181a1b3
...
...
@@ -5,6 +5,7 @@ import { defaultGraphFieldResolver } from '../types'
export
const
Query
:
QueryResolvers
=
{
// user: defaultGraphEntry<'user'>('User'),
da
:
defaultGraphFieldResolver
(),
user
:
defaultGraphFieldResolver
(),
}
...
...
src/gql/resolvers/types/index.ts
View file @
6181a1b3
...
...
@@ -10,6 +10,7 @@ import {
}
from
'
graphql
'
import
{
Context
}
from
'
../..
'
import
{
getParent
}
from
'
../../../mongo/helpers/graphQuery
'
import
{
GraphQueryObj
}
from
'
../../../mongo/types
'
import
{
typeInfo
}
from
'
../../helpers/info
'
import
{
ResolverFn
,
Resolvers
,
TypeResolveFn
}
from
'
../../types
'
export
const
Types
=
{
...
...
@@ -33,48 +34,40 @@ export const Types = {
export
function
defaultGraphFieldResolver
():
ResolverFn
<
any
,
any
,
Context
,
any
>
{
return
(
parent
,
args
,
context
,
info
)
=>
{
if
(
!
context
.
$graph
)
{
// throw new Error(`defaultFieldResolver no context.$graph`)
context
.
$graph
=
{
traverse
:
[],
__typename
:
'
Query
'
,
alias
:
'
Query
'
,
limit
:
-
1
,
match
:
[],
select
:
[],
qObj
:
{
typename
:
'
Query
'
,
query
:
undefined
,
traverse
:
[],
alias
:
'
Query
'
,
select
:
[],
},
}
}
const
{
fieldName
,
parentType
,
returnType
}
=
info
const
{
isList
,
isNullable
,
objs
}
=
typeInfo
(
returnType
)
const
__typenames
=
objs
.
map
((
_
)
=>
_
.
name
)
const
isTop
=
!
info
.
path
.
prev
// if (isTop) {
// // throw new Error(`defaultFieldResolver no context.$graph`)
// context.$graph.traverse.push({
// __typenames,
// limit: 100000,
// match: [],
// traverse: [],
// alias: `${info.path.key}`,
// })
// }
console
.
log
(
`defaultFieldResolver `
,
parent
,
parentType
.
name
,
fieldName
)
const
parentQ
=
getParent
(
info
,
context
,
info
.
parentType
.
name
)
const
parentQ
=
getParent
(
info
,
context
)
console
.
log
(
`defaultFieldResolver `
,
{
parent
,
parentTypeName
:
parentType
.
name
,
fieldName
,
path
:
info
.
path
,
parentQ
,
})
if
(
!
parentQ
)
{
throw
new
Error
(
'
defaultFieldResolver no parentQ
'
)
}
if
(
isTop
||
[
'
_rel
'
,
'
_subj
'
,
'
_obj
'
].
includes
(
fieldName
))
{
const
__typenames
=
objs
.
map
((
_
)
=>
_
.
name
)
parentQ
.
traverse
.
push
(
...
__typenames
.
map
((
__typename
)
=>
({
limit
:
500
,