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

Apollo Angular 2.0 + Apollo Client 3.0 #1383

Merged
merged 15 commits into from
Aug 4, 2020
Merged

Apollo Angular 2.0 + Apollo Client 3.0 #1383

merged 15 commits into from
Aug 4, 2020

Conversation

kamilkisiela
Copy link
Owner

@kamilkisiela kamilkisiela commented Nov 2, 2019

@wSedlacek wSedlacek mentioned this pull request Mar 27, 2020
@denniscalazans
Copy link

Please <3

@kamilkisiela kamilkisiela changed the title Apollo Angular 2.0 + Apollo Client 3.0 + strict mode Apollo Angular 2.0 + Apollo Client 3.0 Jul 24, 2020
@kamilkisiela
Copy link
Owner Author

kamilkisiela commented Jul 24, 2020

First beta: 2.0.0-beta.3

@denniscalazans @migueldv90 @chalber @JesseZomer @MrGekko @PowerKiKi @jcviau @MSakamaki @ambientlight @loremaps @lars-berger @OLDIN @d2kx @gavindoughtie

No migration doc yet but in general, everything can be now imported from apollo-angular, even things from @apollo/client/core (using @apollo/client will cause an issue because it depends on react). Feel free to import everything that cannot be imported from apollo-angular directly from apollo client.

Http and HttpBatch are now under apollo-angular/http.

There are no NgModules, everything has providedIn: 'root'.

@kamilkisiela
Copy link
Owner Author

Feedback welcome, especially about bundle size :) I haven't test it yet, super super busy but I'm counting on you!

@d2kx
Copy link

d2kx commented Jul 24, 2020

Initial findings:

  • Bundle size has regressed slightly. I was initially concerned more on a fresh project, but a big part seemed to come from the new version/AC3 importing graphql-tag always where it didn't show on fresh AC2 projects (but once you import graphql-tag, the difference is gone, and you'll probably do it anyway).

Overall, seems to be about ~15kb larger, mostly from a small bump in the InMemoryCache in AC3 and another small bump in size from GraphQL@15. Also similar to before, Apollo Client itself still seems to always import zen-observable, which I wish was not the case since we have RxJS.

  • I had to add allowSyntheticDefaultImports to my tsconfig, otherwise it would not build:

image

  • while we are at tsconfig.json, one thing that I think has not been necessary even with the previous release (never bothered to file an issue, I'm sorry) is that ng add adds "esnext.asynciterable" but I am 99,99% sure that asynciterable is already part of es2018 lib and newer, so it is no longer necessary nowadays:

image

Have yet to try it in a real world application. I guess the new cache features etc. are all not to relevant to apollo-angular and will get exposed through getClient() or update functions to mutations etc.

Also ❤🌈 thank you for your work, Kamil!! ❤🌈

@sascha1337
Copy link

M E R G E <3

@charsleysa
Copy link

@kamilkisiela LocalStateFragmentMatcher no longer exists in @apollo/client@3.1.1 as it was an alias to FragmentMatcher which is no longer aliased.

It needs to be removed from being re-exported.

I would argue that apollo-angular should avoid re-exporting from @apollo/client as issues like this can arise in the future and break builds even though apollo-angular itself doesn't use these exports.

@sascha1337
Copy link

And please update the docs on the main website, i was so confused looking for angular docs, in the top left menu, and the docs should use @apollo/client then asap - avoids confusion, thanks ! Keep up the great work

@kamilkisiela
Copy link
Owner Author

@sascha1337 it's a beta release, I moved away from Apollo org so there's a lot of work with documentation. I need to setup a website, update docs, create a migration chapter etc.

@sascha1337
Copy link

Ah okay, wish you all the best - any estimated time for a release? Would appreciate a small use-v2-now.md with minimal examples for the most used things, and the best way to use the beta / branch with package.json. Thank you a LOT.

@kamilkisiela
Copy link
Owner Author

Released :)

