Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat request: Typescript support #22

Open
joandvgv opened this issue Apr 24, 2021 · 1 comment
Open

Feat request: Typescript support #22

joandvgv opened this issue Apr 24, 2021 · 1 comment

Comments

@joandvgv
Copy link

Hi! Just wanted to know the feasibility of adding declaration typescript files (since the project is solely built on javascript) This would be a great addition for pure Typescript projects.

Thanks,

@joandvgv
Copy link
Author

joandvgv commented Apr 24, 2021

I know this is a zero-dependency package but here's my typescript definition file for the configuration object based on the documentation
@types/apollo-cache-updater.d.ts

type CacheSearchOperator = "AND" | "AND_EDGE" | "OR" | "OR_EDGE" | "ANY";

type CacheOperationType = "ADD" | "REMOVE" | "MOVE";

type CacheRowType = "TOP" | "BOTTOM" | "SORT";
type CacheRowField = string | undefined;

type OperationI = {
  type: CacheOperationType = "ADD";
  row: {
    type: CacheRowType = "TOP";
    field: CacheRowField;
  };
};

type QueryVariables = Record<string, unknown>;

declare module "apollo-cache-updater" {
  export default function ApolloCacheUpdater<T, K>(options: {
    proxy: import("@apollo/client").ApolloCache<T>;
    queriesToUpdate: import("@apollo/client").DocumentNode[];
    mutationResult: K;
    searchOperator?: SearchOperator = "AND";
    operation?: OperationI;
    switchVars?: QueryVariables;
    searchVariables?: QueryVariables;
    ID?: string = "id";
  }): boolean;
}

This is working in my React project successfully, but it can be easily modified to work with yours.
image

I guess for this project we could "steal" the type definitions for ApolloCache and DocumentNode and keep it a zero-dependency package. It would be interesting to check whether all Apollo clients have these same type definitions, though.

I'm more than happy to contribute to this if needed, not a typescript expert but a huge fan :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant