Skip to content

Commit

Permalink
feat(generate-files): only auto-generate in development mode (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
goldcaddy77 authored Mar 15, 2019
1 parent 7355b51 commit 0e2f65c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,24 @@ input UserWhereUniqueInput {

Notice how we've only added a single field on the model and you get pagination, filtering and tracking of who created, updated and deleted records automatically.

## Server API

### App Options (appOptions)

| attribute | description | default |
| --- | --- | --- |
| container | TypeDI container. Warthog uses dependency injection under the hood. | empty container |
| authChecker | An instance of an [AuthChecker](https://typegraphql.ml/docs/authorization.html) to secure your resolvers. | |
| autoGenerateFiles | Should the server auto-generate your schema, typings, etc... | `true` when NODE_ENV=development. `false` otherwise |
| context | Context getter of form `(request: Request) => object` | empty |
| generatedFolder | Folder where generated content is created | `process.cwd()` + 'generated' |
| logger | Logger | [debug](https://github.com/visionmedia/debug) |
| middlewares | Express middlewares to add to your server | none |
| mockDBConnection | Opens a sqlite connection instead of Postgres. Helpful if you just need to generate the schema | `false` |
| openPlayground | Should server open GraphQL Playground after starting? | `false` if running tests, `true` if in development mode |
| port | App Server Port | 4000 |
| resolversPath | Glob path to find your resolvers | `process.cwd()` + '/**/*.resolver.ts' |

## Config

All config is driven by environment variables. Most options can also be set by setting the value when creating your `Server` instance.
Expand Down
11 changes: 10 additions & 1 deletion src/core/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface ServerOptions<T> {
container?: Container;

authChecker?: AuthChecker<T>;
autoGenerateFiles?: boolean;
context?: (request: Request) => object;
host?: string;
generatedFolder?: string;
Expand All @@ -49,6 +50,7 @@ export class Server<C extends BaseContext> {
appHost: string;
appPort: number;
authChecker: AuthChecker<C>;
autoGenerateFiles: boolean;
connection!: Connection;
container: Container;
generatedFolder: string;
Expand Down Expand Up @@ -91,6 +93,11 @@ export class Server<C extends BaseContext> {
this.logger = this.getLogger();
Container.set('warthog.logger', this.logger); // Save for later so we can pull globally

this.autoGenerateFiles =
typeof this.appOptions.autoGenerateFiles !== 'undefined'
? this.appOptions.autoGenerateFiles
: process.env.NODE_ENV === 'development';

this.resolversPath = this.appOptions.resolversPath || [process.cwd() + '/**/*.resolver.ts'];
}

Expand Down Expand Up @@ -155,7 +162,9 @@ export class Server<C extends BaseContext> {
async start() {
debug('start:start');
await this.establishDBConnection();
await this.generateFiles();
if (this.autoGenerateFiles) {
await this.generateFiles();
}
await this.buildGraphQLSchema();

const contextGetter =
Expand Down

0 comments on commit 0e2f65c

Please sign in to comment.