@kamilkisiela kamilkisiela merged commit f8bebee into master Aug 4, 2020
@kamilkisiela kamilkisiela deleted the feat/v2 branch August 4, 2020 18:23
@KeithGillette
Copy link
Contributor

Executing ng update apollo-angular on our Angular 10.0.6 project produces the following error:

The installed local Angular CLI version is older than the latest stable version.
Installing a temporary version to perform the update.
Installing packages for tooling via npm.
Installed packages for tooling via npm.
Using package manager: 'npm'
Collecting installed dependencies...
Found 107 dependencies.
Fetching dependency metadata from registry...
                  Package "apollo-angular" has a missing peer dependency of "@apollo/client" @ "^3.0.0".
    Updating package.json with dependency apollo-angular @ "2.0.0" (was "1.10.0")...
UPDATE package.json (12689 bytes)
✔ Packages installed successfully.
An unhandled exception occurred: Cannot find module '~/node_modules/apollo-angular/schematics/migrations/v2'
Require stack:
- /private/var/folders/t5/nv32j92n7rngpy281m6gj8n00000gn/T/angular-cli-packages-2np7ik/node_modules/@angular-devkit/schematics/tools/export-ref.js
- /private/var/folders/t5/nv32j92n7rngpy281m6gj8n00000gn/T/angular-cli-packages-2np7ik/node_modules/@angular-devkit/schematics/tools/index.js
- /private/var/folders/t5/nv32j92n7rngpy281m6gj8n00000gn/T/angular-cli-packages-2np7ik/node_modules/@angular/cli/utilities/json-schema.js
- /private/var/folders/t5/nv32j92n7rngpy281m6gj8n00000gn/T/angular-cli-packages-2np7ik/node_modules/@angular/cli/models/command-runner.js
- /private/var/folders/t5/nv32j92n7rngpy281m6gj8n00000gn/T/angular-cli-packages-2np7ik/node_modules/@angular/cli/lib/cli/index.js
- /private/var/folders/t5/nv32j92n7rngpy281m6gj8n00000gn/T/angular-cli-packages-2np7ik/node_modules/@angular/cli/lib/init.js
- /private/var/folders/t5/nv32j92n7rngpy281m6gj8n00000gn/T/angular-cli-packages-2np7ik/node_modules/@angular/cli/bin/ng
See "/private/var/folders/t5/nv32j92n7rngpy281m6gj8n00000gn/T/ng-K2Ud6N/angular-errors.log" for further details.

@kamilkisiela
Copy link
Owner Author

@KeithGillette what about v2.0.1?

@KeithGillette
Copy link
Contributor

KeithGillette commented Aug 4, 2020

✔ Packages installed successfully.
  Migration completed.

Thanks, @kamilkisiela!

@KeithGillette
Copy link
Contributor

However, the schematics added the following to every single TypeScript file in the entire project:

