This repository has been archived by the owner on Jul 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
446 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--- | ||
name: Yoga | ||
route: / | ||
--- | ||
|
||
# Yoga | ||
|
||
A lightweight 'Ruby on Rails'-like framework for GraphQL | ||
|
||
## What is Yoga? | ||
|
||
Yoga is a GraphQL framework built with **conventions over configuration** 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. | ||
|
||
It uses [**GraphQL Nexus**](<[`nexus`](https://graphql-nexus.com/)>) under the hood to help you create a scalable, maintainable, and type-safe GraphQL server. | ||
|
||
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 **[GraphQL Nexus](https://graphql-nexus.com/)** 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
--- | ||
name: Getting started | ||
route: /getting-started | ||
--- | ||
|
||
# Getting started | ||
|
||
## From scratch | ||
|
||
- Install `yoga` as a dependency | ||
|
||
```bash | ||
yarn add yoga | ||
``` | ||
|
||
- Init a `yoga` project | ||
|
||
```bash | ||
yarn yoga init | ||
``` | ||
|
||
- The following folder structure will be created for you | ||
|
||
```bash | ||
src | ||
├── context.ts (optional) | ||
└── graphql | ||
└── Query.ts | ||
``` | ||
|
||
- Run `yarn yoga dev`. You're ready to start 🚀 | ||
|
||
## Bootstrap a ready-to-use project | ||
|
||
- Start the bootstrapper | ||
|
||
```bash | ||
yarn create yoga | ||
``` | ||
|
||
- Choose the template you want to start with: | ||
|
||
```bash | ||
? Choose a GraphQL server template? (Use arrow keys) | ||
❯ minimal-yoga (Basic starter template ) | ||
db-yoga (Template with Prisma database support) | ||
``` | ||
|
||
- Follow the CLI intructions | ||
- You're ready to start 🚀 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
--- | ||
name: How to use | ||
route: /how-to-use | ||
--- | ||
|
||
# How to use | ||
|
||
As Yoga is built with conventions in mind, there are a couple of requirements needed with your folder structure for it to work. | ||
|
||
## Conventions | ||
|
||
Here's the exhaustive list of files that are supported by Yoga: | ||
|
||
```bash | ||
. | ||
├── src | ||
│ ├── graphql | ||
│ │ └── Query.ts | ||
│ ├── context.ts (optional) | ||
│ ├── express.ts (optional) | ||
│ └── server.ts (optional) | ||
└── yoga.config.ts (optional) | ||
``` | ||
|
||
- `src/graphql/*` (required): The folder in which you define all your resolvers | ||
- `src/context.ts` (optional): A file to define the context of your GraphQL server. | ||
- `src/express.ts` (optional): A file to access the underlying express instance (and use middlewares, expose webhooks etc..) | ||
- `src/yoga.config.ts` (optional): [See configuration here](../configuration) | ||
- `src/server.ts` (optional): Where you define your own GraphQL server if needed. (**Adding this file ejects you from the conventions**) | ||
|
||
### Examples | ||
|
||
**`graphql/*` (required)** | ||
|
||
The folder in which you define all your resolvers | ||
|
||
```ts | ||
// src/graphql/Query.ts | ||
import { objectType } from "yoga"; | ||
|
||
export const Query = objectType({ | ||
name: "Query", | ||
definition(t) { | ||
t.string("hello", o => "world"); | ||
} | ||
}); | ||
``` | ||
|
||
**`context.ts` (optional)** | ||
|
||
A file to define the context of your GraphQL server. It must default export a function. | ||
|
||
```ts | ||
// src/context.ts | ||
import { context } from "yoga"; | ||
import { orm } from "./my-orm"; | ||
|
||
// `context` is an optional helper to provide type-safety and autocompletion | ||
export default context(({ req }) => ({ req, orm })); | ||
``` | ||
|
||
**`express.ts` (optional)** | ||
|
||
A file to access the underlying express instance (and use middlewares, expose webhooks etc..) | ||
|
||
```ts | ||
// src/express.ts | ||
import { express } from "yoga"; | ||
import { middleware } from "my-express-middleware"; | ||
|
||
// `express` is an optional helper to provide type-safety and autocompletion | ||
export default express(app => { | ||
// Define any express related logic using the injected `app` express instance | ||
app.use(middleware); | ||
// app.get('/login', ...) | ||
// app.get('/logout', ...) | ||
}); | ||
``` | ||
|
||
## Eject from conventions | ||
|
||
Although Yoga is built on top of many conventions, you can very simply opt-out from it if needed at some point in your development | ||
|
||
> Note: **This step is not irreversible. Don't be afraid of trying it.** | ||
### [See `yoga eject` command for more info](../cli#yoga-eject) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
--- | ||
name: Configuration | ||
route: /configuration | ||
--- | ||
|
||
# Configuration | ||
|
||
Most of the opinionated conventions on which Yoga is built can be overriden at any moment. | ||
|
||
## yoga.config.ts (optional) | ||
|
||
A `yoga.config.ts` file can be created at the root of your project. It must default export an object containing one of the following properties | ||
|
||
| 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` | `./.yoga/nexus-prisma` | 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. | | ||
|
||
### Example | ||
|
||
A `yoga.config.ts` file that would use all the _default_ options would look like this | ||
|
||
```ts | ||
// yoga.config.ts | ||
import { config } from "yoga"; | ||
|
||
// `config` is just an optional helper to provide type-safety and auto-completion | ||
export default config({ | ||
resolversPath: "./src/graphql/", | ||
contextPath: "./src/context.ts", | ||
ejectFilePath: "./src/server.ts", | ||
output: { | ||
typegenPath: "./.yoga/nexus.ts", | ||
schemaPath: "./src/schema.graphql" | ||
}, | ||
// Only if you're using yoga with Prisma | ||
prisma: { | ||
datamodelInfoPath: "./.yoga/nexus-prisma", | ||
client: ctx => ctx.prisma | ||
} | ||
}); | ||
``` |
Oops, something went wrong.