Skip to content
This repository has been archived by the owner on Jun 5, 2021. It is now read-only.

lauriharpf/reproduce-create-test-client-linting-issue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Reproduces linter issue with createTestClient function typing

Reproduces a linter issue in the createTestClient function reported by typescript-eslint with the type-aware rules.

Steps to repeat

  1. npm install
  2. npm run lint

What happens

The following linter errors, related to the createTestClient function, are reported:

/directory/reproduce-create-test-client-typing-issue/src/index.test.ts
  9:11  error  Avoid referencing unbound methods which may cause unintentional scoping of `this`.
If your function does not access `this`, you can annotate it with `this: void`, or consider using an arrow function instead  @typescript-eslint/unbound-method
  9:11  error  Avoid referencing unbound methods which may cause unintentional scoping of `this`.
If your function does not access `this`, you can annotate it with `this: void`, or consider using an arrow function instead  @typescript-eslint/unbound-method

Expected result

No linter errors occur.

Change suggestion

  1. Edit the node_modules/apollo-server-testing/dist/createTestClient.d.ts file. Replace this type definition:
export interface ApolloServerTestClient {
    query<TData = any, TVariables = Record<string, any>>(query: Query<TVariables>): Promise<GraphQLResponse<TData>>;
    mutate<TData = any, TVariables = Record<string, any>>(mutation: Mutation<TVariables>): Promise<GraphQLResponse<TData>>;
}

with this type definition:

export interface ApolloServerTestClient {
    query: <TData = any, TVariables = Record<string, any>>(query: Query<TVariables>) => Promise<GraphQLResponse<TData>>;
    mutate: <TData = any, TVariables = Record<string, any>>(mutation: Mutation<TVariables>) => Promise<GraphQLResponse<TData>>;
}
  1. Run npm run lint again in the repository root directory. It should no longer cause linter errors.

Additional details

See https://stackoverflow.com/a/67573584/843984

About

Reproduces a linting issue with createTestClient function in apollo-server-testing

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published