Skip to content

amirrezaDev1378/swr-codegen

Repository files navigation

SWR GraphQl Code Generator

A powerful code generator that Generate SWR hooks from GraphQL queries & mutations A Powerfull Code Generator For SWR

npm version npm downloads

Table Of Contents

How to Use

Installing The Package:

⚠️ This package does not support global installation anymore,

you can install it in your project using:

npm i swr-codegen -d

Adding config file inside your project:

  1. create a javascript file anywhere in your project e.g. codegen-config.js

  2. add your configs:

you can use the init command : swr-codegen --init to create a config file with default configs, or you can create a config file manually:

const fs = require("fs");

module.exports = {
	gqlGlob: "./**/*.gql",
	targetPath: "/generated/swr/",
	schema: async () => {
		return fs.readFileSync("graphql/schema.graphql").toString();
	},
};
  1. (optional) Add a codegen command to your package.json:
"scripts": {
  ...
  "codegen": "swr-codegen --configPath=./codegen-config.js"
}

That's it! run npm run codegen (or swr-codegen configPath=./codegen-config.js)

High-Priority Tasks:

  • add a better error-handling system.

  • add an option to customize the EJS templates.

  • adding path normalizer

Repository Owners:

Rasoul And Amirreza