import {Apollo, ApolloModule, Apollo, Apollo, Apollo, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, gql, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, gql, Apollo, Apollo, Apollo, Apollo, gql, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, gql, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, QueryRef, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, Apollo, QueryRef, Apollo, Apollo, Apollo, gql} from 'apollo-angular';
import {ApolloQueryResult, ApolloError, ApolloQueryResult, ApolloError, ApolloQueryResult, ApolloError, ApolloError, ApolloQueryResult, ApolloError, ApolloQueryResult, ApolloError, ApolloQueryResult, ApolloError, FetchResult, ApolloError, FetchResult, ApolloError, DataProxy, ApolloError, ApolloQueryResult, MutationOptions, FetchResult, FetchResult, ApolloError, ApolloQueryResult, PureQueryOptions, DataProxy, ApolloError, ApolloQueryResult, FetchResult, DataProxy, ApolloError, ApolloQueryResult, FetchResult, DataProxy, FetchResult, DataProxy, ApolloError, ApolloQueryResult, DataProxy, DocumentNode, FetchResult, ApolloError, ApolloQueryResult, FetchResult, DataProxy, ApolloError, ApolloQueryResult, FetchResult, DataProxy, ApolloError, FetchResult, NextLink, Operation, InMemoryCache, NormalizedCacheObject, ApolloCache, ApolloLink, InMemoryCache, ApolloError, Resolvers, InMemoryCache, NormalizedCacheObject, DocumentNode, FetchResult, NextLink, Operation, ApolloQueryResult, ApolloError, ApolloQueryResult, ApolloError, ApolloQueryResult, ApolloError, ApolloQueryResult, ApolloError, ApolloQueryResult, ApolloError, ApolloQueryResult, FetchResult, ApolloError, ApolloQueryResult, ApolloError, ApolloQueryResult, ApolloError, ApolloQueryResult, ApolloError, ApolloQueryResult, ApolloError, ApolloQueryResult, FetchResult, ApolloError, ApolloQueryResult, ApolloError, ApolloQueryResult, ApolloError, ApolloQueryResult, ExecutionResult, ApolloQueryResult, ApolloError, ApolloQueryResult, ApolloQueryResult, ApolloQueryResult, ApolloError, ApolloQueryResult, ApolloError, ApolloQueryResult, ApolloError, ApolloQueryResult, ApolloError, ApolloQueryResult, ApolloError, ApolloQueryResult, ApolloQueryResult, ApolloError, ExecutionResult, FetchResult, ApolloQueryResult, ApolloError, ApolloQueryResult, ApolloQueryResult, ApolloError, ApolloQueryResult, ApolloError, ApolloError, ApolloQueryResult, ApolloError, ApolloQueryResult, ApolloError, ApolloQueryResult, ApolloQueryResult, ApolloError, ApolloQueryResult, ApolloError, ApolloQueryResult, ApolloError, ApolloQueryResult, ApolloQueryResult, ApolloError, ApolloQueryResult, ApolloError, ApolloQueryResult, ApolloQueryResult, ApolloError, ApolloQueryResult, ApolloQueryResult, ApolloQueryResult, ApolloQueryResult, ApolloQueryResult, ApolloQueryResult, ApolloError, ApolloQueryResult, ApolloQueryResult, ApolloQueryResult, ApolloQueryResult, ApolloError, ApolloQueryResult, FetchResult, ApolloQueryResult, FetchResult, ApolloError, ApolloQueryResult, ApolloError, ApolloQueryResult, ApolloError, ApolloQueryResult, FetchResult, ApolloError, ApolloQueryResult, ApolloError, ApolloQueryResult, ApolloError, ApolloQueryResult, ApolloQueryResult, ApolloError, ApolloQueryResult, ApolloError, ApolloQueryResult} from '@apollo/client/core';
import {HttpLinkModule, HttpLink} from 'apollo-angular/http';
import {ErrorResponse, onError} from '@apollo/client/link/error';

@kamilkisiela
Copy link
Owner Author

@KeithGillette 2.0.2 :)

@KeithGillette
Copy link
Contributor

KeithGillette commented Aug 4, 2020

