Skip to content

MaximBuz/gql-folders-script

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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,
  };

About

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

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published