-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Pho Nguyen
committed
Mar 10, 2021
1 parent
6731b79
commit 0658def
Showing
3 changed files
with
59 additions
and
27 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
) | ||
}, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
// } | ||
// } |