2.0.2 mangled my package.json, @kamilkisiela. :-(

Specifically, munged the repository.url property replacing everything after "url": "https:" with *.

@d2kx
Copy link

d2kx commented Aug 4, 2020

Just wanted to report that for a new project, ng add with 2.0.2 worked flawlessly ❤ I also see nothing funny in the package.json.

@pickfire
Copy link

pickfire commented Aug 5, 2020

ng update failed.

> ng update apollo-angular --allow-dirty
The installed local Angular CLI version is older than the latest stable version.
Installing a temporary version to perform the update.
Installing packages for tooling via yarn.
Installed packages for tooling via yarn.
Repository is not clean. Update changes will be mixed with pre-existing changes.
Using package manager: 'yarn'
Collecting installed dependencies...
Found 120 dependencies.
Fetching dependency metadata from registry...
                  Package "apollo-angular" has a missing peer dependency of "@apollo/client" @ "^3.0.0".
    Updating package.json with dependency apollo-angular @ "2.0.2" (was "1.10.0")...
    Updating package.json with dependency graphql @ "15.3.0" (was "0.11.7")...
UPDATE package.json (7760 bytes)
✔ Packages installed successfully.
** Executing migrations of package 'apollo-angular' **

▸ Update to Apollo Angular 2 and Apollo Client 3
✖ Migration failed: Couldn't parse package.json!
  See "/tmp/ng-dT1j9o/angular-errors.log" for further details.

[error] Error: Couldn't parse package.json!
    at Object.getJsonFile (/home/ivan/act/apu/apspace/node_modules/apollo-angular/schematics/utils/file.js:26:15)
    at /home/ivan/act/apu/apspace/node_modules/apollo-angular/schematics/migrations/v2.js:17:37
    at MergeMapSubscriber.project (/home/ivan/act/apu/apspace/node_modules/@angular-devkit/schematics/src/rules/call.js:75:24)
    at MergeMapSubscriber._tryNext (/home/ivan/act/apu/apspace/node_modules/@angular-devkit/schematics/node_modules/rxjs/internal/operators/mergeMap.js:69:27)
    at MergeMapSubscriber._next (/home/ivan/act/apu/apspace/node_modules/@angular-devkit/schematics/node_modules/rxjs/internal/operators/mergeMap.js:59:18)
    at MergeMapSubscriber.Subscriber.next (/home/ivan/act/apu/apspace/node_modules/@angular-devkit/schematics/node_modules/rxjs/internal/Subscriber.js:66:18)
    at Observable._subscribe (/home/ivan/act/apu/apspace/node_modules/@angular-devkit/schematics/node_modules/rxjs/internal/util/subscribeToArray.js:5:20)
    at Observable._trySubscribe (/home/ivan/act/apu/apspace/node_modules/@angular-devkit/schematics/node_modules/rxjs/internal/Observable.js:44:25)
    at Observable.subscribe (/home/ivan/act/apu/apspace/node_modules/@angular-devkit/schematics/node_modules/rxjs/internal/Observable.js:30:22)
    at MergeMapOperator.call (/home/ivan/act/apu/apspace/node_modules/@angular-devkit/schematics/node_modules/rxjs/internal/operators/mergeMap.js:39:23)
    at Observable.subscribe (/home/ivan/act/apu/apspace/node_modules/@angular-devkit/schematics/node_modules/rxjs/internal/Observable.js:25:31)
    at Object.subscribeToResult (/home/ivan/act/apu/apspace/node_modules/@angular-devkit/schematics/node_modules/rxjs/internal/util/subscribeToResult.js:12:23)
    at MergeMapSubscriber._innerSub (/home/ivan/act/apu/apspace/node_modules/@angular-devkit/schematics/node_modules/rxjs/internal/operators/mergeMap.js:82:53)
    at MergeMapSubscriber._tryNext (/home/ivan/act/apu/apspace/node_modules/@angular-devkit/schematics/node_modules/rxjs/internal/operators/mergeMap.js:76:14)
    at MergeMapSubscriber._next (/home/ivan/act/apu/apspace/node_modules/@angular-devkit/schematics/node_modules/rxjs/internal/operators/mergeMap.js:59:18)
    at MergeMapSubscriber.Subscriber.next (/home/ivan/act/apu/apspace/node_modules/@angular-devkit/schematics/node_modules/rxjs/internal/Subscriber.js:66:18)

@kamilkisiela
Copy link
Owner Author

@KeithGillette @pickfire 2.0.3?

The previous version tried to remove comments from package.json file but I refactored it to use JSON.parse instead and left it for other .json files like tsconfig.

@pickfire
Copy link

pickfire commented Aug 5, 2020

Yes, it works now. 🎉

> ng update apollo-angular
Using package manager: 'yarn'
Collecting installed dependencies...
Found 120 dependencies.
Fetching dependency metadata from registry...
                  Package "apollo-angular" has a missing peer dependency of "@apollo/client" @ "^3.0.0".
    Updating package.json with dependency apollo-angular @ "2.0.3" (was "1.10.0")...
    Updating package.json with dependency graphql @ "15.3.0" (was "0.11.7")...
UPDATE package.json (7760 bytes)
✔ Packages installed successfully.
** Executing migrations of package 'apollo-angular' **

▸ Update to Apollo Angular 2 and Apollo Client 3
    Removed graphql-tag dependency
    Removed apollo-client dependency
    Removed apollo-cache-inmemory dependency
    Removed apollo-link dependency
    Removed apollo-link-http dependency
    Removed apollo-angular-link-http dependency
UPDATE src/app/graphql.module.ts (1395 bytes)
UPDATE src/app/pages/attendix/student/student.page.ts (5965 bytes)
UPDATE src/generated/graphql.ts (9808 bytes)
UPDATE tsconfig.base.json (709 bytes)
UPDATE package.json (7583 bytes)
✔ Packages installed successfully.
  Migration completed.

@slimlime
Copy link

slimlime commented Aug 5, 2020

Nice work 🚀!

Are those utility dependencies no longer required?
Ran the ng update and similarly followed the prompts

    Removed graphql-tag dependency
    Removed apollo-client dependency
    Removed apollo-cache-inmemory dependency
    Removed apollo-link dependency
    Removed apollo-link-http dependency
    Removed apollo-angular-link-http dependency

Which looks a bit scary on first impression.

@kamilkisiela
Copy link
Owner Author

@slimlime

I don't think I mentioned https://apollo-angular.com/docs/migration, there's pretty much everything you need to know about the new and old versions.

Basically, there's one @apollo/client package with multiple entry points, same with apollo-angular which has now /http and /header entries. All the removed packages are now included in those two modules. The graphql-tag is a dependency of @apollo/client which reexports gql (apollo-angular does the same).

@slimlime
Copy link

slimlime commented Aug 5, 2020

@kamilkisiela Thanks for linking Migration Guide | Apollo Angular 2.0.0-next with the following explanation.

Much clearer now 😃

Helps more people landing here as initial searches jumped either old migrations, general or React details to the top of the listings)

