Skip to content

Commit

Permalink
Make initialize method in data sources optional
Browse files Browse the repository at this point in the history
  • Loading branch information
martijnwalraven committed Jul 18, 2018
1 parent 4f7b6e0 commit c4d3a93
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/apollo-datasource/src/index.ts
Expand Up @@ -6,5 +6,5 @@ export interface DataSourceConfig<TContext> {
}

export abstract class DataSource<TContext = any> {
abstract initialize(config: DataSourceConfig<TContext>): void;
initialize?(config: DataSourceConfig<TContext>): void;
}
4 changes: 3 additions & 1 deletion packages/apollo-server-core/src/runHttpQuery.ts
Expand Up @@ -341,7 +341,9 @@ export async function runHttpQuery(
const dataSources = optionsObject.dataSources() || {};

for (const dataSource of Object.values(dataSources)) {
dataSource.initialize({ context, cache: optionsObject.cache! });
if (dataSource.initialize) {
dataSource.initialize({ context, cache: optionsObject.cache! });
}
}

if ('dataSources' in context) {
Expand Down

0 comments on commit c4d3a93

Please sign in to comment.