Skip to content

Commit

Permalink
Extract TypeScript utility types to apollo-server-env (#2415)
Browse files Browse the repository at this point in the history
We do the same in `apollo-env`, which this package will likely be merged with when we drop Node 6 support.
  • Loading branch information
martijnwalraven authored and abernix committed Mar 7, 2019
1 parent eb56a55 commit 3a3c67d
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
3 changes: 1 addition & 2 deletions packages/apollo-datasource-rest/src/RESTDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
URL,
URLSearchParams,
URLSearchParamsInit,
ValueOrPromise,
} from 'apollo-server-env';

import { DataSource, DataSourceConfig } from 'apollo-datasource';
Expand Down Expand Up @@ -41,8 +42,6 @@ export interface CacheOptions {
export type Body = BodyInit | object;
export { Request };

type ValueOrPromise<T> = T | Promise<T>;

export abstract class RESTDataSource<TContext = any> extends DataSource {
httpCache!: HTTPCache;
context!: TContext;
Expand Down
1 change: 1 addition & 0 deletions packages/apollo-server-env/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './fetch';
export * from './url';
export * from './typescript-utility-types';
2 changes: 2 additions & 0 deletions packages/apollo-server-env/src/typescript-utility-types.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export type ValueOrPromise<T> = T | Promise<T>;
export type WithRequired<T, K extends keyof T> = T & Required<Pick<T, K>>;
6 changes: 2 additions & 4 deletions packages/apollo-server-plugin-base/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { ValueOrPromise, WithRequired } from 'apollo-server-env';
export { WithRequired };
import {
GraphQLServiceContext,
GraphQLRequestContext,
Expand All @@ -11,17 +13,13 @@ export {
GraphQLResponse,
};

type ValueOrPromise<T> = T | Promise<T>;

export interface ApolloServerPlugin {
serverWillStart?(service: GraphQLServiceContext): ValueOrPromise<void>;
requestDidStart?<TContext>(
requestContext: GraphQLRequestContext<TContext>,
): GraphQLRequestListener<TContext> | void;
}

export type WithRequired<T, K extends keyof T> = T & Required<Pick<T, K>>;

export interface GraphQLRequestListener<TContext = Record<string, any>> {
parsingDidStart?(
requestContext: GraphQLRequestContext<TContext>,
Expand Down

0 comments on commit 3a3c67d

Please sign in to comment.