@KeithGillette
Copy link
Contributor

Still seeing the following issues with 2.0.3:

  • Migrated import contains incorrect package name: import { RefetchQueryDescription } from 'apollo-client/core/watchQueryOptions';
  • Migrated import not found: import { ExecutionResult } from '@apollo/client/core'; Is it now import { ExecutionResult } from 'graphql/execution';?
  • Not migrated: import { ServerError } from 'apollo-link-http-common'; Is it now import { ServerError } from '@apollo/client/core';?
  • Removed without migration: import ApolloClient from 'apollo-client'; instead of import { ApolloClient } from '@apollo/client';

Trivial:

  • Deleted imports leaving blank lines
  • Could replace deprecated calls to Apollo.getClient() with Apollo.client

@slimlime
Copy link

slimlime commented Aug 9, 2020

Ended up tracking a resolution for the issue below while writing it up... Confusing;, requires attention to detail. Left notes here in case other people migrate and missed some points. Still in the progress of migrating other usages and hope no other issues arise.

Missed some details in the many changes.

Also, the ng update apollo-angular never worked in three of my projects; erroring out in saying package.json is unparseable. Strange because one of my new projects is built up from scratch and should expect less errors than an established codebase.

Note from the apollo-angular.com/docs/migration:

Important! Migration doesn't cover all use-cases and NgModules like ApolloModule or HttpLinkModule have to be deleted manually. To improve the migration script, please open issues and PRs!

Differences between apollo-angular HttpLink vs apollo-client HttpLink?

  • Is one just for the initial creation and Angular dependency injection-way of doing things?

