Skip to content

Commit

Permalink
Introduce new apollo-server-types package for shared types. (#2990)
Browse files Browse the repository at this point in the history
This moves TypeScript types which are shared by many aspects of Apollo
Server into their own, new, `apollo-server-types` package which can be
depended on directly by the various parts of Apollo Server (and other Apollo
tools) with minimal additional dependency weight.  This helps avoid, for
example, bringing in the heavier weight of `apollo-server-core` merely to
provide some type dependencies.

Furthermore, this aims to remove one of the obvious sources of cycles in our
dependency graph, which occurs when `apollo-engine-reporting` depends on
`apollo-server-core` (for types!), which itself depends on
`apollo-engine-reporting`.  While these cycles are (roughly) fine at runtime
because they're type _merely_ type dependencies, is still made abundantly
obvious (read: noisy) during Lerna publishing.

As part of this project, I've also moved a couple types from
`apollo-server-env` — `PromiseOrValue` and `WithRequired` — into this new
`apollo-server-types` package, since they seemed less like ECMAScript
compatibility needs (i.e. polyfills; which is primarily what that package
aims to provide).  Providing these shared types from a package which has
import side-effects just seemed like it _could be_ considered bad form and
it seemed more appropriate to put them in a "types" package (now that we
have it).  I've left them in `apollo-server-env` for compatibility reasons,
and I suspect `apollo-server-env` will be deprecated soon and replaced with
`apollo-env`.

Lastly, I've also continued to re-export these types from
`packages/apollo-server-core/src/requestPipelineAPI.ts` as a matter of
backwards compatibility, but after this change that single file is no longer
its own TypeScript project, which was originally done to avoid cycles on
`apollo-server-plugin-base`.
  • Loading branch information
abernix committed Jul 9, 2019
1 parent 02feb8a commit aa3e23d
Show file tree
Hide file tree
Showing 101 changed files with 324 additions and 221 deletions.
32 changes: 26 additions & 6 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"apollo-server-plugin-base": "file:packages/apollo-server-plugin-base",
"apollo-server-plugin-response-cache": "file:packages/apollo-server-plugin-response-cache",
"apollo-server-testing": "file:packages/apollo-server-testing",
"apollo-server-types": "file:packages/apollo-server-types",
"apollo-tracing": "file:packages/apollo-tracing",
"graphql-extensions": "file:packages/graphql-extensions"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-cache-control/src/__tests__/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"extends": "../../../../tsconfig.test.base",
"include": ["**/*"],
"references": [
{ "path": "../../" }
{ "path": "../../" },
]
}
2 changes: 1 addition & 1 deletion packages/apollo-cache-control/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ declare module 'graphql/type/definition' {
}
}

declare module 'apollo-server-core/dist/requestPipelineAPI' {
declare module 'apollo-server-types' {
interface GraphQLRequestContext<TContext> {
// Not readonly: plugins can set it.
overallCachePolicy?: Required<CacheHint> | undefined;
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-cache-control/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
"include": ["src/**/*"],
"exclude": ["**/__tests__", "**/__mocks__"],
"references": [
{ "path": "../graphql-extensions" }
{ "path": "../graphql-extensions" },
]
}
3 changes: 3 additions & 0 deletions packages/apollo-datasource-rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@
"apollo-server-env": "file:../apollo-server-env",
"apollo-server-errors": "file:../apollo-server-errors",
"http-cache-semantics": "^4.0.0"
},
"devDependencies": {
"apollo-server-types": "file:../apollo-server-types"
}
}
3 changes: 2 additions & 1 deletion packages/apollo-datasource-rest/src/RESTDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import {
URL,
URLSearchParams,
URLSearchParamsInit,
ValueOrPromise,
} from 'apollo-server-env';

import { ValueOrPromise } from 'apollo-server-types';

import { DataSource, DataSourceConfig } from 'apollo-datasource';

