add definition for mobx-apollo

This commit is contained in:
Paul Selden
2017-11-16 15:22:28 -05:00
parent 61796910d1
commit f313a73ba3
4 changed files with 88 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
// Type definitions for mobx-apollo 0.0
// Project: https://github.com/sonaye/mobx-apollo#readme
// Definitions by: Paul Selden <https://github.com/pselden>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
import {
ApolloClient,
ObservableQuery,
WatchQueryOptions,
ApolloError
} from 'apollo-client';
export interface MobxApolloQueryOptions<T> extends WatchQueryOptions {
client: ApolloClient<any>;
onFetch?: (result: T) => void;
onError?: (error: ApolloError) => void;
}
export interface MobxApolloQuery<T> {
loading: boolean;
data: T;
error?: ApolloError;
ref: ObservableQuery<T>;
}
export default function graphql<T>(
options: MobxApolloQueryOptions<T>
): MobxApolloQuery<T>;
+40
View File
@@ -0,0 +1,40 @@
import * as React from 'react';
import { computed } from 'mobx';
import { ApolloClient } from 'apollo-client';
import gql from 'graphql-tag';
import query from 'mobx-apollo';
const PostsQuery = gql`
{
posts {
id
title
}
}
`;
interface Post {
id: string;
title: string;
}
class PostStore {
@computed
private get postsQuery() {
return query<{ posts: Post[] }>({
client: new ApolloClient({
link: {} as any,
cache: {} as any
}),
query: PostsQuery
});
}
@computed
get posts() {
return this.postsQuery.data.posts;
}
}
new PostStore();
+18
View File
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["es6"],
"target": "es5",
"experimentalDecorators": true,
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": ["../"],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": ["index.d.ts", "mobx-apollo-tests.ts"]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }