gql-folder-cli

1.0.7 • Public • Published

Generate GraphQL Resolver Templates

Easily create a clean folder structure based on a GraphQL schema string

Just go into the folder that contains a file containing your GraphQL schema and run npx gql-folder-cli [filename.js] [variableName]. By default, filename.js will be schema.js and variableName will be typeDefs.

The file containing your GraphQL schema should look as follows:

 export const typeDefs = `
  type User {
    id: Int!
    username: String!
  }

  type Something {
    id: Int!
    user: User
    userId: Int!
  }

  type Mutation {
    createNewUser(email: String!): User
    createSomething: Something
  }
`;

The generated folder structure will rougly look as follows:

 resolvers/
  ├─ mutations/
  │  ├─ createSomething.js
  │  ├─ index.js
  ├─ something/
  │  ├─ index.js
  │  ├─ user.js
  ├─ user/
  │  ├─ index.js
  ├─ index.js

Every file initializes the resolver functions and exports them in the index.js. The main index.js will look as follows:

  import { User } from "./user";
  import { Something } from "./something";
  import { Mutation } from "./mutations";

  export const resolvers = {
    User,
    Something,
    Mutation,
  };

/gql-folder-cli/

    Package Sidebar

    Install

    npm i gql-folder-cli

    Weekly Downloads

    0

    Version

    1.0.7

    License

    MIT

    Unpacked Size

    12.8 kB

    Total Files

    9

    Last publish

    Collaborators

    • maximbuz