-
Notifications
You must be signed in to change notification settings - Fork 224
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to using GraphQL 15's extensions for join-monster config in a …
…schema GraphQL 15 doesn't let schema authors attach arbitrary properties to schema objects anymore, so join-monster's config style has to change. There's an `extensions` property that works great for this, let's use that!
- Loading branch information
Showing
21 changed files
with
1,313 additions
and
862 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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,88 +1,139 @@ | ||
|
||
import * as graphql from 'graphql' | ||
export type Maybe<T> = null | undefined | T | ||
|
||
// Extend graphql objects and fields | ||
|
||
declare module 'graphql/type/definition' { | ||
type SqlJoin<TContext, TArgs> = (table1: string, table2: string, args: TArgs, context: TContext, sqlASTNode: any) => string | ||
type Where<TContext, TArgs> = (usersTable: string, args: TArgs, context: TContext, sqlASTNode: any) => string | void | ||
type SqlJoin<TContext, TArgs> = ( | ||
table1: string, | ||
table2: string, | ||
args: TArgs, | ||
context: TContext, | ||
sqlASTNode: any | ||
) => string | ||
type Where<TContext, TArgs> = ( | ||
usersTable: string, | ||
args: TArgs, | ||
context: TContext, | ||
sqlASTNode: any | ||
) => string | void | ||
type Order = 'ASC' | 'asc' | 'DESC' | 'desc' | ||
type OrderBy = string | { [key: string]: Order } | ||
type ThunkWithArgsCtx<T, TContext, TArgs> = ((args: TArgs, context: TContext) => T) | T; | ||
type ThunkWithArgsCtx<T, TContext, TArgs> = | ||
| ((args: TArgs, context: TContext) => T) | ||
| T | ||
|
||
export interface GraphQLObjectTypeConfig<TSource, TContext> { | ||
alwaysFetch?: string | ||
sqlTable?: ThunkWithArgsCtx<string, any, TContext> | ||
uniqueKey?: string | string[] | ||
extensions?: Maybe<Readonly<Record<string, any>>> & { | ||
alwaysFetch?: string | ||
sqlTable?: ThunkWithArgsCtx<string, any, TContext> | ||
uniqueKey?: string | string[] | ||
} | ||
} | ||
|
||
export interface GraphQLFieldConfig<TSource, TContext, TArgs> { | ||
jmIgnoreAll?: boolean | ||
jmIgnoreTable?: boolean | ||
junction?: { | ||
include?: ThunkWithArgsCtx<{ | ||
sqlColumn?: string | ||
sqlExpr?: string | ||
sqlDeps?: string | string[] | ||
}, TContext, TArgs> | ||
extensions?: Maybe<Readonly<Record<string, any>>> & { | ||
ignoreAll?: boolean | ||
ignoreTable?: boolean | ||
junction?: { | ||
include?: ThunkWithArgsCtx< | ||
{ | ||
sqlColumn?: string | ||
sqlExpr?: string | ||
sqlDeps?: string | string[] | ||
}, | ||
TContext, | ||
TArgs | ||
> | ||
orderBy?: ThunkWithArgsCtx<OrderBy, TContext, TArgs> | ||
sortKey?: ThunkWithArgsCtx< | ||
{ | ||
order: Order | ||
key: string | string[] | ||
}, | ||
TContext, | ||
TArgs | ||
> | ||
sqlBatch?: { | ||
thisKey: string | ||
parentKey: string | ||
sqlJoin: SqlJoin<TContext, TArgs> | ||
} | ||
sqlJoins?: [SqlJoin<TContext, TArgs>, SqlJoin<TContext, TArgs>] | ||
sqlTable: ThunkWithArgsCtx<string, TContext, TArgs> | ||
uniqueKey?: string | string[] | ||
where?: Where<TContext, TArgs> | ||
} | ||
limit?: ThunkWithArgsCtx<number, any, TContext> | ||
orderBy?: ThunkWithArgsCtx<OrderBy, TContext, TArgs> | ||
sortKey?: ThunkWithArgsCtx<{ | ||
order: Order | ||
key: string | string[] | ||
}, TContext, TArgs> | ||
sortKey?: ThunkWithArgsCtx< | ||
{ | ||
order: Order | ||
key: string | string[] | ||
}, | ||
TContext, | ||
TArgs | ||
> | ||
sqlBatch?: { | ||
thisKey: string | ||
parentKey: string | ||
sqlJoin: SqlJoin<TContext, TArgs> | ||
} | ||
sqlJoins?: [SqlJoin<TContext, TArgs>, SqlJoin<TContext, TArgs>] | ||
sqlTable: ThunkWithArgsCtx<string, TContext, TArgs> | ||
uniqueKey?: string | string[] | ||
sqlColumn?: string | ||
sqlDeps?: string[] | ||
sqlExpr?: ( | ||
table: string, | ||
args: TArgs, | ||
context: TContext, | ||
sqlASTNode: any | ||
) => string | ||
sqlJoin?: SqlJoin<TContext, TArgs> | ||
sqlPaginate?: boolean | ||
where?: Where<TContext, TArgs> | ||
} | ||
limit?: ThunkWithArgsCtx<number, any, TContext> | ||
orderBy?: ThunkWithArgsCtx<OrderBy, TContext, TArgs> | ||
sortKey?: ThunkWithArgsCtx<{ | ||
order: Order | ||
key: string | string[] | ||
}, TContext, TArgs> | ||
sqlBatch?: { | ||
thisKey: string | ||
parentKey: string | ||
} | ||
sqlColumn?: string | ||
sqlDeps?: string[] | ||
sqlExpr?: (table: string, args: TArgs, context: TContext, sqlASTNode: any) => string | ||
sqlJoin?: SqlJoin<TContext, TArgs> | ||
sqlPaginate?: boolean | ||
where?: Where<TContext, TArgs> | ||
} | ||
} | ||
|
||
export interface GraphQLUnionTypeConfig<TSource, TContext> { | ||
sqlTable?: string | ||
uniqueKey?: string | string[] | ||
alwaysFetch?: string | ||
extensions?: Maybe<Readonly<Record<string, any>>> & { | ||
sqlTable?: string | ||
uniqueKey?: string | string[] | ||
alwaysFetch?: string | ||
} | ||
} | ||
|
||
export interface GraphQLInterfaceTypeConfig<TSource, TContext> { | ||
sqlTable?: string | ||
uniqueKey?: string | string[] | ||
alwaysFetch?: string | ||
extensions: Maybe<Readonly<Record<string, any>>> & { | ||
sqlTable?: string | ||
uniqueKey?: string | string[] | ||
alwaysFetch?: string | ||
} | ||
} | ||
|
||
// JoinMonster lib interface | ||
|
||
interface DialectModule { name: string } | ||
interface DialectModule { | ||
name: string | ||
} | ||
|
||
type Dialect = 'pg' | 'oracle' | 'mariadb' | 'mysql' | 'mysql8' | 'sqlite3' | ||
type JoinMonsterOptions = { minify?: boolean, dialect?: Dialect, dialectModule?: DialectModule } | ||
type JoinMonsterOptions = { | ||
minify?: boolean | ||
dialect?: Dialect | ||
dialectModule?: DialectModule | ||
} | ||
|
||
type Rows = any | ||
type DbCallCallback = (sql:string, done: (err?: any, rows?: Rows) => void) => void | ||
type DbCallCallback = ( | ||
sql: string, | ||
done: (err?: any, rows?: Rows) => void | ||
) => void | ||
type DbCallPromise = (sql: string) => Promise<Rows> | ||
type DbCall = DbCallCallback | DbCallPromise | ||
|
||
declare function joinMonster(resolveInfo: any, context: any, dbCall: DbCallCallback | DbCallPromise, options?: JoinMonsterOptions) : Promise<any> | ||
declare function joinMonster( | ||
resolveInfo: any, | ||
context: any, | ||
dbCall: DbCallCallback | DbCallPromise, | ||
options?: JoinMonsterOptions | ||
): Promise<any> | ||
|
||
export default joinMonster |
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
Oops, something went wrong.