kaievns / graphql-mock

A client side GraphQL mocking library
61 stars 15 forks source link

Typescript error #12

Closed jonoirwinrsa closed 6 years ago

jonoirwinrsa commented 6 years ago

Hi there I'm getting an error compiling typescript that I can't quite figure out.

I assumed that the issue was from /graphql-mock/dist/client.d.ts mutate<T>(options: MutationOptions<T>): Promise<FetchResult<T, any>> not being the same as /apollo-client/ApolloClient.d.ts mutate<T>(options: MutationOptions<T>): Promise<FetchResult<T>>

However updating that doesn't work for me. Removing the entire mutate line from graphql-mock/dist/client.d.ts makes it compile but isn't ideal.

Full error message:

(12,5): Property 'mutate' in type 'MockClient' is not assignable to the same property in base type 'ApolloClient<NormalizedCacheObject>'.
  Type '<T>(options: MutationOptions<T>) => Promise<FetchResult<T, any>>' is not assignable to type '<T>(options: MutationOptions<T>) => Promise<FetchResult<T, Record<string, any>>>'.
    Type 'Promise<FetchResult<T, any>>' is not assignable to type 'Promise<FetchResult<T, Record<string, any>>>'.
      Type 'FetchResult<T, any>' is not assignable to type 'FetchResult<T, Record<string, any>>'.
        Type 'FetchResult<T, any>' is not assignable to type 'ExecutionResult'.
          Types of property 'errors' are incompatible.
            Type 'GraphQLError[] | undefined' is not assignable to type 'ReadonlyArray<GraphQLError> | undefined'.
              Type 'GraphQLError[]' is not assignable to type 'ReadonlyArray<GraphQLError> | undefined'.
                Type 'GraphQLError[]' is not assignable to type 'ReadonlyArray<GraphQLError>'.
                  Types of property 'flatMap' are incompatible.
                    Type '<U, This = undefined>(callback: (this: This, value: GraphQLError, index: number, array: GraphQLEr...' is not assignable to type '<U, This = undefined>(callback: (this: This, value: GraphQLError, index: number, array: GraphQLEr...'. Two different types with this name exist, but they are unrelated.
                      Types of parameters 'callback' and 'callback' are incompatible.
                        Types of parameters 'value' and 'value' are incompatible.
                          Type 'GraphQLError' is not assignable to type 'GraphQLError'. Two different types with this name exist, but they are unrelated.
                            Property 'locations' is optional in type 'GraphQLError' but required in type 'GraphQLError'.

Package Versions

"typescript": "^2.8.3"
"graphql-mock": "^1.0.2",
"apollo-boost": "0.1.6",
kaievns commented 6 years ago

Hey Jonathan, thank you for letting me know about the issue.

Could you maybe create me a little code snippet so i could reproduce the issue and patch it up quickly for you?

On 18 May 2018, at 5:28 pm, Jonathan Irwin notifications@github.com wrote:

Hi there I'm getting an error compiling typescript that I can't quite figure out.

I assumed that the issue was from /graphql-mock/dist/client.d.ts mutate(options: MutationOptions): Promise<FetchResult<T, any>> not being the same as /apollo-client/ApolloClient.d.ts mutate(options: MutationOptions): Promise<FetchResult>

However updating that doesn't work for me. Removing the entire mutate line from graphql-mock/dist/client.d.ts makes it compile but isn't ideal.

Full error message:

(12,5): Property 'mutate' in type 'MockClient' is not assignable to the same property in base type 'ApolloClient'. Type '(options: MutationOptions) => Promise<FetchResult<T, any>>' is not assignable to type '(options: MutationOptions) => Promise<FetchResult<T, Record<string, any>>>'. Type 'Promise<FetchResult<T, any>>' is not assignable to type 'Promise<FetchResult<T, Record<string, any>>>'. Type 'FetchResult<T, any>' is not assignable to type 'FetchResult<T, Record<string, any>>'. Type 'FetchResult<T, any>' is not assignable to type 'ExecutionResult'. Types of property 'errors' are incompatible. Type 'GraphQLError[] | undefined' is not assignable to type 'ReadonlyArray | undefined'. Type 'GraphQLError[]' is not assignable to type 'ReadonlyArray | undefined'. Type 'GraphQLError[]' is not assignable to type 'ReadonlyArray'. Types of property 'flatMap' are incompatible. Type '<U, This = undefined>(callback: (this: This, value: GraphQLError, index: number, array: GraphQLEr...' is not assignable to type '<U, This = undefined>(callback: (this: This, value: GraphQLError, index: number, array: GraphQLEr...'. Two different types with this name exist, but they are unrelated. Types of parameters 'callback' and 'callback' are incompatible. Types of parameters 'value' and 'value' are incompatible. Type 'GraphQLError' is not assignable to type 'GraphQLError'. Two different types with this name exist, but they are unrelated. Property 'locations' is optional in type 'GraphQLError' but required in type 'GraphQLError'. Package Versions

"typescript": "^2.8.3" "graphql-mock": "^1.0.2", "apollo-boost": "0.1.6", — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

jonoirwinrsa commented 6 years ago

Hi @MadRabbit

Yeah sure! Will try and put something together now.

jonoirwinrsa commented 6 years ago

@MadRabbit I think this should show off the error - https://github.com/SovTech/my-mocking-app

I hope there isn't too much noise in there.. Installing packages and running the app should bring up the error

kaievns commented 6 years ago

@jonoirwinrsa thanks for the app, it's perfect!

so, i tinkered with it for a bit and i run into the same exact problem. i'm not sure why it happens in create react app, because we don't have this problem with vanilla jest/mocha setups, it works perfectly in there. my suspicion is that some of the react-scripts-ts might run an older version of TS or something. maybe ejecting and bumping all deps manually would solve this.

either way, i think i managed to patch the problem by relaxing the overloaded interface to > Promise<any>. It's probably not ideal, but should mitigate the immediate problem.

could you give v 1.0.3 a try? it compiled for me, there a few further explosions which i assume is just part of your app not being fully ready.

jonoirwinrsa commented 6 years ago

Hey @MadRabbit - tested and working! Thanks for the speedy response 🎉

kaievns commented 6 years ago

no drama, enjoy!