Is there a migration instruction for using HttpLinkHandler

Docs from other places are still confusing and our migration guide does not list at the top of search results.

Could we have an interim note on https://www.apollographql.com/docs/angular/basics/setup/ https://www.apollographql.com/docs/angular/migration/ denoting the versions to avoid confusion?

https://www.apollographql.com/docs/angular/features/subscriptions/

    // - FIXME: No longer able to create a HttpLinkHandler
    const http: HttpLinkHandler = httpLink.create({
      uri: 'http://localhost:3000/graphql'
    });

    // Create a WebSocket link:
    const ws = new WebSocketLink({
      uri: `ws://localhost:5000/`,
      options: {
        reconnect: true
      }
    });

Do we still have the httpLink provided in deps to a factory function on AppModule per previous docs?

The previous split link example (for real time subscription vs query/mutation) relied on creating a HttpLinkHandler from a provided httpLink (rather than calling new httpLink(). I am not sure what the canonical example would be now as it seems different to see the WebSocket link created with new WebSocketLink() and whether we should instantiate a separate new HttpLink().

Any ideas?

https://www.apollographql.com/docs/angular/basics/setup/, again, the React docs seem more up-to-date.


Looking at the declarations

The apollo-angular.com migration before-after diff shows no difference, but my node_modules declarations of HttpLink before and after no longer has the create() function.

From the installed node modules before and after.

From the apollo-angular-2.0.0-next migration doc.

@NgModule({
  imports: [
    // ... other modules
    HttpClientModule,
-   HttpLinkModule,
-   ApolloModule,
  ],
  providers: [
    {
      provide: APOLLO_OPTIONS,
      useFactory(httpLink: HttpLink) {
        return {
          cache: new InMemoryCache(),
          link: httpLink.create({
            uri: 'http://localhost:3000',
          }),
        };
      },
      deps: [HttpLink],
    },
  ],
})
class AppModule {}

  • Fixed my error I noted where I and VS Code auto-import went wrong. Sorted through a lot of clashing namespaces that seem very developer-unfriendly between apollo-client and apollo-angular –but missed this one.
    I imagine this may have been one of the reasons the modules were split up before and have not been fully smoothed over.
// angular-apollo version
import { HttpClient } from '@angular/common/http';
import { ApolloLink, Observable as LinkObservable, Operation, FetchResult } from '@apollo/client/core';
import { Options } from './types';
import * as ɵngcc0 from '@angular/core';
export declare class HttpLinkHandler extends ApolloLink {
    private httpClient;
    private options;
    requester: (operation: Operation) => LinkObservable<FetchResult> | null;
    constructor(httpClient: HttpClient, options: Options);
    request(op: Operation): LinkObservable<FetchResult> | null;
}
export declare class HttpLink {
    private httpClient;
    constructor(httpClient: HttpClient);
    create(options: Options): HttpLinkHandler;
    static ɵfac: ɵngcc0.ɵɵFactoryDef<HttpLink, never>;
}

//# sourceMappingURL=http-link.d.ts.map
// apollo-client version
import { ApolloLink, RequestHandler } from '../core';
import { HttpOptions } from './selectHttpOptionsAndBody';
export declare class HttpLink extends ApolloLink {
    options: HttpOptions;
    requester: RequestHandler;
    constructor(options?: HttpOptions);
}
//# sourceMappingURL=HttpLink.d.ts.map

@kamilkisiela
Copy link
Owner Author

@KeithGillette nested imports of apollo-client or other packages are not supported because it's something internal (the way code is written and it's not the public api). With graphql package it's the same, the maintainers have to keep graphql/execution and other nested imports because a lot of folks are using them.

About apollo-link-http-common, this could be added to migration.

Could replace deprecated calls to Apollo.getClient() with Apollo.client

It's trivial, I could write the whole migration, we (The Guild work a lot with AST but it's time consuming and I don't want to invest a lot of time into it, just basics so someone could push it forward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants