A lightweight 'Ruby on Rails'-like framework for GraphQL

Note: This project is still very WIP

What is Yoga?

Yoga is a GraphQL framework built with conventions over configurationsin mind. Its goal is to help you get setup as quick as possible and to boost your daily productivity while allowing you to eject at any moment so that you're not locked when more flexibility is needed.

We take care of the boilerplate, you focus on the business logic.


  • Type-safe
  • Zero-config
  • Scalable
  • Conventions over configuration
  • Resolver-first GraphQL
  • Batteries included (DB, Auth, rate limiting, ...)
  • Deploy anywhere

What sort of abstraction does Yoga provide ?

Yoga is shipped with several technologies embedded such as a GraphQL server, a databaseto persist your data, and a libraryto easily maintain and scale your server.

Thanks to _opinionated conventions_, Yoga offers built-in integration tools to better your daily workflows when crafting your GraphQL server:

  • Speed-up your productivity with the interactive scaffolding commands.
  • Deploy anywherewith the build command to deploy to any plateform
  • Solve the usual N+1 problem with easethanks to the integrated built-in dataloading helpers
  • Optimized typescript live reload
  • Easily handle authentication and permissions
  • Bootstrapa customised, fully ready-to-use GraphQL server based on a datamodel

Get started

Start from scratch

Bootstrap a GraphQL server with a ready-made yogasetup then start the server:

npm init yoga my-app
cd my-app
npm start

That's it, you're ready to start <g-emoji class="g-emoji" alias="raised_hands" fallback-src="">🙌</g-emoji>

Add to existing project


You can install yogawith either of the following commands:

npm install --save yoga

and add a script to your package.json like this:

  "scripts": {
    "dev": "yoga dev"

You can now run

npm run dev

That's it, you're ready to start <g-emoji class="g-emoji" alias="raised_hands" fallback-src="">🙌</g-emoji>



The following is the tree structure needed for yogato work

├── context.ts (optional)
└── graphql
    ├── Query.ts
    └── User.ts

The ./src/graphqlfolder is the entry point of your GraphQL server.

Every .tsfile within that directory that exposes some GraphQL types will be processed, and exposed through a GraphQL server


// ./src/graphql/Query.ts
import { objectType } from "yoga";

export const Query = objectType("Query", t => {
  t.string("hello", {
    resolve: () => " world!"

Optionally, you can also provide a ./src/context.tsfile to inject anything to the context of your resolvers.

That file needs to default export a function returning an object containing what you want to put within your resolvers' context.


// ./src/context.ts
import something from "somewhere";

export default () => ({ something });


yogaships itself with a CLI.

Usage: yoga <command> [options]

  yoga new       Create new yoga project from template
  yoga start     Start the server
  yoga dev       Start the server in dev mode
  yoga scaffold  Scaffold a new GraphQL type
  yoga build     Build a yoga server

  --version   Show version number                                      [boolean]
  -h, --help  Show help                                                [boolean]

yoga devwill run a GraphQL server in watch mode, updating your server whenever a file change.


yogacomes with a default set of options (convention over configuration), but if you need to change them you can do so in the yoga.config.ts. Below is a table of all options, their types, and short descriptions.

resolversPathstring./src/graphql/Path to the directory where your resolvers are defined. If provided, path has to exist.
contextPathstring./src/context.tsPath to your context.tsfile. If provided, path has to exist.
ejectFilePathstring./src/server.tsPath to an server.tsfile to eject from default configuration yoga.config.ts. When provided, all other configuration properties are ignored and should be configured programatically. If provided, path has to exist.
outputInputOutputFilesConfigSee below.Configuration for the outputted files (schema, typings, etc).
prismaInputPrismaConfigSee below.Configuration for the Prisma integration.


typegenPathstring./.yoga/nexus.tsPath to the generated typings.
schemaPathstring./src/schema.graphqlPath to the generated schema.


datamodelInfoPathstringnullThe default exported object generated by nexus-prisma-generate. Import it from the output directory generated by nexus-prisma-generate
clientPrismaClientInput./.yoga/prisma-client/index.tsInstance of the prisma-client, either passed statically or returned from the context defined in your GraphQL server.


Install dependencies

npm install
npm run bootstrap

Move onto the ./examplefolder at the root of the repository (the example is used to test yogalocally)

cd ./example

And run yoga

npm run yoga

The server should start. You're ready to help <g-emoji class="g-emoji" alias="pray" fallback-src="">🙏</g-emoji>

以上是 nexus-cli-tmp 的使用教程帮助文档。


扫码加入 JavaScript 社区



欢迎加入 JavaScript 社区