Skip to content

Commit

Permalink
continue
Browse files Browse the repository at this point in the history
  • Loading branch information
Pho Nguyen committed Mar 10, 2021
1 parent 6731b79 commit 0658def
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 27 deletions.
Empty file.
32 changes: 32 additions & 0 deletions src/core/api-builder/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import * as graphql from 'graphql'
import { IApi } from '../metadata'

export interface IApiBuilder {
build(): IApi
}

export abstract class PaginatedApi<Input> {
abstract apiName: string
abstract model: { withContext(context: any): any }

abstract getOutputType(): graphql.GraphQLObjectType

abstract getArgs(): graphql.GraphQLFieldConfigArgumentMap

abstract getQueryObject(input: Input): any

abstract canAccess(): Promise<void>

getApi(): graphql.GraphQLFieldConfig<any, any> {
return {
type: this.getOutputType(),
args: {},
resolve: async (_parent, input: Input, context) => {
await this.canAccess()
return this.model.withContext(context).paginate(
this.getQueryObject(input)
)
},
}
}
}
54 changes: 27 additions & 27 deletions src/core/list-api-builder.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
import { IApiGenerator } from './metadata'
// import { IApiGenerator } from './metadata'

enum ESearchOperation {
EQUAL = '$eq',
}
// enum ESearchOperation {
// EQUAL = '$eq',
// }

interface ISearchableProperty {
fieldName: string
operator: ESearchOperation
required: boolean
}
// interface ISearchableProperty {
// fieldName: string
// operator: ESearchOperation
// required: boolean
// }

class ListAPIBuilder {
private name: string
searchableProps: ISearchableProperty[] = []
// class ListAPIBuilder {
// private name: string
// searchableProps: ISearchableProperty[] = []

from() {
return this
}
// from() {
// return this
// }

setApiName(name: string) {
this.name = name
return this
}
// setApiName(name: string) {
// this.name = name
// return this
// }

add(searchableProp: ISearchableProperty) {
this.searchableProps.push(searchableProp)
return this
}
// add(searchableProp: ISearchableProperty) {
// this.searchableProps.push(searchableProp)
// return this
// }

build(): IApiGenerator | null {
return null
}
}
// build(): IApiGenerator | null {
// return null
// }
// }

0 comments on commit 0658def

Please sign in to comment.