octokit / plugin-paginate-graphql.js

Octokit plugin to paginate GraphQL Query responses
MIT License
41 stars 20 forks source link

Provide type information #10

Open tenjaa opened 2 years ago

tenjaa commented 2 years ago

What’s missing?

An easy to use type of the extension to octokit this plugin provides.

Why?

We are passing an octokit instance as constructor parameter. To benefit of typing we want to set the type properly.

Alternatives you tried

We copied the type from the index.d.ts to build this workaround.

/**
 * from node_modules/@octokit/plugin-paginate-graphql/dist-types/index.d.ts
 */
export type GraphqlPaginationExtension = {
  graphql: import("@octokit/graphql/dist-types/types").graphql & {
    paginate: (<ResponseType_1 extends object = any>(query: string, initialParameters?: Record<string, any>) => Promise<ResponseType_1>) & {
      iterator: <ResponseType_2 = any>(query: string, initialParameters?: Record<string, any>) => {
        [Symbol.asyncIterator]: () => {
          next(): Promise<{
            done: boolean;
            value: ResponseType_2;
          }>;
        };
      };
    };
  };
}
  constructor(
    private readonly octokit: Octokit & GraphqlPaginationExtension,
    private readonly otherStuff: OtherStuff,
  ) {
  }
Dizotoff commented 2 years ago

Thank you for this!

wolfy1339 commented 7 months ago

You can do the following to get the returned interface type:

import { paginateGraphQL } from "@octokit/paginate-graphql";
import { Octokit } from "@octokit/core";

type PaginateGraphQLOctokit = Octokit & ReturnType<paginateGraphQL>;