diff --git a/types/mobx-apollo/index.d.ts b/types/mobx-apollo/index.d.ts new file mode 100644 index 0000000000..4054601717 --- /dev/null +++ b/types/mobx-apollo/index.d.ts @@ -0,0 +1,29 @@ +// Type definitions for mobx-apollo 0.0 +// Project: https://github.com/sonaye/mobx-apollo#readme +// Definitions by: Paul Selden +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +import { + ApolloClient, + ObservableQuery, + WatchQueryOptions, + ApolloError +} from 'apollo-client'; + +export interface MobxApolloQueryOptions extends WatchQueryOptions { + client: ApolloClient; + onFetch?: (result: T) => void; + onError?: (error: ApolloError) => void; +} + +export interface MobxApolloQuery { + loading: boolean; + data: T; + error?: ApolloError; + ref: ObservableQuery; +} + +export default function graphql( + options: MobxApolloQueryOptions +): MobxApolloQuery; diff --git a/types/mobx-apollo/mobx-apollo-tests.ts b/types/mobx-apollo/mobx-apollo-tests.ts new file mode 100644 index 0000000000..cc17916a5a --- /dev/null +++ b/types/mobx-apollo/mobx-apollo-tests.ts @@ -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(); diff --git a/types/mobx-apollo/tsconfig.json b/types/mobx-apollo/tsconfig.json new file mode 100644 index 0000000000..c18e0f5512 --- /dev/null +++ b/types/mobx-apollo/tsconfig.json @@ -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"] +} diff --git a/types/mobx-apollo/tslint.json b/types/mobx-apollo/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/mobx-apollo/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }