-
-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add TypeScript definition files (thanks @toverux)
* chore(package, typescript): add typescript and tslint configuration(s) * feat(typescript): add a few .d.ts files * chore(typescript): mark TS-specific comments as @ts-todo
- Loading branch information
Showing
35 changed files
with
680 additions
and
4 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import { InputTypeComposer, SchemaComposer, TypeComposer } from 'graphql-compose'; | ||
import { Document, Model } from 'mongoose'; | ||
import { ConnectionSortMapOpts } from './resolvers/connection'; | ||
import { | ||
FilterHelperArgsOpts, LimitHelperArgsOpts, RecordHelperArgsOpts, SortHelperArgsOpts, | ||
} from './resolvers/helpers'; | ||
import { PaginationResolverOpts } from './resolvers/pagination'; | ||
|
||
export type TypeConverterOpts = { | ||
schemaComposer?: SchemaComposer<any>, | ||
name?: string, | ||
description?: string, | ||
fields?: { | ||
only?: string[], | ||
remove?: string[], | ||
}, | ||
inputType?: TypeConverterInputTypeOpts, | ||
resolvers?: false | TypeConverterResolversOpts, | ||
}; | ||
|
||
export type TypeConverterInputTypeOpts = { | ||
name?: string, | ||
description?: string, | ||
fields?: { | ||
only?: string[], | ||
remove?: string[], | ||
required?: string[], | ||
}, | ||
}; | ||
|
||
export type TypeConverterResolversOpts = { | ||
findById?: false, | ||
findByIds?: | ||
| false | ||
| { | ||
limit?: LimitHelperArgsOpts | false, | ||
sort?: SortHelperArgsOpts | false, | ||
}, | ||
findOne?: | ||
| false | ||
| { | ||
filter?: FilterHelperArgsOpts | false, | ||
sort?: SortHelperArgsOpts | false, | ||
skip?: false, | ||
}, | ||
findMany?: | ||
| false | ||
| { | ||
filter?: FilterHelperArgsOpts | false, | ||
sort?: SortHelperArgsOpts | false, | ||
limit?: LimitHelperArgsOpts | false, | ||
skip?: false, | ||
}, | ||
updateById?: | ||
| false | ||
| { | ||
record?: RecordHelperArgsOpts | false, | ||
}, | ||
updateOne?: | ||
| false | ||
| { | ||
input?: RecordHelperArgsOpts | false, | ||
filter?: FilterHelperArgsOpts | false, | ||
sort?: SortHelperArgsOpts | false, | ||
skip?: false, | ||
}, | ||
updateMany?: | ||
| false | ||
| { | ||
record?: RecordHelperArgsOpts | false, | ||
filter?: FilterHelperArgsOpts | false, | ||
sort?: SortHelperArgsOpts | false, | ||
limit?: LimitHelperArgsOpts | false, | ||
skip?: false, | ||
}, | ||
removeById?: false, | ||
removeOne?: | ||
| false | ||
| { | ||
filter?: FilterHelperArgsOpts | false, | ||
sort?: SortHelperArgsOpts | false, | ||
}, | ||
removeMany?: | ||
| false | ||
| { | ||
filter?: FilterHelperArgsOpts | false, | ||
}, | ||
createOne?: | ||
| false | ||
| { | ||
record?: RecordHelperArgsOpts | false, | ||
}, | ||
count?: | ||
| false | ||
| { | ||
filter?: FilterHelperArgsOpts | false, | ||
}, | ||
connection?: ConnectionSortMapOpts | false, | ||
pagination?: PaginationResolverOpts | false, | ||
}; | ||
|
||
export function composeWithMongoose( | ||
model: Model<any>, | ||
opts?: TypeConverterOpts): TypeComposer<any>; | ||
|
||
export function prepareFields( | ||
tc: TypeComposer<any>, | ||
opts: { only?: string[], remove?: string[] }): void; | ||
|
||
export function prepareInputFields( | ||
inputTypeComposer: InputTypeComposer, | ||
inputFieldsOpts: { only?: string[], remove?: string[], required?: string[] }): void; | ||
|
||
export function createInputType( | ||
tc: TypeComposer<any>, | ||
inputTypeOpts?: TypeConverterInputTypeOpts): void; | ||
|
||
export function createResolvers<TDocument extends Document>( | ||
model: Model<TDocument>, | ||
tc: TypeComposer<any>, | ||
opts: TypeConverterResolversOpts): void; |
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,6 @@ | ||
import { TypeComposerClass } from 'graphql-compose'; | ||
import { Model } from 'mongoose'; | ||
|
||
export function composeWithMongooseDiscriminators( | ||
baseModel: Model<any>, | ||
opts?: { [opts: string]: any }): TypeComposerClass<any>; |
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,74 @@ | ||
import { EnumTypeComposer, SchemaComposer, TypeComposer } from 'graphql-compose'; | ||
import { GraphQLScalarType } from 'graphql-compose/lib/graphql'; | ||
import { Model, Schema } from 'mongoose'; | ||
|
||
// @ts-todo MongooseSchemaField<any> in the Flow version, MongooseSchemaField isn't there in mongoose's .d.ts | ||
type MongooseFieldT = any; | ||
|
||
type MongooseFieldMapT = { [fieldName: string]: MongooseFieldT }; | ||
type ComposeScalarType = string | GraphQLScalarType; | ||
|
||
type ComposeOutputType = | ||
| TypeComposer<any> | ComposeScalarType | EnumTypeComposer | ||
| [TypeComposer<any> | ComposeScalarType | EnumTypeComposer]; | ||
|
||
export type MongoosePseudoModelT = { | ||
schema: Schema, | ||
}; | ||
|
||
export const ComplexTypes: { | ||
ARRAY: 'ARRAY', | ||
EMBEDDED: 'EMBEDDED', | ||
DOCUMENT_ARRAY: 'DOCUMENT_ARRAY', | ||
ENUM: 'ENUM', | ||
REFERENCE: 'REFERENCE', | ||
SCALAR: 'SCALAR', | ||
MIXED: 'MIXED', | ||
}; | ||
|
||
export function dotPathsToEmbedded(fields: MongooseFieldMapT): MongooseFieldMapT; | ||
|
||
export function getFieldsFromModel(model: Model<any> | MongoosePseudoModelT): MongooseFieldMapT; | ||
|
||
export function convertModelToGraphQL( | ||
model: Model<any> | MongoosePseudoModelT, | ||
typeName: string, | ||
sc?: SchemaComposer<any>): TypeComposer<any>; | ||
|
||
export function convertSchemaToGraphQL( | ||
schema: Schema, | ||
typeName: string, | ||
sc?: SchemaComposer<any>): TypeComposer<any>; | ||
|
||
export function convertFieldToGraphQL( | ||
field: MongooseFieldT, | ||
prefix: string | undefined, | ||
schemaComposer: SchemaComposer<any> | ||
): ComposeOutputType; | ||
|
||
export function deriveComplexType(field: MongooseFieldT): keyof typeof ComplexTypes; | ||
|
||
export function scalarToGraphQL(field: MongooseFieldT): ComposeScalarType; | ||
|
||
export function arrayToGraphQL( | ||
field: MongooseFieldT, | ||
prefix: string | undefined, | ||
schemaComposer: SchemaComposer<any> | ||
): ComposeOutputType; | ||
|
||
export function embeddedToGraphQL( | ||
field: MongooseFieldT, | ||
prefix: string | undefined, | ||
schemaComposer: SchemaComposer<any>): TypeComposer<any>; | ||
|
||
export function enumToGraphQL( | ||
field: MongooseFieldT, | ||
prefix: string | undefined, | ||
schemaComposer: SchemaComposer<any>): EnumTypeComposer; | ||
|
||
export function documentArrayToGraphQL( | ||
field: MongooseFieldT, | ||
prefix: string | undefined, | ||
schemaComposer: SchemaComposer<any>): [TypeComposer<any>]; | ||
|
||
export function referenceToGraphQL(field: MongooseFieldT): ComposeScalarType; |
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,10 @@ | ||
import { composeWithMongoose } from './composeWithMongoose'; | ||
import { composeWithMongooseDiscriminators } from './composeWithMongooseDiscriminators'; | ||
import GraphQLMongoID from './types/mongoid'; | ||
|
||
export default composeWithMongoose; | ||
|
||
export * from './fieldsConverter'; | ||
// @ts-todo export * from './discriminators'; // untyped yet | ||
|
||
export { composeWithMongoose, composeWithMongooseDiscriminators, GraphQLMongoID }; |
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,21 @@ | ||
import { Resolver, TypeComposer } from 'graphql-compose'; | ||
// import { ConnectionSortMapOpts } from 'graphql-compose-connection'; | ||
import { Model } from 'mongoose'; | ||
import { IndexT } from '../utils'; | ||
|
||
// @ts-todo The ConnectionSortMapOpts is not available yet since graphql-compose-connection doesn't have types for now, | ||
// fallback to a simple object. | ||
export type ConnectionSortMapOpts = { [opt: string]: any }; | ||
|
||
export default function connection( | ||
model: Model<any>, | ||
tc: TypeComposer<any>, | ||
opts?: ConnectionSortMapOpts): Resolver<any, any> | undefined; | ||
|
||
export function prepareCursorQuery( | ||
rawQuery: object, | ||
cursorData: object, | ||
indexKeys: string[], | ||
indexData: IndexT, | ||
nextOper: '$gt' | '$lt', | ||
prevOper: '$lt' | '$gt'): void; |
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,8 @@ | ||
import { Resolver, TypeComposer } from 'graphql-compose'; | ||
import { Model } from 'mongoose'; | ||
import { GenResolverOpts } from './index'; | ||
|
||
export default function count( | ||
model: Model<any>, | ||
tc: TypeComposer<any>, | ||
opts?: GenResolverOpts): Resolver<any, any>; |
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,8 @@ | ||
import { Resolver, TypeComposer } from 'graphql-compose'; | ||
import { Model } from 'mongoose'; | ||
import { GenResolverOpts } from './index'; | ||
|
||
export default function createOne( | ||
model: Model<any>, | ||
tc: TypeComposer<any>, | ||
opts?: GenResolverOpts): Resolver<any, any>; |
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,8 @@ | ||
import { Resolver, TypeComposer } from 'graphql-compose'; | ||
import { Model } from 'mongoose'; | ||
import { GenResolverOpts } from './index'; | ||
|
||
export default function findById( | ||
model: Model<any>, | ||
tc: TypeComposer<any>, | ||
opts?: GenResolverOpts): Resolver<any, any>; |
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,8 @@ | ||
import { Resolver, TypeComposer } from 'graphql-compose'; | ||
import { Model } from 'mongoose'; | ||
import { GenResolverOpts } from './index'; | ||
|
||
export default function findByIds( | ||
model: Model<any>, | ||
tc: TypeComposer<any>, | ||
opts?: GenResolverOpts): Resolver<any, any>; |
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,8 @@ | ||
import { Resolver, TypeComposer } from 'graphql-compose'; | ||
import { Model } from 'mongoose'; | ||
import { GenResolverOpts } from './index'; | ||
|
||
export default function findMany( | ||
model: Model<any>, | ||
tc: TypeComposer<any>, | ||
opts?: GenResolverOpts): Resolver<any, any>; |
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,8 @@ | ||
import { Resolver, TypeComposer } from 'graphql-compose'; | ||
import { Model } from 'mongoose'; | ||
import { GenResolverOpts } from './index'; | ||
|
||
export default function findOne( | ||
model: Model<any>, | ||
tc: TypeComposer<any>, | ||
opts?: GenResolverOpts): Resolver<any, any>; |
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,22 @@ | ||
import { ComposeFieldConfigArgumentMap, TypeComposer } from 'graphql-compose'; | ||
import { Model } from 'mongoose'; | ||
import { ExtendedResolveParams } from '../index'; | ||
import { FilterOperatorsOpts } from './filterOperators'; | ||
|
||
export type FilterHelperArgsOpts = { | ||
filterTypeName?: string, | ||
isRequired?: boolean, | ||
onlyIndexed?: boolean, | ||
requiredFields?: string | string[], | ||
operators?: FilterOperatorsOpts | false, | ||
removeFields?: string | string[], | ||
}; | ||
|
||
export function getFilterHelperArgOptsMap(): Partial<Record<keyof FilterHelperArgsOpts, string | string[]>>; | ||
|
||
export function filterHelperArgs( | ||
typeComposer: TypeComposer<any>, | ||
model: Model<any>, | ||
opts?: FilterHelperArgsOpts): ComposeFieldConfigArgumentMap; | ||
|
||
export function filterHelper(resolveParams: ExtendedResolveParams): void; |
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,21 @@ | ||
import { InputTypeComposer } from 'graphql-compose'; | ||
import { Model } from 'mongoose'; | ||
import { ExtendedResolveParams } from '../index'; | ||
import { FilterHelperArgsOpts } from './filter'; | ||
|
||
export type FilterOperatorNames = 'gt' | 'gte' | 'lt' | 'lte' | 'ne' | 'in[]' | 'nin[]'; | ||
|
||
export const OPERATORS_FIELDNAME: string; | ||
|
||
export type FilterOperatorsOpts = { | ||
[fieldName: string]: FilterOperatorNames[] | false, | ||
}; | ||
|
||
export function addFilterOperators( | ||
itc: InputTypeComposer, | ||
model: Model<any>, | ||
opts: FilterHelperArgsOpts): void; | ||
|
||
export function processFilterOperators( | ||
filter: object, | ||
resolveParams: ExtendedResolveParams): void; |
Oops, something went wrong.