Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

Commit

Permalink
optimize(gg): do not run scaffolder when disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkuhrt committed Feb 5, 2019
1 parent 2189af0 commit ddf2b69
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions packages/graphqlgen/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { validateConfig } from './validation'
import { handleGlobPattern } from './glob'
import * as Project from './project-output'

export type GenerateCodeArgs = {
export type CodeGenArgs = {
schema: GraphQLTypes
config: GraphQLGenDefinition
modelMap: ModelMap
Expand Down Expand Up @@ -50,7 +50,7 @@ function getResolversGenerator(language: Language): IGenerator {

function generateTypes(
generateArgs: GenerateArgs,
generateCodeArgs: GenerateCodeArgs,
generateCodeArgs: CodeGenArgs,
): string {
const generatorFn: IGenerator = getTypesGenerator(generateCodeArgs.language!)
const generatedTypes = generatorFn.generate(generateArgs)
Expand All @@ -65,7 +65,7 @@ function generateTypes(

function generateResolvers(
generateArgs: GenerateArgs,
generateCodeArgs: GenerateCodeArgs,
generateCodeArgs: CodeGenArgs,
): CodeFileLike[] {
const generatorFn: IGenerator = getResolversGenerator(
generateCodeArgs.language!,
Expand All @@ -85,20 +85,29 @@ function generateResolvers(
})
}

export function generateCode(
generateCodeArgs: GenerateCodeArgs,
): { generatedTypes: string; generatedResolvers: CodeFileLike[] } {
const { schema } = generateCodeArgs
type CodeGenResult = {
generatedTypes: string
generatedResolvers?: CodeFileLike[]
}

export function generateCode(codeGenArgs: CodeGenArgs): CodeGenResult {
const { schema } = codeGenArgs

const generateArgs: GenerateArgs = {
...schema,
context: parseContext(
generateCodeArgs.config.context,
generateCodeArgs.config.output,
codeGenArgs.config.context,
codeGenArgs.config.output,
),
modelMap: generateCodeArgs.modelMap!,
modelMap: codeGenArgs.modelMap!,
}
const generatedTypes = generateTypes(generateArgs, generateCodeArgs)
const generatedResolvers = generateResolvers(generateArgs, generateCodeArgs)

const generatedTypes = generateTypes(generateArgs, codeGenArgs)

const generatedResolvers = codeGenArgs.config['resolver-scaffolding']
? generateResolvers(generateArgs, codeGenArgs)
: undefined

// const generatedModels = generateModels(generateArgs, {schema, prettify, prettifyOptions, language})

return { generatedTypes, generatedResolvers }
Expand Down Expand Up @@ -160,7 +169,10 @@ async function run() {
})

Project.writeTypes(generatedTypes, config)
Project.writeResolversScaffolding(generatedResolvers, config)

if (config['resolver-scaffolding']) {
Project.writeResolversScaffolding(generatedResolvers!, config)
}
}

// Only call run when running from CLI, not when included for tests
Expand Down

0 comments on commit ddf2b69

Please sign in to comment.