Skip to content

fix: wrap deprecated functions with util.deprecate() #1033

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

Merged
merged 4 commits into from
Oct 5, 2021
Merged
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: 2 additions & 0 deletions federation-js/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
> 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.

- Refine internal types to `FieldSet`s in places where we previously used `SelectionNode[]` [PR #1030](https://github.com/apollographql/federation/pull/1030)
- Emit a deprecation warning for deprecated functions. [PR #1033](https://github.com/apollographql/federation/pull/1033).
We would advise to adjust the code to use the new functionality, as the deprecated functions will be removed in a future version. If needed, deprecation warnings can be muted with either the --no-deprecation or --no-warnings command-line flags for node.js. Please keep in mind in doing so will also prevent any future deprecation warnings from node.js itself as well as from any package.

## v0.33.0

Expand Down
6 changes: 5 additions & 1 deletion federation-js/src/service/buildSubgraphSchema.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { deprecate } from 'util';
import {
DocumentNode,
GraphQLSchema,
Expand Down Expand Up @@ -136,4 +137,7 @@ export function buildSubgraphSchema(
/**
* @deprecated Use `buildSubgraphSchema` instead.
*/
export const buildFederatedSchema = buildSubgraphSchema;
export const buildFederatedSchema = deprecate(
buildSubgraphSchema,
`'buildFederatedSchema' is deprecated. Use 'buildSubgraphSchema' instead.`,
);
6 changes: 5 additions & 1 deletion federation-js/src/service/printSubgraphSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* This file has been modified to support printing subgraph
* schema, including associated federation directives.
*/
import { deprecate } from 'util';
import {
GraphQLSchema,
isSpecifiedDirective,
Expand Down Expand Up @@ -37,7 +38,10 @@ import { federationDirectives, gatherDirectives } from '../directives';
/**
* @deprecated Use `printSubgraphSchema` instead.
*/
export const printSchema = printSubgraphSchema;
export const printSchema = deprecate(
printSubgraphSchema,
`'printSchema' is deprecated. Use 'printSubgraphSchema' instead.`,
);

export function printSubgraphSchema(schema: GraphQLSchema): string {
return printFilteredSchema(
Expand Down
2 changes: 1 addition & 1 deletion gateway-js/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

> 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.

- _Nothing yet! Stay tuned!_
- Emit a deprecation warning for deprecated functions. [PR #1033](https://github.com/apollographql/federation/pull/1033)

## v0.42.0

Expand Down
11 changes: 10 additions & 1 deletion gateway-js/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { deprecate } from 'util';
import { GraphQLService, Unsubscriber } from 'apollo-server-core';
import {
GraphQLExecutionResult,
Expand Down Expand Up @@ -117,7 +118,10 @@ export function getDefaultFetcher() {
* TODO(trevor:cloudconfig): Stop exporting this
* @deprecated This will be removed in a future version of @apollo/gateway
*/
export const getDefaultGcsFetcher = getDefaultFetcher;
export const getDefaultGcsFetcher = deprecate(
getDefaultFetcher,
`'getDefaultGcsFetcher' is deprecated. Use 'getDefaultFetcher' instead.`,
);
/**
* TODO(trevor:cloudconfig): Stop exporting this
* @deprecated This will be removed in a future version of @apollo/gateway
Expand Down Expand Up @@ -1270,6 +1274,11 @@ export class ApolloGateway implements GraphQLService {
}
}

ApolloGateway.prototype.onSchemaChange = deprecate(
ApolloGateway.prototype.onSchemaChange,
`'ApolloGateway.prototype.onSchemaChange' is deprecated. Use 'ApolloGateway.prototype.onSchemaLoadOrUpdate' instead.`,
);

function approximateObjectSize<T>(obj: T): number {
return Buffer.byteLength(JSON.stringify(obj), 'utf8');
}
Expand Down