pal generate

Alias: pal g

Use this command to scaffold all the boring code into your project.

Can generate queries, mutations, admin pages, apollo client queries and mutations documents

> pal generate [MODELS] [TYPE]

ARGUMENTSRequiredDescription
MODELSnoschema model name to generate files for. You can pass one or more models like User,Post
TYPEno(crud|queries|mutations|admin|graphql) Type of files to generate you can send one or more like queries,mutations

OPTIONS

charflagdescription
-c--config=config[default: pal] You can pass custom config file name
-m--multiAdd this flag to work with config file as multi schema
-s--schemawhen you working with multi schema and need to select just one add the schema prop name
-a--autoCompleteAdd this flag with ${ZSH_CUSTOM:=~/.oh-my-zsh/custom}/plugins/ path to generate CLI auto complete for oh-my-zsh
-h--helpshow CLI help

Here's the matrix of which files are generated by which command:

TypeMutationsQueriesClient GraphQLAdmin pages
crudyesyes
queriesyes
mutationsyes
adminyes
graphqlyes

EXAMPLES

  # To generate everything for all models in your schema
  > pal g

  Note: you need to change User,Post with your schema models

  # To generate everything for model or more
  > pal g User,Post

  # To generate queries for one model or more
  > pal g User,Post queries

  # To generate mutations for one model or more
  > pal g User,Post mutations

  # To generate admin for one model or more
  > pal g User,Post admin

  # To generate graphql for one model or more
  > pal g User,Post graphql

  # To generate queries and mutations for one model or more
  > pal g User,Post crud

output

Generated code depending on the type of generator

Config file

To customize the generator with your needs and project dirs you need to create configurations.

Add new file to your project root path with name pal.js or pal.json

Config examples

Singel schema

module.exports = {
  backend: {
    generator: 'nexus',
    onDelete: true,
    output: 'src/server/graphql',
  },
  frontend: {
    admin: true,
  },
};

Multi schemas

module.exports = {
  // schema name to add for --schema flag is "schema1"
  schema1: {
  // path to schema
    schema: './prisma1/schema.prisma',
    backend: {
  // prisma client name inside the graphql resolver context to generate for CRUD
      prismaName: 'prisma1',
      generator: 'nexus',
      onDelete: true,
      output: 'src/server/graphql',
    },
    frontend: {
      admin: true,
    },
  },
  schema2: {
    schema: './prisma2/schema.prisma',
    backend: {
      prismaName: 'prisma2',
      generator: 'nexus',
      onDelete: true,
      output: 'src/server/graphql',
    },
    frontend: {
      admin: true,
    },
  },
};

You can change file name and pass it to your command

> pal g -c=config

type definitions for config file

interface Config {
  // prisma schema path
  schema?: string;  // add backend generator
  backend?: {    // generator type it's require
    generator: GeneratorsType;    // if you have our admin PrismaTable and need to customize his settings schema path default prisma/
    adminSettingsPath?: string;
  } & Options;  // add frontend generator
  frontend?: {    // generate admin settings and pages
    admin?: AdminPagesOptions | boolean;    // generate graphql client documents
    graphql?: Options | boolean;
  };}
type GeneratorsType = 'nexus' | 'sdl' | 'graphql-modules' | 'nexus-plugin-prisma';