Skip to content

Commit

Permalink
Remove apollo-env dependency from @apollo/federation package (#3463)
Browse files Browse the repository at this point in the history
Currently, a circular dependency exists between apollo-env and
@apollo-federation such that the apollo-tooling repo is unable to
publish due to requiring multiple versions of apollo-env (one old
and one new).

This commit removes the circular dependency, which unblocks the
ability for apollo-tooling to publish.
  • Loading branch information
trevor-scheer authored Nov 12, 2019
1 parent 9d34565 commit 8d730b7
Show file tree
Hide file tree
Showing 15 changed files with 47 additions and 16 deletions.
9 changes: 8 additions & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion packages/apollo-federation/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 the appropriate changes within that release will be moved into the new section.
- _Nothing yet! Stay tuned!_
* Remove `apollo-env` dependency to eliminate circular dependency between the two packages. This circular dependency makes the tooling repo unpublishable when `apollo-env` requires a version bump. [#3463](https://github.com/apollographql/apollo-server/pull/3463)

### v0.10.1

Expand Down
5 changes: 4 additions & 1 deletion packages/apollo-federation/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
const config = require('../../jest.config.base');

module.exports = Object.assign(Object.create(null), config, {
setupFiles: ['apollo-env'],
setupFiles: [
'core-js/features/array/flat',
'core-js/features/array/flat-map',
],
});
2 changes: 1 addition & 1 deletion packages/apollo-federation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
"access": "public"
},
"dependencies": {
"apollo-env": "^0.5.1",
"apollo-graphql": "^0.3.4",
"apollo-server-env": "file:../apollo-server-env",
"core-js": "^3.4.0",
"lodash.xorby": "^4.7.0"
},
"peerDependencies": {
Expand Down
4 changes: 1 addition & 3 deletions packages/apollo-federation/src/composition/compose.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'apollo-server-env';
import 'apollo-env';
import {
GraphQLSchema,
extendSchema,
Expand All @@ -18,9 +17,7 @@ import {
TypeExtensionNode,
GraphQLDirective,
} from 'graphql';
import { mapValues } from 'apollo-env';
import { transformSchema } from 'apollo-graphql';

import federationDirectives from '../directives';
import {
findDirectivesOnTypeOrField,
Expand All @@ -29,6 +26,7 @@ import {
mapFieldNamesToServiceName,
stripExternalFieldsFromTypeDefs,
typeNodesAreEquivalent,
mapValues
} from './utils';
import {
ServiceDefinition,
Expand Down
21 changes: 20 additions & 1 deletion packages/apollo-federation/src/composition/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'apollo-server-env';
import { isNotNullOrUndefined } from 'apollo-env';
import {
InterfaceTypeExtensionNode,
FieldDefinitionNode,
Expand Down Expand Up @@ -447,3 +446,23 @@ export const defKindToExtKind: { [kind: string]: string } = {
[Kind.ENUM_TYPE_DEFINITION]: Kind.ENUM_TYPE_EXTENSION,
[Kind.INPUT_OBJECT_TYPE_DEFINITION]: Kind.INPUT_OBJECT_TYPE_EXTENSION,
};

// Transform an object's values via a callback function
export function mapValues<T, U = T>(
object: Record<string, T>,
callback: (value: T) => U,
): Record<string, U> {
const result: Record<string, U> = Object.create(null);

for (const [key, value] of Object.entries(object)) {
result[key] = callback(value);
}

return result;
}

export function isNotNullOrUndefined<T>(
value: T | null | undefined,
): value is T {
return value !== null && typeof value !== 'undefined';
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ import {
specifiedDirectives,
} from 'graphql';
import { buildSchemaFromSDL } from 'apollo-graphql';
import { isNotNullOrUndefined } from 'apollo-env';

import { federationDirectives } from '../../../directives';
import { ServiceDefinition } from '../../types';
import {
findDirectivesOnTypeOrField,
isStringValueNode,
logServiceAndType,
errorWithCode,
isNotNullOrUndefined
} from '../../utils';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
} from 'graphql';
import { validateSDL } from 'graphql/validation/validate';
import gql from 'graphql-tag';

import { composeServices, buildMapsFromServiceList } from '../../../compose';
import {
astSerializer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
} from 'graphql';
import { validateSDL } from 'graphql/validation/validate';
import gql from 'graphql-tag';

import { buildMapsFromServiceList } from '../../../compose';
import {
typeSerializer,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "../../../../../../../tsconfig.test.base",
"include": ["**/*"],
"references": [{ "path": "../../../../../" }]
}
3 changes: 3 additions & 0 deletions packages/apollo-federation/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
import "core-js/features/array/flat";
import "core-js/features/array/flat-map";

export * from './composition';
export * from './service';
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import {
print,
specifiedDirectives,
} from 'graphql';

import federationDirectives, { gatherDirectives } from '../directives';
import { isFederationType } from '../types';

Expand Down
1 change: 0 additions & 1 deletion packages/apollo-federation/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export const AnyType = new GraphQLScalarType({
},
});

// FIXME: move to apollo-env
function isPromise<T>(value: PromiseOrValue<T>): value is Promise<T> {
return Boolean(value && 'then' in value && typeof value.then === 'function');
}
Expand Down
3 changes: 2 additions & 1 deletion packages/apollo-federation/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"extends": "../../tsconfig.base",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist"
"outDir": "./dist",
"lib": ["es2017", "es2019.array", "esnext.asynciterable"],
},
"include": ["src/**/*"],
"exclude": ["**/__tests__", "**/__mocks__"],
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.test.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"extends": "./tsconfig.base",
"compilerOptions": {
"noEmit": true,
"lib": ["es2017", "esnext.asynciterable"],
"lib": ["es2017", "es2019.array", "esnext.asynciterable"],
"types": ["node", "jest", "apollo-server-env/dist/global"],
"paths": {
"__mocks__/*" : ["__mocks__/*"],
Expand Down

0 comments on commit 8d730b7

Please sign in to comment.