Skip to content

Commit

Permalink
Add modules option to ApolloServer
Browse files Browse the repository at this point in the history
  • Loading branch information
martijnwalraven committed Nov 9, 2018
1 parent bb67584 commit 8f6481e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/apollo-server-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"node": ">=6"
},
"dependencies": {
"@apollographql/apollo-tools": "^0.2.0",
"@apollographql/apollo-upload-server": "^5.0.3",
"@apollographql/graphql-playground-html": "^1.6.4",
"@types/ws": "^6.0.0",
Expand Down
10 changes: 9 additions & 1 deletion packages/apollo-server-core/src/ApolloServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
} from './requestPipeline';

import { Headers } from 'apollo-server-env';
import { buildServiceDefinition } from '../../../../apollo-tooling/packages/apollo-tools/lib';

const NoIntrospection = (context: ValidationContext) => ({
Field(node: FieldDefinitionNode) {
Expand Down Expand Up @@ -117,6 +118,7 @@ export class ApolloServerBase {
resolvers,
schema,
schemaDirectives,
modules,
typeDefs,
introspection,
mocks,
Expand Down Expand Up @@ -215,10 +217,16 @@ export class ApolloServerBase {

if (schema) {
this.schema = schema;
} else if (modules) {
const { schema, errors } = buildServiceDefinition(modules);
if (errors && errors.length > 0) {
throw new Error(errors.map(error => error.message).join('\n\n'));
}
this.schema = schema!;
} else {
if (!typeDefs) {
throw Error(
'Apollo Server requires either an existing schema or typeDefs',
'Apollo Server requires either an existing schema, modules or typeDefs',
);
}

Expand Down
4 changes: 4 additions & 0 deletions packages/apollo-server-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import {
import { CacheControlExtensionOptions } from 'apollo-cache-control';
import { ApolloServerPlugin } from 'apollo-server-plugin-base';

import { GraphQLSchemaModule } from '@apollographql/apollo-tools';
export { GraphQLSchemaModule };

export { KeyValueCache } from 'apollo-server-caching';

export type Context<T = any> = T;
Expand Down Expand Up @@ -54,6 +57,7 @@ export interface Config
| 'dataSources'
| 'cache'
> {
modules?: GraphQLSchemaModule[];
typeDefs?: DocumentNode | Array<DocumentNode>;
resolvers?: IResolvers;
schema?: GraphQLSchema;
Expand Down
1 change: 1 addition & 0 deletions packages/apollo-server/src/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export {
GraphQLOptions,
GraphQLExtension,
Config,
GraphQLSchemaModule,
// Errors
ApolloError,
toApolloError,
Expand Down
3 changes: 3 additions & 0 deletions packages/graphql-extensions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
"engines": {
"node": ">=6.0"
},
"dependencies": {
"@apollographql/apollo-tools": "^0.2.0"
},
"devDependencies": {
"apollo-server-core": "file:../apollo-server-core",
"apollo-server-env": "file:../apollo-server-env"
Expand Down

0 comments on commit 8f6481e

Please sign in to comment.