• This repository has been archived on 27/Jul/2020
  • Stars
    star
    347
  • Rank 122,141 (Top 3 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 6 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

Yoga

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 configurations in 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.

Features

  • 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 database to persist your data, and a library to 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 anywhere with the build command to deploy to any plateform
  • Solve the usual N+1 problem with ease thanks to the integrated built-in dataloading helpers
  • Optimized typescript live reload
  • Easily handle authentication and permissions
  • Bootstrap a customised, fully ready-to-use GraphQL server based on a datamodel

Get started

Start from scratch

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

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

That's it, you're ready to start πŸ™Œ

Add to existing project

Install

You can install yoga with 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 πŸ™Œ

Usage

Basics

The following is the tree structure needed for yoga to work

src
β”œβ”€β”€ context.ts (optional)
└── graphql
    β”œβ”€β”€ Query.ts
    └── User.ts

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

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

eg:

// ./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.ts file 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.

eg:

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

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

The CLI

yoga ships itself with a CLI.

Usage: yoga <command> [options]

Commands:
  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

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

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

Configuration

yoga comes 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.

Key Type Default Note
resolversPath string ./src/graphql/ Path to the directory where your resolvers are defined. If provided, path has to exist.
contextPath string ./src/context.ts Path to your context.ts file. If provided, path has to exist.
ejectFilePath string ./src/server.ts Path to an server.ts file 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.
output InputOutputFilesConfig See below. Configuration for the outputted files (schema, typings, etc).
prisma InputPrismaConfig See below. Configuration for the Prisma integration.

InputOutputFilesConfig

Key Type Default Note
typegenPath string ./.yoga/nexus.ts Path to the generated typings.
schemaPath string ./src/schema.graphql Path to the generated schema.

InputPrismaConfig

Key Type Default Note
datamodelInfoPath string null The default exported object generated by nexus-prisma-generate. Import it from the output directory generated by nexus-prisma-generate
client PrismaClientInput ./.yoga/prisma-client/index.ts Instance of the prisma-client, either passed statically or returned from the context defined in your GraphQL server.

Contributing

Install dependencies

npm install
npm run bootstrap

Move onto the ./example folder at the root of the repository (the example is used to test yoga locally)

cd ./example

And run yoga

npm run yoga

The server should start. You're ready to help πŸ™

More Repositories

1

graphqlgen

βš™οΈ Generate type-safe resolvers based upon your GraphQL Schema
TypeScript
818
star
2

graphql-prisma-typescript

🏑 GraphQL server reference implementation (Airbnb clone) in Typescript using Prisma & graphql-yoga
TypeScript
749
star
3

graphql-framework-experiment

Code-First Type-Safe GraphQL Framework
TypeScript
673
star
4

get-graphql-schema

Fetch and print the GraphQL schema from a GraphQL HTTP endpoint. (Can be used for Relay Modern.)
TypeScript
665
star
5

prisma-binding

GraphQL Binding for Prisma 1 (using GraphQL schema delegation)
TypeScript
476
star
6

python-graphql-client

Simple GraphQL client for Python 2.7+
Python
156
star
7

dripip

Opinionated CLI for continuous delivery of npm packages
TypeScript
100
star
8

konn

TypeScript
89
star
9

graphql-import-loader

Webpack loader for `graphql-import`
TypeScript
83
star
10

http-link-dataloader

πŸ“šπŸ“‘ HTTP Apollo Link with batching & caching provided by dataloader.
TypeScript
77
star
11

bema

🐎 Delightful benchmarking for Node.js
TypeScript
73
star
12

graphql-framework-experiment-examples

Runnable examples to help you learn how to use Nexus.
TypeScript
64
star
13

nextjs-graphql-api-examples

Next.js example GraphQL API implementations
TypeScript
38
star
14

next-prisma-plugin

TypeScript
19
star
15

graphqlday.org

JavaScript
12
star
16

oss.prisma.io

Documentation content for oss.prisma.io (GraphQL Playground, GraphQL Yoga, GraphQL Config...)
10
star
17

vscode-next

TypeScript
6
star
18

graphql-config-extension-prisma

TypeScript
6
star
19

mockapie

TypeScript
1
star
20

renovate-config

Standard Renovate configurations for Labs team projects.
1
star
21

team

πŸ‘©β€πŸ”¬πŸ‘¨β€πŸ”¬Past sprint demo recordings & more
1
star
22

prettier-config

Standard Prettier configuration for Labs team projects.
1
star