Skip to content

Commit

Permalink
add types for typescript's projects
Browse files Browse the repository at this point in the history
  • Loading branch information
arvitaly committed Nov 15, 2016
1 parent f83b0ee commit 50f6a38
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Expand Up @@ -2,6 +2,7 @@
"name": "lokka",
"version": "1.7.0",
"description": "Simple JavaScript client for GraphQL",
"types": "types.d.ts",
"repository": {
"type": "git",
"url": "https://github.com/kadirahq/lokka.git"
Expand Down Expand Up @@ -42,4 +43,4 @@
"babel-runtime": "6.x.x",
"uuid": "2.x.x"
}
}
}
38 changes: 38 additions & 0 deletions types.d.ts
@@ -0,0 +1,38 @@
declare namespace Lokka {
export type QL = string;
export interface ITransport {
send(rawQuery: string, variables: { [index: string]: any }, operationName: string);
}
export interface IConfig {
transport: ITransport;
}
export interface IVars { [index: string]: any }
export type IFragment = string;
export interface IWatchHandler<T> {
(err, payload: T): any;
}
export interface IStop {
(): void;
}
export interface ICacheConfig {
cacheExpirationTimeout?: number;
}
export interface ICache {
getItemPayload<T>(query: QL, vars?: IVars): T;
setItemPayload<T>(query: QL, vars: IVars, payload: T): void;
fireError(query: QL, vars: IVars, error): void;
removeItem(query: QL, vars?: IVars): void;
getItem<T>(query: QL, vars?: IVars): T;
}
export class Lokka {
constructor(config: IConfig);
query<T>(query: QL, vars?: IVars): Promise<T>;
mutate<T>(query: QL, vars?: IVars): Promise<T>;
watchQuery<T>(query: QL, handler?: IWatchHandler<T>): IStop;
watchQuery<T>(query: QL, vars?: IVars, handler?: IWatchHandler<T>): IStop;
createFragment(fragment: QL): IFragment;
refetchQuery(query: QL, vars?: IVars): void;
cache: ICache;
}
}
export = Lokka

0 comments on commit 50f6a38

Please sign in to comment.