nexus-cli-tmp

2020-01-15

nexus-cli-tmp

null

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

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 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="https://github.githubassets.com/images/icons/emoji/unicode/1f64c.png">🙌</g-emoji>

Add to existing project

Install

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="https://github.githubassets.com/images/icons/emoji/unicode/1f64c.png">🙌</g-emoji>

Usage

Basics

The following is the tree structure needed for yogato work

src
├── 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

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

eg:

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

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

The CLI

yogaships 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 devwill run a GraphQL server in watch mode, updating your server whenever a file change.

Configuration

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.

KeyTypeDefaultNote
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.

InputOutputFilesConfig

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

InputPrismaConfig

KeyTypeDefaultNote
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.

Contributing

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="https://github.githubassets.com/images/icons/emoji/unicode/1f64f.png">🙏</g-emoji>

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


上一篇:node-dev-delay
下一篇:appup
相关教程
关注微信

扫码加入 JavaScript 社区

相关文章

首次访问,需要验证
微信扫码,关注即可
(仅需验证一次)

欢迎加入 JavaScript 社区

号内回复关键字:

回到顶部