graphql-compose / graphql-compose-mongoose

Mongoose model converter to GraphQL types with resolvers for graphql-compose https://github.com/nodkz/graphql-compose
MIT License
708 stars 94 forks source link

Not compatible with mongoose 5.11 in typescript #307

Closed danez closed 3 years ago

danez commented 3 years ago

The new typescript types of mongoose in 5.11 are not compatible with the latest version of graphql-compose-mongoose.

when updating mongoose and removing @types/mongoose in this project the following errors appear:

$ tsc -p ./tsconfig.build.json
src/resolvers/helpers/validate.ts:23:18 - error TS2769: No overload matches this call.
  Overload 1 of 4, '(pathsToValidate?: string[] | undefined, options?: any): Promise<void>', gave the following error.
    Argument of type '(value?: ValidationError | PromiseLike<ValidationError | null> | null | undefined) => void' is not assignable to parameter of type 'string[]'.
      Type '(value?: ValidationError | PromiseLike<ValidationError | null> | null | undefined) => void' is missing the following properties from type 'string[]': pop, push, concat, join, and 25 more.
  Overload 2 of 4, '(callback: (err: CallbackError) => void): void', gave the following error.
    Argument of type '(value?: ValidationError | PromiseLike<ValidationError | null> | null | undefined) => void' is not assignable to parameter of type '(err: CallbackError) => void'.
      Types of parameters 'value' and 'err' are incompatible.
        Type 'CallbackError' is not assignable to type 'ValidationError | PromiseLike<ValidationError | null> | null | undefined'.
          Type 'NativeError' is not assignable to type 'ValidationError | PromiseLike<ValidationError | null> | null | undefined'.
            Property 'errors' is missing in type 'NativeError' but required in type 'ValidationError'.

23     doc.validate(resolve);
                    ~~~~~~~

  node_modules/mongoose/index.d.ts:2595:7
    2595       errors: { [path: string]: ValidatorError | CastError };
               ~~~~~~
    'errors' is declared here.

src/resolvers/index.ts:44:10 - error TS2314: Generic type 'Query<ResultType, DocType>' requires 2 type argument(s).

44   query: Query<any>;
            ~~~~~~~~~~

src/resolvers/index.ts:46:25 - error TS2314: Generic type 'Query<ResultType, DocType>' requires 2 type argument(s).

46   beforeQuery?: (query: Query<any>, rp: ExtendedResolveParams<TDoc>) => Promise<any>;
                           ~~~~~~~~~~

src/resolvers/removeMany.ts:86:7 - error TS2578: Unused '@ts-expect-error' directive.

86       // @ts-expect-error
         ~~~~~~~~~~~~~~~~~~~

src/resolvers/removeMany.ts:88:9 - error TS2578: Unused '@ts-expect-error' directive.

88         // @ts-expect-error
           ~~~~~~~~~~~~~~~~~~~

src/resolvers/updateMany.ts:121:7 - error TS2578: Unused '@ts-expect-error' directive.

121       // @ts-expect-error
          ~~~~~~~~~~~~~~~~~~~

src/resolvers/updateMany.ts:123:9 - error TS2578: Unused '@ts-expect-error' directive.

123         // @ts-expect-error
            ~~~~~~~~~~~~~~~~~~~

Found 7 errors.

Same happens when I try to use mongoose and graphql-composer-mongoose in my projects.

nodkz commented 3 years ago

Thanks for reporting. Fixed in master. Please check a new package version which should be published in a couple of minutes.

danez commented 3 years ago

Thanks for the quick response

yurtaev commented 3 years ago

@danez Hello. Could you help me. What version of @types/mongoose are you using?

I'm getting errors for all version of @types/mongoose@(5.11|5.10|5.7|etc...)

Errors: ``` node_modules/graphql-compose-mongoose/lib/resolvers/helpers/aliases.d.ts:10:89 - error TS2707: Generic type 'Schema' requires between 0 and 1 type arguments. 10 export declare function prepareNestedAliases(schema: Schema, preparedAliases?: Map, undefined>, NestedAliasesMap | undefined>): NestedAliasesMap | undefined; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ node_modules/graphql-compose-mongoose/lib/resolvers/index.d.ts:40:12 - error TS2314: Generic type 'Query' requires 1 type argument(s). 40 query: Query; ~~~~~~~~~~~~~~~ node_modules/graphql-compose-mongoose/lib/resolvers/index.d.ts:44:27 - error TS2314: Generic type 'Query' requires 1 type argument(s). 44 beforeQuery?: (query: Query, rp: ExtendedResolveParams) => Promise; ~~~~~~~~~~~~~~~ Found 3 errors. ```

I can't upgrade graphql-compose-mongoose@9.0.1 because 9.1.x has incompatible typings with @types/mongoose.

nodkz commented 3 years ago

@yurtaev mongoose from some v5 version has its ows typedefs.

Try to update mongoose and remove @types/mongoose.

yurtaev commented 3 years ago

@nodkz 🤦 yep, you're right. Thanks.