Skip to content

Commit baf538a

Browse files
committed
Drop deprecated things
Instead of `ApolloModule`, use either `provideApollo()` or `provideNamedApollo()`. Instead of `import {graphql} from 'apollo-angular';` use `import {gql as graphql} from 'apollo-angular';`
1 parent f86e55d commit baf538a

File tree

8 files changed

+24
-46
lines changed

8 files changed

+24
-46
lines changed

.changeset/sweet-pigs-fix.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'apollo-angular': major
3+
---
4+
5+
Drop deprecated things:
6+
7+
- Instead of `ApolloModule`, use either `provideApollo()` or `provideNamedApollo()`.
8+
- Instead of `import {graphql} from 'apollo-angular';` use `import {gql as graphql} from 'apollo-angular';`
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,19 @@
1-
import { APOLLO_OPTIONS, ApolloModule } from 'apollo-angular';
1+
import { provideApollo } from 'apollo-angular';
22
import { HttpLink } from 'apollo-angular/http';
3-
import { NgModule } from '@angular/core';
3+
import { inject, NgModule } from '@angular/core';
44
import { ApolloClientOptions, InMemoryCache } from '@apollo/client/core';
55

6-
const uri = '<%= endpoint %>'; // <-- add the URL of the GraphQL server here
7-
export function createApollo(httpLink: HttpLink): ApolloClientOptions<any> {
6+
export function createApollo(): ApolloClientOptions<any> {
7+
const uri = '<%= endpoint %>'; // <-- add the URL of the GraphQL server here
8+
const httpLink = inject(HttpLink);
9+
810
return {
911
link: httpLink.create({ uri }),
1012
cache: new InMemoryCache(),
1113
};
1214
}
1315

1416
@NgModule({
15-
exports: [ApolloModule],
16-
providers: [
17-
{
18-
provide: APOLLO_OPTIONS,
19-
useFactory: createApollo,
20-
deps: [HttpLink],
21-
},
22-
],
17+
providers: [provideApollo(createApollo)],
2318
})
2419
export class GraphQLModule {}

packages/apollo-angular/src/apollo-module.ts

+1-14
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,9 @@
1-
import { NgModule, Provider } from '@angular/core';
1+
import { Provider } from '@angular/core';
22
import { ApolloClientOptions } from '@apollo/client/core';
33
import { Apollo } from './apollo';
44
import { APOLLO_FLAGS, APOLLO_NAMED_OPTIONS, APOLLO_OPTIONS } from './tokens';
55
import { Flags, NamedOptions } from './types';
66

7-
/**
8-
* This is deprecated and will be removed in the next major version, because
9-
* Angular is moving toward a moduleless ecosystem.
10-
*
11-
* Instead, use either `provideApollo()` or `provideNamedApollo()`.
12-
*
13-
* @deprecated
14-
*/
15-
@NgModule({
16-
providers: [Apollo],
17-
})
18-
export class ApolloModule {}
19-
207
export function provideApollo<TCacheShape = any>(
218
optionsFactory: () => ApolloClientOptions<TCacheShape>,
229
flags: Flags = {},

packages/apollo-angular/src/gql.ts

-5
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,3 @@ const typedGQLTag: <Result, Variables>(
66
) => TypedDocumentNode<Result, Variables> = gqlTag;
77

88
export const gql = typedGQLTag;
9-
10-
/**
11-
* @deprecated Instead, use `import {gql as graphql} from 'apollo-angular';`. Because different exports for the same thing will increase the final bundle size.
12-
*/
13-
export const graphql = typedGQLTag;

packages/apollo-angular/src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export type { TypedDocumentNode } from '@apollo/client/core';
2-
export { ApolloModule, provideApollo, provideNamedApollo } from './apollo-module';
2+
export { provideApollo, provideNamedApollo } from './apollo-module';
33
export { Apollo, ApolloBase } from './apollo';
44
export { QueryRef, QueryRefFromDocument } from './query-ref';
55
export { Query } from './query';
@@ -19,4 +19,4 @@ export type {
1919
WatchQueryOptions,
2020
WatchQueryOptionsAlone,
2121
} from './types';
22-
export { gql, graphql } from './gql';
22+
export { gql } from './gql';

packages/apollo-angular/testing/src/module.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Apollo, ApolloModule } from 'apollo-angular';
1+
import { Apollo } from 'apollo-angular';
22
import { Inject, InjectionToken, NgModule, Optional } from '@angular/core';
33
import {
44
ApolloCache,
@@ -31,8 +31,8 @@ function addClient(name: string, op: LinkOperation): Operation {
3131
}
3232

3333
@NgModule({
34-
imports: [ApolloModule],
3534
providers: [
35+
Apollo,
3636
ApolloTestingBackend,
3737
{ provide: ApolloTestingController, useExisting: ApolloTestingBackend },
3838
],
+2-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as api from '../src';
22
import { Apollo } from '../src/apollo';
3-
import { ApolloModule, provideApollo, provideNamedApollo } from '../src/apollo-module';
4-
import { gql, graphql } from '../src/gql';
3+
import { provideApollo, provideNamedApollo } from '../src/apollo-module';
4+
import { gql } from '../src/gql';
55
import { QueryRef } from '../src/query-ref';
66

77
describe('public api', () => {
@@ -11,9 +11,6 @@ describe('public api', () => {
1111
test('should export QueryRef', () => {
1212
expect(api.QueryRef).toBe(QueryRef);
1313
});
14-
test('should export ApolloModule', () => {
15-
expect(api.ApolloModule).toBe(ApolloModule);
16-
});
1714
test('should export provideApollo', () => {
1815
expect(api.provideApollo).toBe(provideApollo);
1916
});
@@ -23,7 +20,4 @@ describe('public api', () => {
2320
test('should export gql', () => {
2421
expect(api.gql).toBe(gql);
2522
});
26-
test('should export graphql', () => {
27-
expect(api.graphql).toBe(graphql);
28-
});
2923
});

scripts/prepare-e2e.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ const [, , name, version] = process.argv;
99
function updateComponent() {
1010
let filepath = path.join(cwd, `./${name}/src/app/app.component.ts`);
1111
const code =
12-
`import { Apollo, ApolloModule } from 'apollo-angular';\n` +
12+
`import { Apollo } from 'apollo-angular';\n` +
1313
`import { versionInfo } from 'graphql';\n` +
1414
fs
1515
.readFileSync(filepath, 'utf8')
16-
.replace('AppComponent {', 'AppComponent { constructor(private readonly apollo: Apollo) {}')
17-
.replace('imports: [', 'imports: [ApolloModule, ') +
16+
.replace('AppComponent {', 'AppComponent { constructor(private readonly apollo: Apollo) {}') +
1817
`\n (window as any).GRAPHQL_VERSION = versionInfo.major;`;
1918

2019
fs.writeFileSync(filepath, code, 'utf8');

0 commit comments

Comments
 (0)