create-graphql-app

Cli tool for bootstrapping production grade GraphQL server, using:
- typescript
- apollo-server 2
- graphql-code-generator
- merge-graphql-schemas
- Dependency injection with
injection-js
Installation
Please make sure you have Node.js version 8+, and type
npm install -g create-graphql-app
CLI commands
Init server command
Open shell in the desired folder for bootstrapping the server, and typed:
cga init <project-name>
The command will prompt available server seeds options. Choose the boilerplate project
you want, and start coding!

Generate server resolver files
The server boilerplate code is designed as multi file schema definitions.
Our recommended way for schema design is to create a type file for certain entity.
Eventually, all entities schemas are merged.
To generate a matching resolver file for type file, execute the command:
cga r <type-file> <resolver file>
This will create a matching file, with all Query, Mutation and Subscription
definitions.
Generate services
Our server resolvers should operate as a thin layer, or controller, that links between the schema,
and the server business logic. We use services for our model, to perform logic such as api fetching,
db operations, etc. In order to create a new service, run the command:
cga s <service-path> [--ignoreContext]
This will create a new service file to services directory. Also, it will register the service on the
server injector file, and will add its definition to the context object, thus allowing its usage
by resolvers.
You can exclude context file additions by passing the ignoreContext flag.
Deploy server to production
Inside the project directory, type:
cga d
This will run the server deploy script, and will move the server to production! :rocket:
Extended documentation
Please check out the extended documentation for more information
Variables
Const allCommands
all
Commands: AbstractCommand[] = [new Init(), new Resolver(), new Service(), new Deploy()]
Const allowedFileExtensions
allowedFileExtensions: string[] = ['.ts']
Const contextInterfacePattern
contextInterfacePattern: RegExp = /IAppContext/
Const contextInterfaceStartSeparators
contextInterfaceStartSeparators: string[] = ['{']
Const contextPattern
contextPattern: RegExp = /context/
Const contextStartSeparators
contextStartSeparators: string[] = ['return {', 'return{']
Const fileDefinitionMap
file
DefinitionMap: Map<DefinitionFileType, DefinitionFileProps> = new Map<DefinitionFileType,DefinitionFileProps>([['injector',{filePattern: injectorPattern,declarationName: 'injector',possibleStartSeparators: injectorStartSeparators,definitionSignatureFn: injectorSignatureFn,ignoreContext: false}],['context',{filePattern: contextPattern,declarationName: 'getContext',possibleStartSeparators: contextStartSeparators,definitionSignatureFn: contextSignatureFn,ignoreContext: true}],['context-interface',{filePattern: contextInterfacePattern,declarationName: 'IAppContext',possibleStartSeparators: contextInterfaceStartSeparators,definitionSignatureFn: contextInterfaceSignatureFn,ignoreContext: true}]])
Const find
find: any = find_
Const format
format: format = winston.format
Const functionOperationPrefix
functionOperationPrefix: " => {}," = " => {},"
Const gqlMethodSignature
gqlMethodSignature: "(rootObj: any, args: any, context: IAppContext)" = "(rootObj: any, args: any, context: IAppContext)"
Const gqlMethodSuffix
gqlMethodSuffix: " {}," = " {},"
Const importServicePrefix
importServicePrefix: "@src/services" = "@src/services"
Const injectorPattern
injectorPattern: RegExp = /injector/
Const injectorStartSeparators
injectorStartSeparators: string[] = ['([']
Const keysToGenerate
keysToGenerate: string[] = ['Query', 'Mutation', 'Subscription']
Const logger
logger: Logger = winston.createLogger({level: 'info',format: winston.format.json(),transports: [new winston.transports.Console({format: format.combine(format.colorize(), format.simple())})]})
Const operationFuntionsSuffix
operationFuntionsSuffix: " }," = " },"
Const operationPrefix
operationPrefix: ": {" = ": {"
Const operationSuffix
operationSuffix: " }," = " },"
Const questions
questions: inquirer.QuestionCollection<any> = [{type: 'rawlist',name: 'seedName',message: 'Select seed type',choices: [{name: 'graphql-server-typed: Typescript server deployed on now',value: 'graphql-server-typed'},{name: 'apollo-typed-lambda: Typescript server for aws lambda deployment',value: 'apollo-typed-lambda'}]}]
Const resolverPrefix
resolverPrefix: "import { IAppContext } from '@src/interfaces/IAppContext'const resolveFunctions = {" = "import { IAppContext } from '@src/interfaces/IAppContext'const resolveFunctions = {"
Const resolverSuffix
resolverSuffix: "}export default resolveFunctions" = "}export default resolveFunctions"
Const serviceFileNameSuffix
serviceFileNameSuffix: "Service" = "Service"
Const serviceFilePrefix
serviceFilePrefix: string = "import {Injectable} from 'injection-js'\n\n" + '@Injectable()\n' + 'export class '
Const serviceFileSuffix
serviceFileSuffix: " {}" = " {}"
Const servicePattern
servicePattern: RegExp = /service/
Const spawn
spawn: spawn = spawn_
Const subscriptionSubscribeDefinition
subscriptionSubscribeDefinition: " subscribe: " = " subscribe: "
Const transform
transform: any = transform_