diff --git a/COMMUNITY-TEMPLATES.md b/COMMUNITY-TEMPLATES.md new file mode 100644 index 0000000000..d76b076d3d --- /dev/null +++ b/COMMUNITY-TEMPLATES.md @@ -0,0 +1,59 @@ +# Using Graphback With Your Own Templates + +In case you want to use some other templates than the ones offered, Graphback also supports adding your templates. The process is fairly simple and is as follows: + +## Step 1: Creating an object for your template + +To add your template, you first need to have it in the form of an object which you'll later add to an array. This is best explained by an example: + +Let's say you have a template which you want to name `a-sample-template` and the files for it are located in the repository `https://github.com/sample-user/sample-project`. Then the object for your template would look like this: + +``` +{ + "name": "a-sample-template", + "description": "Fetching current templates in the sample template", + "repos": [ + { + "uri": "https://github.com/sample-user/sample-project", + "branch": "specify-desired-branch", + "path": "exact-path-of-the-directory", + "mountpath": "client" + }, + { + "uri": "https://github.com/sample-user/sample-project", + "branch": "specify-desired-branch", + "path": "exact-path-of-the-directory" + } + ], + } +``` + +Note that you can specify as many repositories as you want (with the desired branch and mount path). Files from the specified repositories would be picked up for your template. + +## Step 2: Adding your template object + +In the packages directory of Graphback you'll find the file `community-templates.ts`. This exports an array called `externalTemplates`. It is in this array that you should add your template object for it to be picked up by the CLI. So the final file would look something like this: + +``` +export default externalTemplates = [ + { + "name": "a-sample-template", + "description": "Fetching current templates in the sample template", + "repos": [ + { + "uri": "https://github.com/sample-user/sample-project", + "branch": "specify-desired-branch", + "path": "exact-path-of-the-directory", + "mountpath": "client" + }, + { + "uri": "https://github.com/sample-user/sample-project", + "branch": "specify-desired-branch", + "path": "exact-path-of-the-directory" + } + ], + } +] +``` + +With this, you're good to go. Yes, it's that simple! If you still have any doubts or are facing problems feel free to reach out to us! diff --git a/packages/community-templates.ts b/packages/community-templates.ts new file mode 100644 index 0000000000..63a6329883 --- /dev/null +++ b/packages/community-templates.ts @@ -0,0 +1 @@ +export default externalTemplates = []; diff --git a/packages/create-graphback/src/init/starterTemplates.ts b/packages/create-graphback/src/init/starterTemplates.ts index 6edd614b10..9ed86c1520 100644 --- a/packages/create-graphback/src/init/starterTemplates.ts +++ b/packages/create-graphback/src/init/starterTemplates.ts @@ -1,16 +1,17 @@ import { createWriteStream, mkdirSync, existsSync } from 'fs'; import chalk from 'chalk'; import ora from 'ora' -import * as github from 'parse-github-url'; -import * as request from 'request'; +import github from 'parse-github-url'; +import request from 'request'; import * as tar from 'tar'; import * as tmp from 'tmp'; +import externalTemplates from '../../../community-templates'; import { Template, TemplateRepository } from './templateMetadata'; /** * available templates */ -export const allTemplates: Template[] = [ +export let allTemplates: Template[] = [ { name: 'apollo-fullstack-react-postgres-ts', description: 'Apollo GraphQL Server connecting to Postgres database and React client using TypeScript', @@ -113,6 +114,12 @@ export const allTemplates: Template[] = [ } ]; +const externalTemplatesArray: Template[] = externalTemplates; +externalTemplatesArray.forEach( + template => (template.name = 'Community: ' + template.name) +); +allTemplates = allTemplates.concat(externalTemplatesArray); + /** * information about repository */ diff --git a/packages/graphback-core/src/runtime/CRUDService.ts b/packages/graphback-core/src/runtime/CRUDService.ts index bf35de8c9d..b37999b6dd 100644 --- a/packages/graphback-core/src/runtime/CRUDService.ts +++ b/packages/graphback-core/src/runtime/CRUDService.ts @@ -1,4 +1,4 @@ -import * as DataLoader from "dataloader"; +import DataLoader from "dataloader"; import { PubSubEngine, withFilter } from 'graphql-subscriptions'; import { GraphQLResolveInfo } from 'graphql'; import { GraphbackCRUDGeneratorConfig, GraphbackOperationType, upperCaseFirstChar, getSubscriptionName } from '..'; diff --git a/tsconfig.json b/tsconfig.json index fe28c6c5c3..1adf8d23fc 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -17,6 +17,8 @@ "noUnusedParameters": false, "noImplicitAny": false, "noImplicitThis": false, + "resolveJsonModule": true, + "esModuleInterop": true, "strictNullChecks": false, "lib": [ "esnext"