Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-3.0] RxJS #5749

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function eachFile(dir: string, callback: (
) => any) {
const promises: Promise<any>[] = [];

return new Promise((resolve, reject) => {
return new Promise<void>((resolve, reject) => {
glob(`${dir}/**/*.js`, (error, files) => {
if (error) return reject(error);

Expand Down
10,615 changes: 5,949 additions & 4,666 deletions examples/bundling/no-tree-shaking/rollup-ac3-no-react/package-lock.json

Large diffs are not rendered by default.

12,565 changes: 8,583 additions & 3,982 deletions examples/bundling/no-tree-shaking/rollup-ac3/package-lock.json

Large diffs are not rendered by default.

315 changes: 180 additions & 135 deletions examples/bundling/tree-shaking/rollup-ac3-no-react/package-lock.json

Large diffs are not rendered by default.

358 changes: 187 additions & 171 deletions examples/bundling/tree-shaking/rollup-ac3/package-lock.json

Large diffs are not rendered by default.

30,448 changes: 18,373 additions & 12,075 deletions examples/bundling/tree-shaking/webpack-ac3/package-lock.json

Large diffs are not rendered by default.

97 changes: 66 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 3 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,16 @@
},
"dependencies": {
"@graphql-typed-document-node/core": "^3.0.0",
"@types/zen-observable": "^0.8.0",
"@wry/context": "^0.6.0",
"@wry/equality": "^0.4.0",
"fast-json-stable-stringify": "^2.0.0",
"graphql-tag": "^2.12.0",
"hoist-non-react-statics": "^3.3.2",
"optimism": "^0.15.0",
"prop-types": "^15.7.2",
"symbol-observable": "^2.0.0",
"rxjs": "^7.0.0",
"ts-invariant": "^0.7.0",
"tslib": "^1.10.0",
"zen-observable": "^0.8.14"
"tslib": "^2.0.0"
},
"devDependencies": {
"@babel/parser": "7.14.0",
Expand Down Expand Up @@ -121,12 +119,11 @@
"rimraf": "3.0.2",
"rollup": "1.31.1",
"rollup-plugin-terser": "7.0.2",
"rxjs": "6.6.7",
"subscriptions-transport-ws": "0.9.18",
"terser": "5.7.0",
"ts-jest": "26.5.5",
"ts-node": "8.10.2",
"typescript": "3.9.9",
"typescript": "4.2.4",
"wait-for-observables": "^1.0.3"
},
"publishConfig": {
Expand Down
3 changes: 2 additions & 1 deletion src/__tests__/ApolloClient.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import gql from 'graphql-tag';
import { of } from 'rxjs';

import {
ApolloClient,
Expand Down Expand Up @@ -1185,7 +1186,7 @@ describe('ApolloClient', () => {
},
};
const link = new ApolloLink(() => {
return Observable.of({ data });
return of({ data });
});
function newClient() {
return new ApolloClient({
Expand Down
2 changes: 1 addition & 1 deletion src/cache/inmemory/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export type OptimisticStoreItem = {
export type ReadQueryOptions = {
store: NormalizedCache;
query: DocumentNode;
variables?: Object;
variables?: object;
previousResult?: any;
rootId?: string;
config?: ApolloReducerConfig;
Expand Down
14 changes: 7 additions & 7 deletions src/core/ObservableQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ export class ObservableQuery<
private observers = new Set<Observer<ApolloQueryResult<TData>>>();
private subscriptions = new Set<ObservableSubscription>();

private lastResult: ApolloQueryResult<TData>;
private lastResultSnapshot: ApolloQueryResult<TData>;
private lastError: ApolloError;
private lastResult?: ApolloQueryResult<TData>;
private lastResultSnapshot?: ApolloQueryResult<TData>;
private lastError?: ApolloError;
private queryInfo: QueryInfo;

constructor({
Expand Down Expand Up @@ -135,7 +135,7 @@ export class ObservableQuery<
NetworkStatus.ready;

const result: ApolloQueryResult<TData> = {
...lastResult,
...lastResult!,
loading: isNetworkRequestInFlight(networkStatus),
networkStatus,
};
Expand Down Expand Up @@ -198,11 +198,11 @@ export class ObservableQuery<
// Returns the last result that observer.next was called with. This is not the same as
// getCurrentResult! If you're not sure which you need, then you probably need getCurrentResult.
public getLastResult(): ApolloQueryResult<TData> {
return this.lastResult;
return this.lastResult!;
}

public getLastError(): ApolloError {
return this.lastError;
return this.lastError!;
}

public resetLastResults(): void {
Expand Down Expand Up @@ -610,7 +610,7 @@ once, rather than every time you call fetchMore.`);
// Since we don't get the current result on errors, only the error, we
// must mirror the updates that occur in QueryStore.markQueryError here
this.updateLastResult({
...this.lastResult,
...this.lastResult!,
error,
errors: error.graphQLErrors,
networkStatus: NetworkStatus.error,
Expand Down
8 changes: 4 additions & 4 deletions src/core/QueryInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ export class QueryInfo {

// Cancel the pending notify timeout
this.reset();
this.cancel();

this.cancel!();
// Revert back to the no-op version of cancel inherited from
// QueryInfo.prototype.
delete this.cancel;
Expand All @@ -251,7 +251,7 @@ export class QueryInfo {

// This method is a no-op by default, until/unless overridden by the
// updateWatch method.
private cancel() {}
private cancel?() {}

private lastWatch?: Cache.WatchOptions;

Expand All @@ -263,7 +263,7 @@ export class QueryInfo {
if (!this.lastWatch ||
this.lastWatch.query !== this.document ||
!equal(variables, this.lastWatch.variables)) {
this.cancel();
this.cancel!();
this.cancel = this.cache.watch(this.lastWatch = {
query: this.document!,
variables,
Expand Down
52 changes: 28 additions & 24 deletions src/core/QueryManager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { DocumentNode } from 'graphql';
import { invariant, InvariantError } from 'ts-invariant';
import { equal } from '@wry/equality';
import { of } from 'rxjs';
import { map } from 'rxjs/operators';

import { ApolloLink, execute, FetchResult } from '../link/core';
import { Cache, ApolloCache } from '../cache';
Expand Down Expand Up @@ -689,30 +691,32 @@ export class QueryManager<TStore> {
context,
variables,
false,
).map(result => {
if (fetchPolicy !== 'no-cache') {
// the subscription interface should handle not sending us results we no longer subscribe to.
// XXX I don't think we ever send in an object with errors, but we might in the future...
if (shouldWriteResult(result, errorPolicy)) {
this.cache.write({
query,
result: result.data,
dataId: 'ROOT_SUBSCRIPTION',
variables: variables,
});
}
).pipe(
map(result => {
if (fetchPolicy !== 'no-cache') {
// the subscription interface should handle not sending us results we no longer subscribe to.
// XXX I don't think we ever send in an object with errors, but we might in the future...
if (shouldWriteResult(result, errorPolicy)) {
this.cache.write({
query,
result: result.data,
dataId: 'ROOT_SUBSCRIPTION',
variables: variables,
});
}

this.broadcastQueries();
}
this.broadcastQueries();
}

if (graphQLResultHasError(result)) {
throw new ApolloError({
graphQLErrors: result.errors,
});
}
if (graphQLResultHasError(result)) {
throw new ApolloError({
graphQLErrors: result.errors,
});
}

return result;
});
return result;
})
);

if (this.transform(query).hasClientExports) {
const observablePromise = this.localState.addExportedVariables(
Expand Down Expand Up @@ -804,7 +808,7 @@ export class QueryManager<TStore> {
observable = byVariables.get(varJson);

if (!observable) {
const concast = new Concast([
const concast = new Concast<FetchResult<T>>([
execute(link, operation) as Observable<FetchResult<T>>
]);

Expand All @@ -825,7 +829,7 @@ export class QueryManager<TStore> {
}
} else {
observable = new Concast([
Observable.of({ data: {} } as FetchResult<T>)
of({ data: {} } as FetchResult<T>)
]);
context = this.prepareContext(context);
}
Expand Down Expand Up @@ -1067,7 +1071,7 @@ export class QueryManager<TStore> {
}`, diff.missing);
}

const fromData = (data: TData) => Observable.of({
const fromData = (data: TData) => of({
data,
loading: isNetworkRequestInFlight(networkStatus),
networkStatus,
Expand Down
Loading