Skip to content

Instantly share code, notes, and snippets.

@qswitcher
Created January 27, 2019 03:48
Show Gist options
  • Save qswitcher/c7bad7fcf3a03e154c322ab38e38582b to your computer and use it in GitHub Desktop.
Save qswitcher/c7bad7fcf3a03e154c322ab38e38582b to your computer and use it in GitHub Desktop.
import { DocumentNode } from "graphql";
interface Query<TVariables> {
/* The GraphQL query shape to be used constructed using the `gql` template
* string tag from `graphql-tag`. The query will be used to determine the
* shape of the data to be read.*/
query: DocumentNode;
/**
* Any variables that the GraphQL query may depend on
*/
variables?: TVariables;
}
interface ReadOptions<TVariables> extends Query<TVariables> {
rootId?: String;
previousResult?: any;
/*
* Flag indicating if this is an optimistic read (Optimistic UI)
*/
optimistic: boolean;
}
interface WriteOptions<TResult, TVariables> extends Query<TVariables> {
dataId: string;
result: TResult;
}
interface DiffOptions<TVariables> extends ReadOptions<TVariables> {
/**
* Flag indicating if the diff operation should return partial results even
* if some fields are missing
*/
returnPartialData?: boolean;
}
interface DiffResult<TResult> {
result?: TResult;
/**
* Flag indicating if any fields were missing in the result
*/
complete?: boolean;
}
interface WatchOptions<TVariables> extends ReadOptions<TVariables> {
callback: (newData: any) => void;
}
interface EvictOptions<TVariables> extends Query<TVariables> {
rootId?: string;
}
interface EvictionResult {
success: boolean;
}
type Transaction<T> = (c: ApolloCache<T>) => void;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment