Skip to content

Commit

Permalink
Merge pull request #7 from gatewayapps/should-emit-model
Browse files Browse the repository at this point in the history
depracated isModelTopLevel, added shouldEmitModel
  • Loading branch information
danielgary authored Jan 14, 2019
2 parents 68e0c15 + 56b6e07 commit fe11af8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gatewayapps/cradle-apollo-emitter",
"version": "0.3.0",
"version": "0.3.1",
"description": "",
"main": "./dist/index.js",
"scripts": {
Expand Down
11 changes: 10 additions & 1 deletion src/ApolloEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default class ApolloEmitter implements ICradleEmitter {

public async emitSchema(schema: CradleSchema) {
schema.Models.forEach((model) => {
if (!this.options.options.isModelToplevel || this.options.options.isModelToplevel(model)) {
if (this.shouldEmitModel(model)) {
this.writeTypeDefsForModel(model)

if (this.shouldGenerateResolvers(model) && this.options.options.shouldOutputResolverFiles !== false) {
Expand Down Expand Up @@ -204,6 +204,15 @@ ${localFields.join('\n')}
}
}

private shouldEmitModel(model: CradleModel): boolean {
if (this.options.options.shouldEmitModel) {
return this.options.options.shouldEmitModel(model)
} else if (this.options.options.isModelToplevel) {
return this.options.options.isModelToplevel(model)
}
return true
}

private getDirectiveForResolver(model: CradleModel, resolverType: string, resolverName: string): string {
if (!this.options.options.getDirectiveForResolver) {
return ''
Expand Down
4 changes: 4 additions & 0 deletions src/IApolloEmitterOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ export interface IApolloEmitterOptions {
readonly verbose: boolean
readonly outputType: string
readonly useMongoObjectIds: boolean
readonly shouldEmitModel?: (model: CradleModel) => boolean
/**
* @deprecated since version 0.3.1
*/
readonly isModelToplevel?: (model: CradleModel) => boolean
readonly shouldOutputResolverFiles: boolean
readonly shouldGenerateResolvers?: (model: CradleModel) => boolean
Expand Down

0 comments on commit fe11af8

Please sign in to comment.