Commit 082c4818 authored by aleclofabbro's avatar aleclofabbro
Browse files

minor readability refactors

parent 0de45aed
import { Field, UnionLookupField } from '../types'
export const isUnionLookupField = (_: Field): _ is UnionLookupField => !!(_ && 'lookups' in _)
import {
DocumentSelection,
Field,
GraphQuery,
GraphQueryObj,
UnionLookupField,
ValueField,
} from './types'
} from '../types'
import { isUnionLookupField } from './helpers'
export const buildQueryDocumentSelection = (
export const buildDocumentSelectionRoot = (
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 _)
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,
......
import { Context } from '../gql'
import { ResolverFn } from '../gql/types'
import { ShallowTypeMocks } from '../gql/shallowTypes'
import { typeInfo, getParent } from './graphQuery'
import { GraphQueryObj, TraverseRelation } from './types'
import { Context } from '../../gql'
import { ResolverFn } from '../../gql/types'
import { ShallowTypeMocks } from '../../gql/shallowTypes'
import { typeInfo, getParent } from './helpers'
import { GraphQueryObj, TraverseRelation } from '../types'
export function defaultGraphFieldResolver(): ResolverFn<any, any, Context, any> {
return (parent, args, context, info) => {
......
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>
......
import { defaultGraphFieldResolver } from '../../../gql-graph/defaultGraphFieldResolver'
import { defaultGraphFieldResolver } from '../../../gql-graph/graphqlResolver'
import { QueryResolvers } from '../../types'
export const Query: QueryResolvers = {
......
import { defaultGraphFieldResolver } from '../../../gql-graph/defaultGraphFieldResolver'
import { defaultGraphFieldResolver } from '../../../gql-graph/graphqlResolver'
export const Types = {
User: {
_id: defaultGraphFieldResolver(),
......
......@@ -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 { buildQueryDocumentSelection } from '../gql-graph/buildDocumentSelection'
import { buildDocumentSelectionRoot } from '../gql-graph/documentSelection'
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 = buildQueryDocumentSelection(ctx.$graph)
const documentSelection = buildDocumentSelectionRoot(ctx.$graph)
console.dir({ 'executor documentSelection': documentSelection }, { depth: 15 })
if (documentSelection) {
const pipeline = buildMongoPipeline(documentSelection)
......
Markdown is supported
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