import { HTTPCache } from './HTTPCache';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"extends": "../../../../tsconfig.test.base",
"include": ["**/*", "../../../../__mocks__"],
"references": [
{ "path": "../../" }
{ "path": "../../" },
]
}
3 changes: 2 additions & 1 deletion packages/apollo-datasource-rest/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"references": [
{ "path": "../apollo-datasource" },
{ "path": "../apollo-server-caching" },
{ "path": "../apollo-server-errors" }
{ "path": "../apollo-server-errors" },
{ "path": "../apollo-server-types" },
]
}
2 changes: 1 addition & 1 deletion packages/apollo-engine-reporting/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"dependencies": {
"apollo-engine-reporting-protobuf": "file:../apollo-engine-reporting-protobuf",
"apollo-graphql": "^0.3.3",
"apollo-server-core": "file:../apollo-server-core",
"apollo-server-types": "file:../apollo-server-types",
"apollo-server-env": "file:../apollo-server-env",
"async-retry": "^1.2.1",
"graphql-extensions": "file:../graphql-extensions"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"extends": "../../../../tsconfig.test.base",
"include": ["**/*"],
"references": [
{ "path": "../../" }
{ "path": "../../" },
]
}
2 changes: 1 addition & 1 deletion packages/apollo-engine-reporting/src/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { fetch, RequestAgent, Response } from 'apollo-server-env';
import retry from 'async-retry';

import { EngineReportingExtension } from './extension';
import { GraphQLRequestContext } from 'apollo-server-core/dist/requestPipelineAPI';
import { GraphQLRequestContext } from 'apollo-server-types';
import { InMemoryLRUCache } from 'apollo-server-caching';
import { defaultEngineReportingSignature } from 'apollo-graphql';

Expand Down
5 changes: 2 additions & 3 deletions packages/apollo-engine-reporting/src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Request, Headers, WithRequired } from 'apollo-server-env';

import { GraphQLRequestContext, WithRequired } from 'apollo-server-types';
import { Request, Headers } from 'apollo-server-env';
import {
GraphQLResolveInfo,
responsePathAsArray,
Expand All @@ -18,7 +18,6 @@ import {
VariableValueOptions,
SendValuesBaseOptions,
} from './agent';
import { GraphQLRequestContext } from 'apollo-server-core/dist/requestPipelineAPI';

const clientNameHeaderKey = 'apollographql-client-name';
const clientReferenceIdHeaderKey = 'apollographql-client-reference-id';
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-engine-reporting/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"exclude": ["**/__tests__", "**/__mocks__"],
"references": [
{ "path": "../graphql-extensions" },
{ "path": "../apollo-server-core/tsconfig.requestPipelineAPI.json" }
{ "path": "../apollo-server-types" },
]
}
5 changes: 4 additions & 1 deletion packages/apollo-gateway/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@
"apollo-env": "^0.5.1",
"apollo-graphql": "^0.3.3",
"apollo-server-caching": "file:../apollo-server-caching",
"apollo-server-core": "file:../apollo-server-core",
"apollo-server-env": "file:../apollo-server-env",
"loglevel": "^1.6.1",
"loglevel-debug": "^0.0.1",
"pretty-format": "^24.7.0"
},
"devDependencies": {
"apollo-server-core": "file:../apollo-server-core",
"apollo-server-types": "file:../apollo-server-types"
},
"peerDependencies": {
"graphql": "^14.2.1"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
GraphQLResolverMap,
} from 'apollo-graphql';
import gql from 'graphql-tag';
import { GraphQLRequestContext } from 'apollo-server-core';
import { GraphQLRequestContext } from 'apollo-server-types';
import { composeServices, buildFederatedSchema } from '@apollo/federation';

