mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-07 08:17:05 +00:00
add definition for mobx-apollo
This commit is contained in:
Vendored
+29
@@ -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>;
|
||||
@@ -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();
|
||||
@@ -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"]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user