Skip to content

Commit

Permalink
Merge pull request apollographql#5882 from apollographql/export-adjus…
Browse files Browse the repository at this point in the history
…tments

Minor export changes
  • Loading branch information
hwillson authored Jan 30, 2020
2 parents 87b9fd2 + 7364bff commit 945aa0b
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 24 deletions.
8 changes: 6 additions & 2 deletions src/core/ObservableQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import { tryFunctionOrLogError } from '../utilities/common/errorHandling';
import { cloneDeep } from '../utilities/common/cloneDeep';
import { getOperationDefinition } from '../utilities/graphql/getFromAST';
import { NetworkStatus, isNetworkRequestInFlight } from './networkStatus';
import { Observable, Observer, Subscription } from '../utilities/observables/Observable';
import {
Observable,
Observer,
ObservableSubscription
} from '../utilities/observables/Observable';
import { ApolloError } from '../errors/ApolloError';
import { QueryManager } from './QueryManager';
import { ApolloQueryResult, FetchType, OperationVariables } from './types';
Expand Down Expand Up @@ -65,7 +69,7 @@ export class ObservableQuery<
private isTornDown: boolean;
private queryManager: QueryManager<any>;
private observers = new Set<Observer<ApolloQueryResult<TData>>>();
private subscriptions = new Set<Subscription>();
private subscriptions = new Set<ObservableSubscription>();

private lastResult: ApolloQueryResult<TData>;
private lastResultSnapshot: ApolloQueryResult<TData>;
Expand Down
12 changes: 8 additions & 4 deletions src/core/QueryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ import {
import { removeConnectionDirectiveFromDocument } from '../utilities/graphql/transform';
import { canUseWeakMap } from '../utilities/common/canUse';
import { isApolloError, ApolloError } from '../errors/ApolloError';
import { Observer, Subscription, Observable } from '../utilities/observables/Observable';
import {
Observer,
ObservableSubscription,
Observable
} from '../utilities/observables/Observable';
import { MutationStore } from '../data/mutations';
import { QueryStore, QueryStoreValue } from '../data/queries';
import {
Expand Down Expand Up @@ -59,7 +63,7 @@ export interface QueryInfo {
// these to keep track of queries that are inflight and error on the observers associated
// with them in case of some destabalizing action (e.g. reset of the Apollo store).
observableQuery: ObservableQuery<any> | null;
subscriptions: Set<Subscription>;
subscriptions: Set<ObservableSubscription>;
cancel?: () => void;
}

Expand Down Expand Up @@ -1018,7 +1022,7 @@ export class QueryManager<TStore> {
).then(makeObservable);

return new Observable<FetchResult<T>>(observer => {
let sub: Subscription | null = null;
let sub: ObservableSubscription | null = null;
observablePromise.then(
observable => sub = observable.subscribe(observer),
observer.error,
Expand Down Expand Up @@ -1331,7 +1335,7 @@ export class QueryManager<TStore> {
newData: null,
lastRequestId: 1,
observableQuery: null,
subscriptions: new Set<Subscription>(),
subscriptions: new Set<ObservableSubscription>(),
}
);
}
Expand Down
16 changes: 7 additions & 9 deletions src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ export { HttpLink } from '../link/http/HttpLink';
export { fromError } from '../link/utils/fromError';
export { toPromise } from '../link/utils/toPromise';
export { ServerError, throwServerError } from '../link/utils/throwServerError';
export { Observable } from '../utilities/observables/Observable';
export {
Observable,
Observer,
ObservableSubscription
} from '../utilities/observables/Observable';

/* Supporting */

Expand All @@ -84,16 +88,10 @@ export { Observable } from '../utilities/observables/Observable';
// then re-exporting them separately, helps keeps bundlers happy without any
// additional config changes.
import gql from 'graphql-tag';
const {
export const {
resetCaches,
disableFragmentWarnings,
enableExperimentalFragmentVariables,
disableExperimentalFragmentVariables
} = gql;
export {
gql,
resetCaches,
disableFragmentWarnings,
enableExperimentalFragmentVariables,
disableExperimentalFragmentVariables
};
export { gql };
2 changes: 1 addition & 1 deletion src/types/graphql-tag.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// be fully updated to use Typescript, and these discrepancies will be fixed.

declare module 'graphql-tag' {
function gql(literals: any, ...placeholders: any[]): any;
function gql(literals: string[], ...placeholders: any[]): any;
namespace gql {
export function resetCaches(): void;
export function disableFragmentWarnings(): void;
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/observables/Observable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Observable from 'zen-observable';
// proposal (https://github.com/zenparsing/es-observable)
import 'symbol-observable';

export type Subscription = ZenObservable.Subscription;
export type ObservableSubscription = ZenObservable.Subscription;
export type Observer<T> = ZenObservable.Observer<T>;

// Use global module augmentation to add RxJS interop functionality. By
Expand Down
4 changes: 2 additions & 2 deletions src/utilities/observables/observables.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Observable, Observer, Subscription } from './Observable';
import { Observable, Observer, ObservableSubscription } from './Observable';

// Returns a normal Observable that can have any number of subscribers,
// while ensuring the original Observable gets subscribed to at most once.
export function multiplex<T>(inner: Observable<T>): Observable<T> {
const observers = new Set<Observer<T>>();
let sub: Subscription | null = null;
let sub: ObservableSubscription | null = null;
return new Observable<T>(observer => {
observers.add(observer);
sub = sub || inner.subscribe({
Expand Down
6 changes: 3 additions & 3 deletions src/utilities/testing/observableToPromise.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ObservableQuery } from '../../core/ObservableQuery';
import { ApolloQueryResult } from '../../core/types';
import { Subscription } from '../../utilities/observables/Observable';
import { ObservableSubscription } from '../../utilities/observables/Observable';

/**
*
Expand All @@ -27,8 +27,8 @@ export type ResultCallback = ((result: ApolloQueryResult<any>) => any);
export function observableToPromiseAndSubscription(
{ observable, shouldResolve = true, wait = -1, errorCallbacks = [] }: Options,
...cbs: ResultCallback[]
): { promise: Promise<any[]>; subscription: Subscription } {
let subscription: Subscription = null as never;
): { promise: Promise<any[]>; subscription: ObservableSubscription } {
let subscription: ObservableSubscription = null as never;
const promise = new Promise<any[]>((resolve, reject) => {
let errorIndex = 0;
let cbIndex = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/utilities/testing/subscribeAndCount.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { ObservableQuery } from '../../core/ObservableQuery';
import { ApolloQueryResult } from '../../core/types';
import { Subscription } from '../../utilities/observables/Observable';
import { ObservableSubscription } from '../../utilities/observables/Observable';
import { asyncMap } from '../../utilities/observables/observables';

export default function subscribeAndCount(
reject: (reason: any) => any,
observable: ObservableQuery<any>,
cb: (handleCount: number, result: ApolloQueryResult<any>) => any,
): Subscription {
): ObservableSubscription {
let handleCount = 0;
const subscription = asyncMap(
observable,
Expand Down

0 comments on commit 945aa0b

Please sign in to comment.