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
082c4818
Commit
082c4818
authored
Oct 08, 2020
by
aleclofabbro
Browse files
minor readability refactors
parent
0de45aed
Changes
8
Hide whitespace changes
Inline
Side-by-side
src/gql-graph/documentSelection/helpers.ts
0 → 100644
View file @
082c4818
import
{
Field
,
UnionLookupField
}
from
'
../types
'
export
const
isUnionLookupField
=
(
_
:
Field
):
_
is
UnionLookupField
=>
!!
(
_
&&
'
lookups
'
in
_
)
src/gql-graph/
buildD
ocumentSelection.ts
→
src/gql-graph/
d
ocumentSelection
/index
.ts
View file @
082c4818
import
{
DocumentSelection
,
Field
,
GraphQuery
,
GraphQueryObj
,
UnionLookupField
,
ValueField
,
}
from
'
./types
'
}
from
'
../types
'
import
{
isUnionLookupField
}
from
'
./helpers
'
export
const
build
Query
DocumentSelection
=
(
export
const
buildDocumentSelection
Root
=
(
root
:
GraphQuery
|
null
|
undefined
):
DocumentSelection
|
null
|
undefined
=>
{
return
root
&&
buildDocumentSelection
(
root
.
qObj
)
...
...
@@ -68,5 +68,3 @@ const aliasConflictError = (selection: GraphQueryObj, par: GraphQueryObj) => {
console
.
error
(
`A ValueField can't have same alias[
${
selection
.
alias
}
] as a UnionLookupField`
,
par
)
return
new
Error
(
`A ValueField can't have same alias[
${
selection
.
alias
}
] as a UnionLookupField`
)
}
export
const
isUnionLookupField
=
(
_
:
Field
):
_
is
UnionLookupField
=>
!!
(
_
&&
'
lookups
'
in
_
)
src/gql-graph/graph
Qu
er
y
.ts
→
src/gql-graph/graph
qlResolver/help
er
s
.ts
View file @
082c4818
import
{
Path
}
from
'
graphql/jsutils/Path
'
import
{
Context
}
from
'
../gql
'
import
{
Context
}
from
'
../
../
gql
'
import
{
GraphQLResolveInfo
,
GraphQLOutputType
,
...
...
@@ -11,7 +11,7 @@ import {
GraphQLInterfaceType
,
GraphQLSchema
,
}
from
'
graphql
'
import
{
GraphQueryObj
}
from
'
./types
'
import
{
GraphQueryObj
}
from
'
.
.
/types
'
export
const
typeInfo
=
(
schema
:
GraphQLSchema
,
...
...
src/gql-graph/
defaultGraphField
Resolver.ts
→
src/gql-graph/
graphql
Resolver
/index
.ts
View file @
082c4818
import
{
Context
}
from
'
../gql
'
import
{
ResolverFn
}
from
'
../gql/types
'
import
{
ShallowTypeMocks
}
from
'
../gql/shallowTypes
'
import
{
typeInfo
,
getParent
}
from
'
./
graphQu
er
y
'
import
{
GraphQueryObj
,
TraverseRelation
}
from
'
./types
'
import
{
Context
}
from
'
../
../
gql
'
import
{
ResolverFn
}
from
'
../
../
gql/types
'
import
{
ShallowTypeMocks
}
from
'
../
../
gql/shallowTypes
'
import
{
typeInfo
,
getParent
}
from
'
./
help
er
s
'
import
{
GraphQueryObj
,
TraverseRelation
}
from
'
.
.
/types
'
export
function
defaultGraphFieldResolver
():
ResolverFn
<
any
,
any
,
Context
,
any
>
{
return
(
parent
,
args
,
context
,
info
)
=>
{
...
...
src/gql-graph/mongo/buildMongoPipeline.ts
View file @
082c4818
import
{
isUnionLookupField
}
from
'
../documentSelection/helpers
'
import
{
DocumentSelection
}
from
'
../types
'
import
{
isUnionLookupField
}
from
'
../buildDocumentSelection
'
export
const
buildMongoPipeline
=
(
docS
:
DocumentSelection
,
notTop
?:
boolean
)
=>
{
const
lookups
=
[]
as
any
[]
const
project
=
{
__typename
:
true
}
as
Record
<
string
,
any
>
...
...
src/gql/resolvers/query/index.ts
View file @
082c4818
import
{
defaultGraphFieldResolver
}
from
'
../../../gql-graph/
defaultGraphField
Resolver
'
import
{
defaultGraphFieldResolver
}
from
'
../../../gql-graph/
graphql
Resolver
'
import
{
QueryResolvers
}
from
'
../../types
'
export
const
Query
:
QueryResolvers
=
{
...
...
src/gql/resolvers/types/index.ts
View file @
082c4818
import
{
defaultGraphFieldResolver
}
from
'
../../../gql-graph/
defaultGraphField
Resolver
'
import
{
defaultGraphFieldResolver
}
from
'
../../../gql-graph/
graphql
Resolver
'
export
const
Types
=
{
User
:
{
_id
:
defaultGraphFieldResolver
(),
...
...
src/http/index.ts
View file @
082c4818
...
...
@@ -4,7 +4,7 @@ import express from 'express'
import
{
graphql
,
GraphQLSchema
}
from
'
graphql
'
import
{
Context
}
from
'
../gql
'
import
{
buildMongoPipeline
}
from
'
../gql-graph/mongo/buildMongoPipeline
'
import
{
build
Query
DocumentSelection
}
from
'
../gql-graph/
buildD
ocumentSelection
'
import
{
buildDocumentSelection
Root
}
from
'
../gql-graph/
d
ocumentSelection
'
import
{
collection
}
from
'
../mongo/collection
'
type
Cfg
=
{
...
...
@@ -24,7 +24,7 @@ const executor: GraphQLServerOptions['executor'] = async (requestContext) => {
const
res
=
await
graphql
({
...
requestContext
,
contextValue
:
ctx
})
console
.
dir
({
'
executor res
'
:
res
},
{
depth
:
15
})
console
.
dir
({
'
executor $graph
'
:
ctx
},
{
depth
:
15
})
const
documentSelection
=
build
Query
DocumentSelection
(
ctx
.
$graph
)
const
documentSelection
=
buildDocumentSelection
Root
(
ctx
.
$graph
)
console
.
dir
({
'
executor documentSelection
'
:
documentSelection
},
{
depth
:
15
})
if
(
documentSelection
)
{
const
pipeline
=
buildMongoPipeline
(
documentSelection
)
...
...
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