Skip to content

Commit 5c79632

Browse files
chore(federation): Rename buildFederatedSchema -> buildSubgraphSchema (#915)
This deprecates but continues to support usages of buildFederatedSchema by exporting an alias of the existing function.
1 parent be65c42 commit 5c79632

15 files changed

+71
-65
lines changed

docs/source/api/apollo-federation.mdx

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ api_reference: true
77

88
This API reference documents the exports from the `@apollo/federation` package.
99

10-
## `buildFederatedSchema`
10+
## `buildSubgraphSchema`
11+
> This method was renamed from `buildFederatedSchema` after @apollo/federation v0.28.0 (the previous name still works but might be removed in a future release).
1112
1213
A function that takes an array of GraphQL schema modules and returns a federation-ready schema based on those modules:
1314

1415
```js{2}
1516
const server = new ApolloServer({
16-
schema: buildFederatedSchema([{ typeDefs, resolvers }])
17+
schema: buildSubgraphSchema([{ typeDefs, resolvers }])
1718
});
1819
```
1920

@@ -83,13 +84,13 @@ const resolvers = {
8384
};
8485

8586
const server = new ApolloServer({
86-
schema: buildFederatedSchema([{ typeDefs, resolvers }])
87+
schema: buildSubgraphSchema([{ typeDefs, resolvers }])
8788
});
8889
```
8990

9091
## `__resolveReference`
9192

92-
The name of a special **reference resolver** function you can define for every [entity](../entities/) in a resolver map, _if_ that resolver map is part of a [federated schema](#buildfederatedschema).
93+
The name of a special **reference resolver** function you can define for every [entity](../entities/) in a resolver map, _if_ that resolver map is part of a [subgraph schema](#buildSubgraphSchema).
9394

9495
The `__resolveReference` function enables your gateway's query planner to resolve a particular entity by whatever unique identifier your other subgraphs use to reference it. For details, see [Entities: Resolving](../entities/#resolving).
9596

docs/source/migrating-from-stitching.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ If your implementing services use Apollo Server, add federation support to them
4343
npm install @apollo/federation
4444
```
4545

46-
Then use the `buildFederatedSchema` function to augment your schema with fields that are necessary for federation support:
46+
Then use the `buildSubgraphSchema` function to augment your schema with fields that are necessary for federation support:
4747

4848
```js
4949
const { ApolloServer } = require('apollo-server');
50-
const { buildFederatedSchema } = require('@apollo/federation');
50+
const { buildSubgraphSchema } = require('@apollo/federation');
5151

5252
const server = new ApolloServer({
53-
schema: buildFederatedSchema([
53+
schema: buildSubgraphSchema([
5454
{
5555
typeDefs,
5656
resolvers,

docs/source/quickstart-pt-3.mdx

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,21 @@ First, install the `@apollo/federation` library in your project:
2525
npm install @apollo/federation
2626
```
2727

28-
Next, import the `buildFederatedSchema` function in the file where you initialize `ApolloServer`:
28+
Next, import the `buildSubgraphSchema` function in the file where you initialize `ApolloServer`:
2929

3030
```js:title=index.js
31-
const { buildFederatedSchema } = require('@apollo/federation');
31+
const { buildSubgraphSchema } = require('@apollo/federation');
3232
```
3333

3434
Finally, modify your `ApolloServer` constructor by passing it a `schema` option instead of `typeDefs` and `resolvers`, like so:
3535

3636
```js:title=index.js
3737
const server = new ApolloServer({
38-
schema: buildFederatedSchema([{ typeDefs, resolvers }])
38+
schema: buildSubgraphSchema([{ typeDefs, resolvers }])
3939
});
4040
```
4141

42-
(As shown, you now pass your `typeDefs` and `resolvers` to `buildFederatedSchema`.)
42+
(As shown, you now pass your `typeDefs` and `resolvers` to `buildSubgraphSchema`.)
4343

4444
And that's it! You can now perform all of the same subgraph setup on your _own_ service (introspection, schema registration, etc.) that you did with the Apollo-hosted services we used in the first two parts. Refer to those parts for guidance.
4545

docs/source/subgraphs.mdx

+8-8
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ As part of our federated architecture, we want _other_ subgraphs to be able to e
6262

6363
```js:title=index.js
6464
const { ApolloServer, gql } = require('apollo-server');
65-
const { buildFederatedSchema } = require('@apollo/federation');
65+
const { buildSubgraphSchema } = require('@apollo/federation');
6666

6767
const typeDefs = gql`
6868
type Query {
@@ -99,13 +99,13 @@ const resolvers = {
9999

100100
> [Learn more about entities](./entities/)
101101
102-
### Generating a federated schema
102+
### Generating a subgraph schema
103103

104-
Finally, we use the `buildFederatedSchema` function from the `@apollo/federation` package to augment our schema definition with federation support. We provide the result of this function to the `ApolloServer` constructor:
104+
Finally, we use the `buildSubgraphSchema` function from the `@apollo/federation` package to augment our schema definition with federation support. We provide the result of this function to the `ApolloServer` constructor:
105105

106106
```js:title=index.js
107107
const server = new ApolloServer({
108-
schema: buildFederatedSchema([{ typeDefs, resolvers }])
108+
schema: buildSubgraphSchema([{ typeDefs, resolvers }])
109109
});
110110

111111
server.listen(4001).then(({ url }) => {
@@ -121,7 +121,7 @@ Here are the snippets above combined (again, note that for this sample to be com
121121

122122
```js:title=index.js
123123
const { ApolloServer, gql } = require('apollo-server');
124-
const { buildFederatedSchema } = require('@apollo/federation');
124+
const { buildSubgraphSchema } = require('@apollo/federation');
125125

126126
const typeDefs = gql`
127127
type Query {
@@ -148,7 +148,7 @@ const resolvers = {
148148
}
149149

150150
const server = new ApolloServer({
151-
schema: buildFederatedSchema([{ typeDefs, resolvers }])
151+
schema: buildSubgraphSchema([{ typeDefs, resolvers }])
152152
});
153153

154154
server.listen(4001).then(({ url }) => {
@@ -191,7 +191,7 @@ const server = new ApolloServer({
191191

192192
```js
193193
const { ApolloServer, gql, SchemaDirectiveVisitor } = require('apollo-server');
194-
const { buildFederatedSchema } = require ('@apollo/federation')
194+
const { buildSubgraphSchema } = require ('@apollo/federation')
195195

196196
// typeDefs and resolvers defined here
197197

@@ -205,7 +205,7 @@ class DeprecatedDirective extends SchemaDirectiveVisitor {
205205
const directives = {
206206
deprecated: DeprecatedDirective
207207
};
208-
let schema = buildFederatedSchema([{ typeDefs, resolvers }]);
208+
let schema = buildSubgraphSchema([{ typeDefs, resolvers }]);
209209

210210
SchemaDirectiveVisitor.visitSchemaDirectives(schema, directives);
211211

federation-js/CHANGELOG.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
> The changes noted within this `vNEXT` section have not been released yet. New PRs and commits which introduce changes should include an entry in this `vNEXT` section as part of their development. When a release is being prepared, a new header will be (manually) created below and the appropriate changes within that release will be moved into the new section.
66
7-
-_Nothing yet! Stay tuned_.
7+
- Rename `buildFederatedSchema` to `buildSubgraphSchema`. The previous name will continue to be supported but is deprecated. No functional change, usages of `buildFederatedSchema` should just be replaced with `buildSubgraphSchema`. [PR #915](https://github.com/apollographql/federation/pull/913)
88

99
## v0.28.0
1010

11-
- When resolving the `Query._entities` field, honor `@cacheControl` directives on the object types that are members of the `_Entity` union. This feature is only enabled when your subgraph is running Apollo Server 3.0.2 or later. [PR #870](https://github.com/apollographql/apollo-server/pull/870) [Related docs PR](https://github.com/apollographql/apollo-server/pull/5536)
11+
- When resolving the `Query._entities` field, honor `@cacheControl` directives on the object types that are members of the `_Entity` union. This feature is only enabled when your subgraph is running Apollo Server 3.0.2 or later. [PR #870](https://github.com/apollographql/federation/pull/870) [Related docs PR](https://github.com/apollographql/apollo-server/pull/5536)
1212

1313
## v0.27.1
1414

federation-js/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ For complete documentation, see the [Apollo Federation API reference](https://ww
88

99
```js
1010
const { ApolloServer, gql } = require("apollo-server");
11-
const { buildFederatedSchema } = require("@apollo/federation");
11+
const { buildSubgraphSchema } = require("@apollo/federation");
1212

1313
const typeDefs = gql`
1414
type Query {
@@ -35,6 +35,6 @@ const resolvers = {
3535
};
3636

3737
const server = new ApolloServer({
38-
schema: buildFederatedSchema([{ typeDefs, resolvers }])
38+
schema: buildSubgraphSchema([{ typeDefs, resolvers }])
3939
});
4040
```

federation-js/src/service/__tests__/buildFederatedSchema.test.ts renamed to federation-js/src/service/__tests__/buildSubgraphSchema.test.ts

+23-23
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import gql from 'graphql-tag';
22
import { Kind, graphql, DocumentNode, execute } from 'graphql';
3-
import { buildFederatedSchema } from '../buildFederatedSchema';
3+
import { buildSubgraphSchema } from '../buildSubgraphSchema';
44
import { typeSerializer } from 'apollo-federation-integration-testsuite';
55

66
expect.addSnapshotSerializer(typeSerializer);
@@ -10,9 +10,9 @@ const EMPTY_DOCUMENT = {
1010
definitions: [],
1111
};
1212

13-
describe('buildFederatedSchema', () => {
13+
describe('buildSubgraphSchema', () => {
1414
it(`should mark a type with a key field as an entity`, () => {
15-
const schema = buildFederatedSchema(gql`
15+
const schema = buildSubgraphSchema(gql`
1616
type Product @key(fields: "upc") {
1717
upc: String!
1818
name: String
@@ -34,7 +34,7 @@ type Product {
3434
});
3535

3636
it(`should mark a type with multiple key fields as an entity`, () => {
37-
const schema = buildFederatedSchema(gql`
37+
const schema = buildSubgraphSchema(gql`
3838
type Product @key(fields: "upc") @key(fields: "sku") {
3939
upc: String!
4040
sku: String!
@@ -58,7 +58,7 @@ type Product {
5858
});
5959

6060
it(`should not mark a type without a key field as an entity`, () => {
61-
const schema = buildFederatedSchema(gql`
61+
const schema = buildSubgraphSchema(gql`
6262
type Money {
6363
amount: Int!
6464
currencyCode: String!
@@ -79,7 +79,7 @@ type Money {
7979
sdl
8080
}
8181
}`;
82-
const schema = buildFederatedSchema(gql`
82+
const schema = buildSubgraphSchema(gql`
8383
"A user. This user is very complicated and requires so so so so so so so so so so so so so so so so so so so so so so so so so so so so so so so so much description text"
8484
type User @key(fields: "id") {
8585
"""
@@ -130,7 +130,7 @@ type User @key(fields: "id") {
130130

131131
describe(`should add an _entities query root field to the schema`, () => {
132132
it(`when a query root type with the default name has been defined`, () => {
133-
const schema = buildFederatedSchema(gql`
133+
const schema = buildSubgraphSchema(gql`
134134
type Query {
135135
rootField: String
136136
}
@@ -149,7 +149,7 @@ type Query {
149149
});
150150

151151
it(`when a query root type with a non-default name has been defined`, () => {
152-
const schema = buildFederatedSchema(gql`
152+
const schema = buildSubgraphSchema(gql`
153153
schema {
154154
query: QueryRoot
155155
}
@@ -173,7 +173,7 @@ type QueryRoot {
173173
});
174174
describe(`should not add an _entities query root field to the schema`, () => {
175175
it(`when no query root type has been defined`, () => {
176-
const schema = buildFederatedSchema(EMPTY_DOCUMENT);
176+
const schema = buildSubgraphSchema(EMPTY_DOCUMENT);
177177

178178
expect(schema.getQueryType()).toMatchInlineSnapshot(`
179179
type Query {
@@ -182,7 +182,7 @@ type Query {
182182
`);
183183
});
184184
it(`when no types with keys are found`, () => {
185-
const schema = buildFederatedSchema(gql`
185+
const schema = buildSubgraphSchema(gql`
186186
type Query {
187187
rootField: String
188188
}
@@ -196,7 +196,7 @@ type Query {
196196
`);
197197
});
198198
it(`when only an interface with keys are found`, () => {
199-
const schema = buildFederatedSchema(gql`
199+
const schema = buildSubgraphSchema(gql`
200200
type Query {
201201
rootField: String
202202
}
@@ -233,7 +233,7 @@ type Query {
233233
],
234234
};
235235

236-
const schema = buildFederatedSchema([
236+
const schema = buildSubgraphSchema([
237237
{
238238
typeDefs: gql`
239239
type Product @key(fields: "upc") {
@@ -287,7 +287,7 @@ type Query {
287287
],
288288
};
289289

290-
const schema = buildFederatedSchema(gql`
290+
const schema = buildSubgraphSchema(gql`
291291
type Product @key(fields: "upc") {
292292
upc: Int
293293
name: String
@@ -311,7 +311,7 @@ type Query {
311311
sdl
312312
}
313313
}`;
314-
const schema = buildFederatedSchema(gql`
314+
const schema = buildSubgraphSchema(gql`
315315
type Review {
316316
id: ID
317317
}
@@ -346,7 +346,7 @@ type Review {
346346
sdl
347347
}
348348
}`;
349-
const schema = buildFederatedSchema(gql`
349+
const schema = buildSubgraphSchema(gql`
350350
type Review {
351351
id: ID
352352
}
@@ -388,7 +388,7 @@ type Review {
388388
sdl
389389
}
390390
}`;
391-
const schema = buildFederatedSchema(gql`
391+
const schema = buildSubgraphSchema(gql`
392392
type Product @key(fields: "upc") {
393393
upc: String!
394394
name: String
@@ -411,7 +411,7 @@ type Review {
411411
sdl
412412
}
413413
}`;
414-
const schema = buildFederatedSchema(gql`
414+
const schema = buildSubgraphSchema(gql`
415415
type Product @key(fields: "upc") @key(fields: "name") {
416416
upc: String!
417417
name: String
@@ -436,7 +436,7 @@ type Review {
436436
}
437437
}`;
438438

439-
const schema = buildFederatedSchema(gql`
439+
const schema = buildSubgraphSchema(gql`
440440
type Review @key(fields: "id") {
441441
id: ID!
442442
body: String
@@ -483,7 +483,7 @@ extend type User @key(fields: "email") {
483483
}
484484
}`;
485485

486-
const schema = buildFederatedSchema(gql`
486+
const schema = buildSubgraphSchema(gql`
487487
directive @custom on FIELD
488488
489489
extend type User @key(fields: "email") {
@@ -530,7 +530,7 @@ describe('legacy interface', () => {
530530
`,
531531
];
532532
it('allows legacy schema module interface as an input with an array of typeDefs and resolvers', async () => {
533-
const schema = buildFederatedSchema({ typeDefs, resolvers });
533+
const schema = buildSubgraphSchema({ typeDefs, resolvers });
534534
expect(schema.getType('_Entity')).toMatchInlineSnapshot(
535535
`union _Entity = Product`,
536536
);
@@ -553,7 +553,7 @@ describe('legacy interface', () => {
553553
});
554554
});
555555
it('allows legacy schema module interface as a single module', async () => {
556-
const schema = buildFederatedSchema({
556+
const schema = buildSubgraphSchema({
557557
typeDefs: gql`
558558
type Query {
559559
product: Product
@@ -588,7 +588,7 @@ describe('legacy interface', () => {
588588
});
589589
});
590590
it('allows legacy schema module interface as a single module without resolvers', async () => {
591-
const schema = buildFederatedSchema({
591+
const schema = buildSubgraphSchema({
592592
typeDefs: gql`
593593
type Query {
594594
product: Product
@@ -612,7 +612,7 @@ type Product {
612612
);
613613
});
614614
it('allows legacy schema module interface as a simple array of documents', async () => {
615-
const schema = buildFederatedSchema({ typeDefs });
615+
const schema = buildSubgraphSchema({ typeDefs });
616616
expect(schema.getType('Product')).toMatchInlineSnapshot(`
617617
type Product {
618618
upc: String!

federation-js/src/service/buildFederatedSchema.ts renamed to federation-js/src/service/buildSubgraphSchema.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type LegacySchemaModule = {
2828

2929
export { GraphQLSchemaModule };
3030

31-
export function buildFederatedSchema(
31+
export function buildSubgraphSchema(
3232
modulesOrSDL:
3333
| (GraphQLSchemaModule | DocumentNode)[]
3434
| DocumentNode
@@ -38,9 +38,9 @@ export function buildFederatedSchema(
3838
// map of resolvers to build a schema. Long term we don't want to support this
3939
// style anymore as we move towards a more structured approach to modules,
4040
// however, it has tripped several teams up to not support this signature
41-
// in buildFederatedSchema. Especially as teams migrate from
41+
// in buildSubgraphSchema. Especially as teams migrate from
4242
// `new ApolloServer({ typeDefs: DocumentNode[], resolvers })` to
43-
// `new ApolloServer({ schema: buildFederatedSchema({ typeDefs: DocumentNode[], resolvers }) })`
43+
// `new ApolloServer({ schema: buildSubgraphSchema({ typeDefs: DocumentNode[], resolvers }) })`
4444
//
4545
// The last type in the union for `modulesOrSDL` supports this "legacy" input
4646
// style in a simple manner (by just adding the resolvers to the first typeDefs entry)
@@ -132,3 +132,8 @@ export function buildFederatedSchema(
132132

133133
return schema;
134134
}
135+
136+
/**
137+
* @deprecated Use `buildSubgraphSchema` instead.
138+
*/
139+
export const buildFederatedSchema = buildSubgraphSchema;

0 commit comments

Comments
 (0)