Skip to content

Commit

Permalink
Fixed single response and added subscriptions to links
Browse files Browse the repository at this point in the history
  • Loading branch information
evans committed Aug 3, 2017
1 parent cfd134e commit 3abfd04
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/ApolloClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
Request,
} from './transport/networkInterface';

import { execute, ApolloLink } from 'apollo-link-core';
import { execute, ApolloLink, FetchResult } from 'apollo-link-core';

import {
ExecutionResult,
Expand Down Expand Up @@ -207,9 +207,9 @@ export default class ApolloClient implements DataProxy {
const createQuery = (
getResult: (request: Request) => Observable<ExecutionResult>,
) => {
let resolved = false;
return (request: Request) =>
new Promise<ExecutionResult>((resolve, reject) => {
let resolved = false;
const subscription = getResult(request).subscribe({
next: (data: ExecutionResult) => {
if (!resolved) {
Expand All @@ -235,6 +235,18 @@ export default class ApolloClient implements DataProxy {
request,
) as any) as Observable<ExecutionResult>;
}),
subscribe: (request: any, handler: any): string => {
const subscription = (execute(
networkInterface as ApolloLink,
request,
) as any).subscribe({
next: (data: FetchResult) => handler(data.errors, data.data),
});
return '';
},
unsubscribe: (id: string): void => {
// wsClient.unsubscribe(id);
},
};
} else if (
networkInterface &&
Expand Down

0 comments on commit 3abfd04

Please sign in to comment.