Git Product home page Git Product logo

gql-folders-script's Introduction

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-folders-script's People

Contributors

maximbuz avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.