import { buildQueryPlan, buildOperationContext } from '../buildQueryPlan';
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-gateway/src/__tests__/execution-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
GraphQLSchemaModule,
GraphQLResolverMap,
} from 'apollo-graphql';
import { GraphQLRequest, GraphQLExecutionResult } from 'apollo-server-core';
import { GraphQLRequest, GraphQLExecutionResult } from 'apollo-server-types';
import {
composeAndValidate,
buildFederatedSchema,
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-gateway/src/__tests__/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"extends": "../../../../tsconfig.test.base",
"include": ["**/*"],
"references": [
{ "path": "../../" }
{ "path": "../../" },
]
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GraphQLRequestContext, GraphQLResponse } from 'apollo-server-core';
import { GraphQLRequestContext, GraphQLResponse } from 'apollo-server-types';
import {
GraphQLSchema,
graphql,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { GraphQLRequestContext, GraphQLResponse } from 'apollo-server-core';
import {
GraphQLRequestContext,
GraphQLResponse,
ValueOrPromise,
} from 'apollo-server-types';
import {
ApolloError,
AuthenticationError,
Expand All @@ -10,7 +14,6 @@ import {
RequestInit,
Headers,
Response,
ValueOrPromise,
} from 'apollo-server-env';
import { isObject } from '../utilities/predicates';
import { GraphQLDataSource } from './types';
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-gateway/src/datasources/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GraphQLResponse, GraphQLRequestContext } from 'apollo-server-core';
import { GraphQLResponse, GraphQLRequestContext } from 'apollo-server-types';

export interface GraphQLDataSource {
process<TContext>(
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-gateway/src/executeQueryPlan.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
GraphQLExecutionResult,
GraphQLRequestContext,
} from 'apollo-server-core';
} from 'apollo-server-types';
import {
ASTNode,
execute,
Expand Down
8 changes: 5 additions & 3 deletions packages/apollo-gateway/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import {
GraphQLExecutionResult,
GraphQLRequestContext,
GraphQLService,
SchemaChangeCallback,
Unsubscriber,
GraphQLServiceEngineConfig,
} from 'apollo-server-core';
import {
GraphQLExecutionResult,
GraphQLRequestContext,
WithRequired,
} from 'apollo-server-types';
import { InMemoryLRUCache } from 'apollo-server-caching';
import { isObjectType, isIntrospectionType, GraphQLSchema } from 'graphql';
import { WithRequired } from 'apollo-env';
import { GraphQLSchemaValidationError } from 'apollo-graphql';
import { composeAndValidate, ServiceDefinition } from '@apollo/federation';
import loglevel, { Logger } from 'loglevel';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ServiceDefinition } from '@apollo/federation';
import { GraphQLExecutionResult } from 'apollo-server-core';
import { GraphQLExecutionResult } from 'apollo-server-types';
import { parse } from 'graphql';
import fetch, { HeadersInit } from 'node-fetch';
import { ServiceEndpointDefinition } from './';
Expand Down
1 change: 1 addition & 0 deletions packages/apollo-gateway/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"exclude": ["**/__tests__", "**/__mocks__"],
"references": [
{ "path": "../apollo-server-core" },
{ "path": "../apollo-server-types" },
{ "path": "../apollo-federation" },
]
}
1 change: 1 addition & 0 deletions packages/apollo-server-azure-functions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@apollographql/graphql-playground-html": "1.6.24",
"apollo-server-core": "file:../apollo-server-core",
"apollo-server-env": "file:../apollo-server-env",
"apollo-server-types": "file:../apollo-server-types",
"graphql-tools": "^4.0.0"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
HttpQueryError,
runHttpQuery,
} from 'apollo-server-core';
import { Headers, ValueOrPromise } from 'apollo-server-env';
import { Headers } from 'apollo-server-env';
import { ValueOrPromise } from 'apollo-server-types';

export interface AzureFunctionGraphQLOptionsFunction {
(request: HttpRequest, context: Context): ValueOrPromise<GraphQLOptions>;
Expand Down
Loading

0 comments on commit aa3e23d

Please sign in to comment.