├── .circleci └── config.yml ├── .github ├── ISSUE_TEMPLATE.md ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── PULL_REQUEST_TEMPLATE.md ├── .gitignore ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── examples ├── minimal-ejected │ ├── .gitignore │ ├── .yoga │ │ └── nexus.ts │ ├── package.json │ ├── src │ │ ├── context.ts │ │ ├── graphql │ │ │ ├── Query.ts │ │ │ ├── User.ts │ │ │ └── index.ts │ │ ├── schema.graphql │ │ └── server.ts │ └── tsconfig.json ├── minimal │ ├── .gitignore │ ├── .yoga │ │ └── nexus.ts │ ├── README.md │ ├── package.json │ ├── src │ │ ├── context.ts │ │ ├── data.ts │ │ ├── graphql │ │ │ ├── Query.ts │ │ │ └── User.ts │ │ ├── schema.graphql │ │ └── server.ts │ └── tsconfig.json └── with-db │ ├── .gitignore │ ├── README.md │ ├── package.json │ ├── prisma │ ├── datamodel.prisma │ ├── prisma.yml │ └── seed.ts │ ├── src │ ├── context.ts │ ├── graphql │ │ ├── Mutation.ts │ │ ├── Post.ts │ │ ├── Query.ts │ │ └── User.ts │ └── schema.graphql │ └── tsconfig.json ├── lerna.json ├── package.json ├── packages ├── create-yoga │ ├── README.md │ ├── package.json │ ├── src │ │ ├── bin.ts │ │ ├── bootstrap.ts │ │ ├── index.ts │ │ ├── loader.ts │ │ ├── scaffold.ts │ │ └── templates.ts │ ├── tsconfig.json │ └── tslint.json └── yoga │ ├── package.json │ ├── src │ ├── cli │ │ ├── commands │ │ │ ├── build │ │ │ │ ├── index.ts │ │ │ │ └── renderers.ts │ │ │ ├── eject │ │ │ │ └── index.ts │ │ │ ├── scaffold │ │ │ │ └── index.ts │ │ │ ├── start │ │ │ │ └── index.ts │ │ │ └── watch │ │ │ │ └── index.ts │ │ ├── index.ts │ │ └── spawnAsync.ts │ ├── config.ts │ ├── decache.ts │ ├── helpers.ts │ ├── index.ts │ ├── logger.ts │ ├── nexusDefaults.ts │ ├── server.ts │ ├── types.ts │ └── yogaDefaults.ts │ ├── tsconfig.json │ └── tslint.json └── renovate.json /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | jobs: 3 | build: 4 | working_directory: ~/yoga2 5 | docker: 6 | # Node 10 LTS 7 | - image: circleci/node:10 8 | steps: 9 | - checkout 10 | - run: 11 | name: update-npm 12 | command: sudo npm install -g npm@latest 13 | - run: 14 | name: install-package-dependencies 15 | command: yarn run bootstrap:ci 16 | - run: 17 | name: link yoga 18 | workdir: ./packages/yoga 19 | command: sudo npm link --unsafe-perm=true 20 | - run: 21 | name: run-build 22 | command: sudo yarn run build:ci 23 | - run: 24 | name: run lint 25 | command: yarn run lint 26 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | **Please post usage questions or broader discussions in the [Slack channel](https://prisma.slack.com/messages/CF62PPR29)**. 2 | 3 | --- 4 | 5 | For **feature requests**, please fill out the [feature request template](https://github.com/prisma/yoga2/issues/new?template=feature_request.md) 6 | 7 | --- 8 | 9 | For **bug reports**, please fill out the [bug report issue template](https://github.com/prisma/yoga2/issues/new?template=bug_report.md) 10 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | 5 | --- 6 | 7 | **Describe the bug** 8 | A clear and concise description of what the bug is. 9 | 10 | **To Reproduce** 11 | Steps to reproduce the behavior: 12 | 1. Go to '...' 13 | 2. Click on '....' 14 | 3. Scroll down to '....' 15 | 4. See error 16 | 17 | **Expected behavior** 18 | A clear and concise description of what you expected to happen. 19 | 20 | **Screenshots** 21 | If applicable, add screenshots to help explain your problem. 22 | 23 | **Versions (please complete the following information):** 24 | - OS: [e.g. `Windows 10`, `OS X High Sierra`, `Ubuntu 16.04`] 25 | - `yoga` CLI: [e.g. `yoga/0.0.1 (darwin-x64) node-v10.4.0`] 26 | 27 | **Additional context** 28 | Add any other context about the problem here. 29 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | 5 | --- 6 | 7 | **Is your feature request related to a problem? Please describe.** 8 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 9 | 10 | **Describe the solution you'd like** 11 | A clear and concise description of what you want to happen. 12 | 13 | **Describe alternatives you've considered** 14 | A clear and concise description of any alternative solutions or features you've considered. 15 | 16 | **Additional context** 17 | Add any other context or screenshots about the feature request here. 18 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 9 | 10 | ## Description 11 | 12 | 13 | ## Progress 14 | 15 | - [ ] Implementation 16 | - [ ] Documentation 17 | - [ ] Tests -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | .yalc 4 | yalc.lock 5 | yarn.lock 6 | package-lock.json 7 | .idea 8 | .docz -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at hello@prisma.io. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contribution Guidelines 2 | 3 | Please read this guide if you're interested in contributing to Prisma Yoga2. 4 | 5 | **We welcome any form of contribution, especially from new members of our community** 💚 6 | 7 | ## Discussions 8 | 9 | **Our community is a safe and friendly environment, where we support and treat each other with respect**. 10 | 11 | We invite you to actively participate in discussions on Github and 12 | [Slack collab-yoga2 channel](https://prisma.slack.com/messages/CF62PPR29)**. 13 | 14 | You'll see many discussions about usage or design questions, but any topic is welcome. 15 | They are a great foundation to find potential issues, feature requests or documentation improvements. 16 | 17 | ## Issues 18 | 19 | To report a bug, you can use [this template](https://github.com/prisma/yoga2/issues/new). 20 | 21 | New bug reports require to be triaged. Oftentimes this includes creating a minimal reproduction, or verifying that the problem still occurs on the latest stable version or the unstable channel (see below). 22 | 23 | When you're starting to look into fixing a bug, create a WIP PR that you mention in the original issue. This way, we ensure that everyone interested can share their thoughts, and duplicate work is prevented. 24 | 25 | Adding tests is a great way to help preventing future bugs. 26 | 27 | ## Submitting Changes 28 | 29 | After getting some feedback, push to your fork and submit a pull request. We 30 | may suggest some changes or improvements or alternatives, but for small changes 31 | your pull request should be accepted quickly. 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Graphcool, Inc 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Yoga 2 | 3 | A lightweight 'Ruby on Rails'-like framework for GraphQL 4 | 5 | > Note: This project is still very WIP 6 | 7 | ## What is Yoga? 8 | 9 | Yoga is a GraphQL framework built with _conventions over configurations_ in mind. 10 | 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. 11 | 12 | We take care of the boilerplate, you focus on the business logic. 13 | 14 | ## Features 15 | 16 | - Type-safe 17 | - Zero-config 18 | - Scalable 19 | - Conventions over configuration 20 | - Resolver-first GraphQL 21 | - Batteries included (DB, Auth, rate limiting, ...) 22 | - Deploy anywhere 23 | 24 | ### What sort of abstraction does Yoga provide ? 25 | 26 | Yoga is shipped with several technologies embedded such as a **GraphQL server**, a **database** to persist your data, and a **[library](https://graphql-nexus.com/)** to easily maintain and scale your server. 27 | 28 | Thanks to _opinionated conventions_, Yoga offers built-in integration tools to better your daily workflows when crafting your GraphQL server: 29 | 30 | - Speed-up your productivity with the **interactive scaffolding commands**. 31 | - **Deploy anywhere** with the build command to deploy to any plateform 32 | - Solve the usual **N+1 problem with ease** thanks to the integrated built-in dataloading helpers 33 | - Optimized typescript **live reload** 34 | - Easily **handle authentication and permissions** 35 | - **Bootstrap** a customised, fully ready-to-use GraphQL server based on a datamodel 36 | 37 | ## Get started 38 | 39 | ### Start from scratch 40 | 41 | Bootstrap a GraphQL server with a ready-made `yoga` setup then 42 | start the server: 43 | 44 | ```bash 45 | npm init yoga my-app 46 | cd my-app 47 | npm start 48 | ``` 49 | 50 | That's it, you're ready to start 🙌 51 | 52 | ### Add to existing project 53 | 54 | #### Install 55 | 56 | You can install `yoga` with either of the following commands: 57 | 58 | ```bash 59 | npm install --save yoga 60 | ``` 61 | 62 | and add a script to your package.json like this: 63 | 64 | ```json 65 | { 66 | "scripts": { 67 | "dev": "yoga dev" 68 | } 69 | } 70 | ``` 71 | 72 | You can now run 73 | 74 | ```bash 75 | npm run dev 76 | ``` 77 | 78 | That's it, you're ready to start 🙌 79 | 80 | ## Usage 81 | 82 | ### Basics 83 | 84 | The following is the tree structure needed for `yoga` to work 85 | 86 | ``` 87 | src 88 | ├── context.ts (optional) 89 | └── graphql 90 | ├── Query.ts 91 | └── User.ts 92 | ``` 93 | 94 | The `./src/graphql` folder is the entry point of your GraphQL server. 95 | 96 | Every `.ts` file within that directory that exposes some GraphQL types will be processed, and exposed through a GraphQL server 97 | 98 | _eg:_ 99 | 100 | ```ts 101 | // ./src/graphql/Query.ts 102 | import { objectType } from "yoga"; 103 | 104 | export const Query = objectType("Query", t => { 105 | t.string("hello", { 106 | resolve: () => " world!" 107 | }); 108 | }); 109 | ``` 110 | 111 | Optionally, you can also provide a `./src/context.ts` file to inject anything to the context of your resolvers. 112 | 113 | That file needs to default export a function returning an object containing what you want to put within your resolvers' context. 114 | 115 | _eg:_ 116 | 117 | ```ts 118 | // ./src/context.ts 119 | import something from "somewhere"; 120 | 121 | export default () => ({ something }); 122 | ``` 123 | 124 | ### The CLI 125 | 126 | `yoga` ships itself with a CLI. 127 | 128 | ``` 129 | Usage: yoga [options] 130 | 131 | Commands: 132 | yoga new Create new yoga project from template 133 | yoga start Start the server 134 | yoga dev Start the server in dev mode 135 | yoga scaffold Scaffold a new GraphQL type 136 | yoga build Build a yoga server 137 | 138 | Options: 139 | --version Show version number [boolean] 140 | -h, --help Show help [boolean] 141 | ``` 142 | 143 | `yoga dev` will run a GraphQL server in watch mode, updating your server whenever a file change. 144 | 145 | ### Configuration 146 | 147 | `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. 148 | 149 | | Key | Type | Default | Note | 150 | | --------------------------- | --------------------------------------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | 151 | | `resolversPath` | `string` | `./src/graphql/` | Path to the directory where your resolvers are defined. **If provided, path has to exist.** | 152 | | `contextPath` | `string` | `./src/context.ts` | Path to your `context.ts` file. **If provided, path has to exist.** | 153 | | `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.** | 154 | | `output` | [`InputOutputFilesConfig`](/packages/yoga/src/types.ts#L25) | See below. | Configuration for the outputted files (schema, typings, etc). | 155 | | `prisma` | [`InputPrismaConfig`](/packages/yoga/src/types.ts#L9) | See below. | Configuration for the Prisma integration. | 156 | 157 | #### InputOutputFilesConfig 158 | 159 | | Key | Type | Default | Note | 160 | | --------------------------- | --------------------------------------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | 161 | | `typegenPath` | `string` | `./.yoga/nexus.ts` | Path to the generated typings. | 162 | | `schemaPath` | `string` | `./src/schema.graphql` | Path to the generated schema. | 163 | 164 | #### InputPrismaConfig 165 | 166 | | Key | Type | Default | Note | 167 | | --------------------------- | --------------------------------------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | 168 | | `datamodelInfoPath` | `string` | `null` | The default exported object generated by `nexus-prisma-generate`. Import it from the output directory generated by `nexus-prisma-generate` | 169 | | `client` | [`PrismaClientInput`](https://github.com/prisma/nexus-prisma/blob/04a24271ae3b7d3cbee3318bc15c4b07cb70cd65/packages/nexus-prisma/src/types.ts#L99) | `./.yoga/prisma-client/index.ts` | Instance of the `prisma-client`, either passed statically or returned from the context defined in your GraphQL server. | 170 | 171 | 172 | ## Contributing 173 | 174 | Install dependencies 175 | 176 | ```bash 177 | npm install 178 | npm run bootstrap 179 | ``` 180 | 181 | Move onto the `./example` folder at the root of the repository (the example is used to test `yoga` locally) 182 | 183 | ```bash 184 | cd ./example 185 | ``` 186 | 187 | And run `yoga` 188 | 189 | ``` 190 | npm run yoga 191 | ``` 192 | 193 | The server should start. You're ready to help 🙏 194 | -------------------------------------------------------------------------------- /examples/minimal-ejected/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | *.log 4 | dist 5 | -------------------------------------------------------------------------------- /examples/minimal-ejected/.yoga/nexus.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file was automatically generated by Nexus 0.10.0 3 | * Do not make changes to this file directly 4 | */ 5 | 6 | import * as ctx from "../src/context" 7 | 8 | 9 | declare global { 10 | interface NexusGen extends NexusGenTypes {} 11 | } 12 | 13 | export interface NexusGenInputs { 14 | } 15 | 16 | export interface NexusGenEnums { 17 | } 18 | 19 | export interface NexusGenRootTypes { 20 | Query: {}; 21 | User: { // root type 22 | id: string; // ID! 23 | name: string; // String! 24 | } 25 | String: string; 26 | Int: number; 27 | Float: number; 28 | Boolean: boolean; 29 | ID: string; 30 | } 31 | 32 | export interface NexusGenAllTypes extends NexusGenRootTypes { 33 | } 34 | 35 | export interface NexusGenFieldTypes { 36 | Query: { // field return type 37 | hello: string; // String! 38 | users: NexusGenRootTypes['User'][]; // [User!]! 39 | } 40 | User: { // field return type 41 | id: string; // ID! 42 | name: string; // String! 43 | } 44 | } 45 | 46 | export interface NexusGenArgTypes { 47 | Query: { 48 | hello: { // args 49 | name?: string | null; // String 50 | } 51 | } 52 | } 53 | 54 | export interface NexusGenAbstractResolveReturnTypes { 55 | } 56 | 57 | export interface NexusGenInheritedFields {} 58 | 59 | export type NexusGenObjectNames = "Query" | "User"; 60 | 61 | export type NexusGenInputNames = never; 62 | 63 | export type NexusGenEnumNames = never; 64 | 65 | export type NexusGenInterfaceNames = never; 66 | 67 | export type NexusGenScalarNames = "Boolean" | "Float" | "ID" | "Int" | "String"; 68 | 69 | export type NexusGenUnionNames = never; 70 | 71 | export interface NexusGenTypes { 72 | context: ctx.Context; 73 | inputTypes: NexusGenInputs; 74 | rootTypes: NexusGenRootTypes; 75 | argTypes: NexusGenArgTypes; 76 | fieldTypes: NexusGenFieldTypes; 77 | allTypes: NexusGenAllTypes; 78 | inheritedFields: NexusGenInheritedFields; 79 | objectNames: NexusGenObjectNames; 80 | inputNames: NexusGenInputNames; 81 | enumNames: NexusGenEnumNames; 82 | interfaceNames: NexusGenInterfaceNames; 83 | scalarNames: NexusGenScalarNames; 84 | unionNames: NexusGenUnionNames; 85 | allInputTypes: NexusGenTypes['inputNames'] | NexusGenTypes['enumNames'] | NexusGenTypes['scalarNames']; 86 | allOutputTypes: NexusGenTypes['objectNames'] | NexusGenTypes['enumNames'] | NexusGenTypes['unionNames'] | NexusGenTypes['interfaceNames'] | NexusGenTypes['scalarNames']; 87 | allNamedTypes: NexusGenTypes['allInputTypes'] | NexusGenTypes['allOutputTypes'] 88 | abstractTypes: NexusGenTypes['interfaceNames'] | NexusGenTypes['unionNames']; 89 | abstractResolveReturn: NexusGenAbstractResolveReturnTypes; 90 | } -------------------------------------------------------------------------------- /examples/minimal-ejected/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "minimal-ejected", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "dev": "yoga dev", 6 | "build": "yoga build", 7 | "build:ci": "yarn build", 8 | "start": "yoga start", 9 | "lint": "echo linting disabled" 10 | }, 11 | "dependencies": { 12 | "yoga": "0.0.20" 13 | }, 14 | "devDependencies": { 15 | "@types/graphql": "^14.0.4", 16 | "@types/node": "^10.12.11", 17 | "@types/ws": "^6.0.1", 18 | "typescript": "^3.2.1" 19 | }, 20 | "prettier": { 21 | "semi": false, 22 | "singleQuote": true, 23 | "trailingComma": "all" 24 | }, 25 | "license": "MIT" 26 | } 27 | -------------------------------------------------------------------------------- /examples/minimal-ejected/src/context.ts: -------------------------------------------------------------------------------- 1 | import { yogaContext } from 'yoga' 2 | 3 | interface UserModel { 4 | id: string 5 | name: string 6 | } 7 | 8 | const users: UserModel[] = [ 9 | { 10 | id: '1', 11 | name: 'Foo', 12 | }, 13 | { 14 | id: '2', 15 | name: 'Bar', 16 | }, 17 | { 18 | id: '3', 19 | name: 'John', 20 | }, 21 | ] 22 | 23 | export interface Context { 24 | users: UserModel[] 25 | } 26 | 27 | export default yogaContext(() => ({ 28 | users, 29 | })) 30 | -------------------------------------------------------------------------------- /examples/minimal-ejected/src/graphql/Query.ts: -------------------------------------------------------------------------------- 1 | import { objectType, stringArg } from 'yoga' 2 | import { User } from './User' 3 | 4 | /* 5 | type Query { 6 | hello(name: String!): String! 7 | user(name: String!): User! 8 | } 9 | */ 10 | export const Query = objectType({ 11 | name: 'Query', 12 | definition(t) { 13 | t.string('hello', { 14 | args: { 15 | name: stringArg(), 16 | }, 17 | resolve: (root, { name }) => `Hello ${name}`, 18 | }) 19 | 20 | t.list.field('users', { 21 | type: User, 22 | resolve: (root, args, ctx) => { 23 | return ctx.users 24 | }, 25 | }) 26 | }, 27 | }) 28 | -------------------------------------------------------------------------------- /examples/minimal-ejected/src/graphql/User.ts: -------------------------------------------------------------------------------- 1 | import { objectType } from 'yoga' 2 | 3 | /* 4 | type User { 5 | id: ID! 6 | name: String! 7 | } 8 | */ 9 | export const User = objectType({ 10 | name: 'User', 11 | definition(t) { 12 | t.id('id') 13 | t.string('name') 14 | }, 15 | }) 16 | -------------------------------------------------------------------------------- /examples/minimal-ejected/src/graphql/index.ts: -------------------------------------------------------------------------------- 1 | export * from './Query' 2 | export * from './User' 3 | -------------------------------------------------------------------------------- /examples/minimal-ejected/src/schema.graphql: -------------------------------------------------------------------------------- 1 | ### This file was autogenerated by Nexus 0.10.0 2 | ### Do not make changes to this file directly 3 | 4 | 5 | type Query { 6 | hello(name: String): String! 7 | users: [User!]! 8 | } 9 | 10 | type User { 11 | id: ID! 12 | name: String! 13 | } 14 | -------------------------------------------------------------------------------- /examples/minimal-ejected/src/server.ts: -------------------------------------------------------------------------------- 1 | import { Server } from 'http' 2 | import * as path from 'path' 3 | import { ApolloServer, express, makeSchema, yogaEject } from 'yoga' 4 | import context from './context' 5 | import * as types from './graphql' 6 | 7 | export default yogaEject({ 8 | async server() { 9 | const app = express() 10 | 11 | const schema = makeSchema({ 12 | types, 13 | outputs: { 14 | schema: path.join(__dirname, './schema.graphql'), 15 | typegen: path.join(__dirname, '../.yoga/nexus.ts'), 16 | }, 17 | typegenAutoConfig: { 18 | sources: [ 19 | { 20 | source: path.join(__dirname, './context.ts'), 21 | alias: 'ctx', 22 | }, 23 | ], 24 | contextType: 'ctx.Context', 25 | }, 26 | }) 27 | 28 | const apolloServer = new ApolloServer.ApolloServer({ 29 | schema, 30 | context, 31 | }) 32 | 33 | apolloServer.applyMiddleware({ app, path: '/' }) 34 | 35 | return app 36 | }, 37 | async startServer(express) { 38 | return new Promise((resolve, reject) => { 39 | const httpServer = express 40 | .listen({ port: 4000 }, () => { 41 | console.log(`🚀 Server ready at http://localhost:4000/`) 42 | 43 | resolve(httpServer) 44 | }) 45 | .on('error', err => reject(err)) 46 | }) 47 | }, 48 | async stopServer(httpServer) { 49 | return httpServer.close() 50 | }, 51 | }) 52 | -------------------------------------------------------------------------------- /examples/minimal-ejected/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "target": "es5", 5 | "rootDir": ".", 6 | "outDir": "dist", 7 | "sourceMap": true, 8 | "lib": ["es2015", "esnext.asynciterable", "es2017", "dom"], 9 | "noUnusedLocals": true, 10 | "noUnusedParameters": false, 11 | "strict": false, 12 | "skipLibCheck": true 13 | }, 14 | "include": ["./src/**/*.ts", ".yoga/**/*"], 15 | "exclude": ["node_modules"] 16 | } 17 | -------------------------------------------------------------------------------- /examples/minimal/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | *.log 4 | dist 5 | -------------------------------------------------------------------------------- /examples/minimal/.yoga/nexus.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file was automatically generated by Nexus 0.9.14 3 | * Do not make changes to this file directly 4 | */ 5 | 6 | import * as ctx from "../src/context" 7 | 8 | 9 | declare global { 10 | interface NexusGen extends NexusGenTypes {} 11 | } 12 | 13 | export interface NexusGenInputs { 14 | } 15 | 16 | export interface NexusGenEnums { 17 | } 18 | 19 | export interface NexusGenRootTypes { 20 | Query: {}; 21 | User: { // root type 22 | id: string; // ID! 23 | name: string; // String! 24 | } 25 | String: string; 26 | Int: number; 27 | Float: number; 28 | Boolean: boolean; 29 | ID: string; 30 | } 31 | 32 | export interface NexusGenAllTypes extends NexusGenRootTypes { 33 | } 34 | 35 | export interface NexusGenFieldTypes { 36 | Query: { // field return type 37 | hello: string; // String! 38 | users: NexusGenRootTypes['User'][]; // [User!]! 39 | } 40 | User: { // field return type 41 | id: string; // ID! 42 | name: string; // String! 43 | } 44 | } 45 | 46 | export interface NexusGenArgTypes { 47 | Query: { 48 | hello: { // args 49 | name: string; // String! 50 | } 51 | } 52 | } 53 | 54 | export interface NexusGenAbstractResolveReturnTypes { 55 | } 56 | 57 | export interface NexusGenInheritedFields {} 58 | 59 | export type NexusGenObjectNames = "Query" | "User"; 60 | 61 | export type NexusGenInputNames = never; 62 | 63 | export type NexusGenEnumNames = never; 64 | 65 | export type NexusGenInterfaceNames = never; 66 | 67 | export type NexusGenScalarNames = "Boolean" | "Float" | "ID" | "Int" | "String"; 68 | 69 | export type NexusGenUnionNames = never; 70 | 71 | export interface NexusGenTypes { 72 | context: ctx.Context; 73 | inputTypes: NexusGenInputs; 74 | rootTypes: NexusGenRootTypes; 75 | argTypes: NexusGenArgTypes; 76 | fieldTypes: NexusGenFieldTypes; 77 | allTypes: NexusGenAllTypes; 78 | inheritedFields: NexusGenInheritedFields; 79 | objectNames: NexusGenObjectNames; 80 | inputNames: NexusGenInputNames; 81 | enumNames: NexusGenEnumNames; 82 | interfaceNames: NexusGenInterfaceNames; 83 | scalarNames: NexusGenScalarNames; 84 | unionNames: NexusGenUnionNames; 85 | allInputTypes: NexusGenTypes['inputNames'] | NexusGenTypes['enumNames'] | NexusGenTypes['scalarNames']; 86 | allOutputTypes: NexusGenTypes['objectNames'] | NexusGenTypes['enumNames'] | NexusGenTypes['unionNames'] | NexusGenTypes['interfaceNames'] | NexusGenTypes['scalarNames']; 87 | allNamedTypes: NexusGenTypes['allInputTypes'] | NexusGenTypes['allOutputTypes'] 88 | abstractTypes: NexusGenTypes['interfaceNames'] | NexusGenTypes['unionNames']; 89 | abstractResolveReturn: NexusGenAbstractResolveReturnTypes; 90 | } -------------------------------------------------------------------------------- /examples/minimal/README.md: -------------------------------------------------------------------------------- 1 | ## Getting started 2 | 3 | Run the following command to bootstrap the example 4 | 5 | ```bash 6 | yarn create yoga 7 | ``` 8 | 9 | Then select the `minimal-yoga` template 10 | 11 | ``` 12 | ? Choose a GraphQL server template? 13 | ❯ minimal-yoga (Basic starter template) 14 | db-yoga (Template with Prisma database support) 15 | ``` 16 | 17 | Once this is done, `cd` in the created directory, and run 18 | 19 | ```bash 20 | yarn dev 21 | ``` 22 | 23 | You're good to go, `yarn dev` will start the server 🙌 -------------------------------------------------------------------------------- /examples/minimal/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "minimal", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "dev": "yoga dev", 6 | "build": "yoga build", 7 | "build:ci": "yarn build", 8 | "start": "yoga start", 9 | "lint": "echo linting disabled" 10 | }, 11 | "dependencies": { 12 | "yoga": "0.0.20" 13 | }, 14 | "devDependencies": { 15 | "@types/graphql": "^14.0.4", 16 | "@types/ws": "^6.0.1", 17 | "@types/node": "^10.12.11", 18 | "typescript": "^3.2.1" 19 | }, 20 | "prettier": { 21 | "semi": false, 22 | "singleQuote": true, 23 | "trailingComma": "all" 24 | }, 25 | "license": "MIT" 26 | } 27 | -------------------------------------------------------------------------------- /examples/minimal/src/context.ts: -------------------------------------------------------------------------------- 1 | import { data, Data } from './data' 2 | 3 | export interface Context { 4 | data: Data 5 | } 6 | 7 | export default () => ({ 8 | data, 9 | }) 10 | -------------------------------------------------------------------------------- /examples/minimal/src/data.ts: -------------------------------------------------------------------------------- 1 | interface UserModel { 2 | id: string 3 | name: string 4 | } 5 | 6 | const users: UserModel[] = [ 7 | { 8 | id: '1', 9 | name: 'Foo', 10 | }, 11 | { 12 | id: '2', 13 | name: 'Bar', 14 | }, 15 | { 16 | id: '3', 17 | name: 'John', 18 | }, 19 | ] 20 | 21 | export interface Data { 22 | users: UserModel[] 23 | } 24 | 25 | export const data = { 26 | users, 27 | } 28 | -------------------------------------------------------------------------------- /examples/minimal/src/graphql/Query.ts: -------------------------------------------------------------------------------- 1 | import { queryType, stringArg } from 'yoga' 2 | 3 | /* 4 | type Query { 5 | hello(name: String!): String! 6 | user(name: String!): User! 7 | } 8 | */ 9 | export const Query = queryType({ 10 | definition(t) { 11 | t.string('hello', { 12 | args: { 13 | name: stringArg(), 14 | }, 15 | resolve: (root, { name }) => `Hello ${name}`, 16 | }) 17 | 18 | t.list.field('users', { 19 | type: 'User', 20 | resolve: (root, args, ctx) => { 21 | return ctx.data.users 22 | }, 23 | }) 24 | }, 25 | }) 26 | -------------------------------------------------------------------------------- /examples/minimal/src/graphql/User.ts: -------------------------------------------------------------------------------- 1 | import { objectType } from 'yoga' 2 | 3 | /* 4 | type User { 5 | id: ID! 6 | name: String! 7 | } 8 | */ 9 | export const User = objectType({ 10 | name: 'User', 11 | definition(t) { 12 | t.id('id') 13 | t.string('name') 14 | }, 15 | }) 16 | -------------------------------------------------------------------------------- /examples/minimal/src/schema.graphql: -------------------------------------------------------------------------------- 1 | ### This file was autogenerated by Nexus 0.9.14 2 | ### Do not make changes to this file directly 3 | 4 | 5 | type Query { 6 | hello(name: String!): String! 7 | users: [User!]! 8 | } 9 | 10 | type User { 11 | id: ID! 12 | name: String! 13 | } 14 | -------------------------------------------------------------------------------- /examples/minimal/src/server.ts: -------------------------------------------------------------------------------- 1 | import * as path from 'path' 2 | import { ApolloServer, makeSchema, express, yogaEject } from 'yoga' 3 | import * as types from './graphql' 4 | import context from './context' 5 | 6 | export default yogaEject({ 7 | async server() { 8 | const schema = makeSchema({ 9 | types, 10 | outputs: { 11 | schema: path.join(__dirname, './schema.graphql'), 12 | typegen: path.join(__dirname, '../.yoga/nexus.ts'), 13 | }, 14 | nonNullDefaults: { 15 | input: true, 16 | output: true, 17 | }, 18 | typegenAutoConfig: { 19 | sources: [ 20 | { 21 | source: path.join(__dirname, './context.ts'), 22 | alias: 'ctx', 23 | }, 24 | ], 25 | contextType: 'ctx.Context', 26 | }, 27 | }) 28 | const apolloServer = new ApolloServer.ApolloServer({ 29 | schema, 30 | context, 31 | }) 32 | const app = express() 33 | 34 | apolloServer.applyMiddleware({ app, path: '/' }) 35 | 36 | return app 37 | }, 38 | async startServer(app) { 39 | return app.listen({ port: 4000 }, () => { 40 | console.log(`🚀 Server ready at http://localhost:4000/`) 41 | }) 42 | }, 43 | async stopServer(http) { 44 | http.close() 45 | }, 46 | }) 47 | -------------------------------------------------------------------------------- /examples/minimal/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "moduleResolution": "node", 5 | "target": "es5", 6 | "rootDir": ".", 7 | "outDir": "dist", 8 | "sourceMap": true, 9 | "lib": ["es2015", "esnext.asynciterable", "es2017", "dom"], 10 | "noUnusedLocals": true, 11 | "noUnusedParameters": false, 12 | "strict": false, 13 | "skipLibCheck": true 14 | }, 15 | "include": ["./src/**/*.ts", ".yoga/**/*"], 16 | "exclude": ["node_modules"] 17 | } 18 | -------------------------------------------------------------------------------- /examples/with-db/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | *.log 4 | .yoga 5 | dist 6 | -------------------------------------------------------------------------------- /examples/with-db/README.md: -------------------------------------------------------------------------------- 1 | ## Getting started 2 | 3 | 4 | 5 | Run the following command to bootstrap the example 6 | 7 | ```bash 8 | yarn create yoga 9 | ``` 10 | 11 | Then select the `db-yoga` template 12 | 13 | ``` 14 | ? Choose a GraphQL server template? 15 | minimal-yoga (Basic starter template ) 16 | ❯ db-yoga (Template with Prisma database support) 17 | ``` 18 | 19 | Once this is done, `cd` in the created directory, and run 20 | 21 | ```bash 22 | yarn prisma deploy 23 | ``` 24 | 25 | For a quicker startup, choose `Demo server` 26 | 27 | ```bash 28 | ? Set up a new Prisma server or deploy to an existing server? 29 | Use existing database Connect to existing database 30 | Create new database Set up a local database using Docker 31 | 32 | Or deploy to an existing Prisma server: 33 | ❯ Demo server Hosted demo environment incl. database 34 | ``` 35 | 36 | You're good to go, simply run `yarn dev` and the server will start 🙌 -------------------------------------------------------------------------------- /examples/with-db/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "with-db", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "dev": "yoga dev", 6 | "build": "yoga build", 7 | "build:ci": "npx nexus-prisma-generate --output ./.yoga/nexus-prisma && yarn prisma generate && yoga build", 8 | "start": "yoga start", 9 | "scaffold": "yoga scaffold", 10 | "lint": "echo linting disabled" 11 | }, 12 | "dependencies": { 13 | "yoga": "0.0.20" 14 | }, 15 | "devDependencies": { 16 | "@types/graphql": "^14.0.4", 17 | "@types/node": "^10.12.11", 18 | "@types/ws": "^6.0.1", 19 | "prisma": "^1.26.4", 20 | "typescript": "^3.2.1" 21 | }, 22 | "prettier": { 23 | "semi": false, 24 | "singleQuote": true, 25 | "trailingComma": "all" 26 | }, 27 | "license": "MIT" 28 | } 29 | -------------------------------------------------------------------------------- /examples/with-db/prisma/datamodel.prisma: -------------------------------------------------------------------------------- 1 | type User { 2 | id: ID! @id 3 | email: String! @unique 4 | name: String! 5 | posts: [Post!]! 6 | } 7 | 8 | type Post { 9 | id: ID! @id 10 | title: String! 11 | content: String! 12 | published: Boolean! @default(value: false) 13 | author: User! 14 | } 15 | -------------------------------------------------------------------------------- /examples/with-db/prisma/prisma.yml: -------------------------------------------------------------------------------- 1 | # Defines your models, each model is mapped to the database as a table. 2 | datamodel: datamodel.prisma 3 | 4 | # Specifies the language and directory for the generated Prisma client. 5 | generate: 6 | - generator: typescript-client 7 | output: ../.yoga/prisma-client/ 8 | 9 | # Ensures Prisma client is re-generated after a datamodel change. 10 | hooks: 11 | post-deploy: 12 | - npx nexus-prisma-generate --output ./.yoga/nexus-prisma 13 | 14 | # Seeds initial data into the database by running a script. 15 | seed: 16 | run: npx ts-node ./prisma/seed.ts 17 | -------------------------------------------------------------------------------- /examples/with-db/prisma/seed.ts: -------------------------------------------------------------------------------- 1 | import { prisma } from '../.yoga/prisma-client' 2 | 3 | async function main() { 4 | await prisma.createUser({ 5 | email: 'alice@prisma.io', 6 | name: 'Alice', 7 | posts: { 8 | create: { 9 | title: 'Join us for GraphQL Conf 2019 in Berlin', 10 | content: 'https://www.graphqlconf.org/', 11 | published: true, 12 | }, 13 | }, 14 | }) 15 | await prisma.createUser({ 16 | email: 'bob@prisma.io', 17 | name: 'Bob', 18 | posts: { 19 | create: [ 20 | { 21 | title: 'Subscribe to GraphQL Weekly for community news', 22 | content: 'https://graphqlweekly.com/', 23 | published: true, 24 | }, 25 | { 26 | title: 'Follow Prisma on Twitter', 27 | content: 'https://twitter.com/prisma', 28 | }, 29 | ], 30 | }, 31 | }) 32 | } 33 | 34 | main().catch(e => console.error(e)) 35 | -------------------------------------------------------------------------------- /examples/with-db/src/context.ts: -------------------------------------------------------------------------------- 1 | import { prisma, Prisma } from '../.yoga/prisma-client' 2 | import { yogaContext } from 'yoga' 3 | 4 | export interface Context { 5 | prisma: Prisma 6 | } 7 | 8 | export default yogaContext(({ req }) => ({ 9 | req, 10 | prisma, 11 | })) 12 | -------------------------------------------------------------------------------- /examples/with-db/src/graphql/Mutation.ts: -------------------------------------------------------------------------------- 1 | import { idArg, prismaObjectType, stringArg } from 'yoga' 2 | 3 | /* 4 | type Mutation { 5 | deletePost(id: ID!): Post 6 | signupUser(name: String!, email: String!): User! 7 | createDraft(title: String!, content: String!, authorEmail: String!): Post! 8 | publish(id: ID!): Post! 9 | } 10 | */ 11 | export const Mutation = prismaObjectType({ 12 | name: 'Mutation', 13 | definition(t) { 14 | // All fields from the underlying object type are exposed automatically 15 | // use `t.primaFields(['fieldName', ...])` to hide, customize, or select specific fields 16 | 17 | // This removes all fields from the underlying Mutation object type 18 | t.prismaFields([]) 19 | 20 | t.field('deletePost', { 21 | type: 'Post', 22 | nullable: true, 23 | args: { 24 | id: idArg(), 25 | }, 26 | resolve: (parent, args, ctx) => { 27 | return ctx.prisma.deletePost({ id: args.id }) 28 | }, 29 | }) 30 | 31 | t.field('signupUser', { 32 | type: 'User', 33 | args: { 34 | name: stringArg(), 35 | email: stringArg(), 36 | }, 37 | resolve: (parent, { name, email }, ctx) => { 38 | return ctx.prisma.createUser({ name, email }) 39 | }, 40 | }) 41 | 42 | t.field('createDraft', { 43 | type: 'Post', 44 | args: { 45 | title: stringArg(), 46 | content: stringArg(), 47 | authorEmail: stringArg(), 48 | }, 49 | resolve: (parent, { title, content, authorEmail }, ctx) => { 50 | return ctx.prisma.createPost({ 51 | title, 52 | content, 53 | author: { connect: { email: authorEmail } }, 54 | }) 55 | }, 56 | }) 57 | 58 | t.field('publish', { 59 | type: 'Post', 60 | args: { 61 | id: idArg(), 62 | }, 63 | resolve: (parent, { id }, ctx) => { 64 | return ctx.prisma.updatePost({ 65 | where: { id }, 66 | data: { published: true }, 67 | }) 68 | }, 69 | }) 70 | }, 71 | }) 72 | -------------------------------------------------------------------------------- /examples/with-db/src/graphql/Post.ts: -------------------------------------------------------------------------------- 1 | import { prismaObjectType } from 'yoga' 2 | 3 | export const Post = prismaObjectType({ 4 | name: 'Post', 5 | definition(t) { 6 | // If you wish you customize/hide fields, call `t.prismaFields(['id', ...])` with the desired field names 7 | // If you wish to add custom fields on top of prisma's ones, use t.field/string/int... 8 | t.prismaFields(['*']) 9 | }, 10 | }) 11 | -------------------------------------------------------------------------------- /examples/with-db/src/graphql/Query.ts: -------------------------------------------------------------------------------- 1 | import { prismaObjectType, stringArg } from 'yoga' 2 | 3 | /* 4 | type Query { 5 | feed: [Post!]! 6 | filterPosts(searchString: String!): [Post!]! 7 | } 8 | */ 9 | export const Query = prismaObjectType({ 10 | name: 'Query', 11 | definition(t) { 12 | // All fields from the underlying object type are exposed automatically 13 | // use `t.primaFields(['fieldName', ...])` to hide, customize, or select specific fields 14 | 15 | // This removes all fields from the underlying Query object type 16 | t.prismaFields([]) 17 | 18 | t.list.field('feed', { 19 | type: 'Post', 20 | resolve: (parent, args, ctx) => { 21 | return ctx.prisma.posts({ 22 | where: { published: true }, 23 | }) 24 | }, 25 | }) 26 | 27 | t.list.field('filterPosts', { 28 | type: 'Post', 29 | args: { 30 | searchString: stringArg(), 31 | }, 32 | resolve: (parent, { searchString }, ctx) => { 33 | return ctx.prisma.posts({ 34 | where: { 35 | OR: [ 36 | { title_contains: searchString }, 37 | { content_contains: searchString }, 38 | ], 39 | }, 40 | }) 41 | }, 42 | }) 43 | }, 44 | }) 45 | -------------------------------------------------------------------------------- /examples/with-db/src/graphql/User.ts: -------------------------------------------------------------------------------- 1 | import { prismaObjectType } from 'yoga' 2 | 3 | export const User = prismaObjectType({ 4 | name: 'User', 5 | definition(t) { 6 | // If you wish you customize/hide fields, call `t.prismaFields(['id', ...])` with the desired field names 7 | // If you wish to add custom fields on top of prisma's ones, use t.field/string/int... 8 | t.prismaFields(['*']) 9 | }, 10 | }) 11 | -------------------------------------------------------------------------------- /examples/with-db/src/schema.graphql: -------------------------------------------------------------------------------- 1 | ### This file was autogenerated by Nexus 0.9.17 2 | ### Do not make changes to this file directly 3 | 4 | 5 | type Mutation { 6 | createDraft(authorEmail: String!, content: String!, title: String!): Post! 7 | deletePost(id: ID!): Post 8 | publish(id: ID!): Post! 9 | signupUser(email: String!, name: String!): User! 10 | } 11 | 12 | type Post { 13 | author: User! 14 | content: String! 15 | id: ID! 16 | published: Boolean! 17 | title: String! 18 | } 19 | 20 | enum PostOrderByInput { 21 | content_ASC 22 | content_DESC 23 | createdAt_ASC 24 | createdAt_DESC 25 | id_ASC 26 | id_DESC 27 | published_ASC 28 | published_DESC 29 | title_ASC 30 | title_DESC 31 | updatedAt_ASC 32 | updatedAt_DESC 33 | } 34 | 35 | input PostWhereInput { 36 | AND: [PostWhereInput!] 37 | author: UserWhereInput 38 | content: String 39 | content_contains: String 40 | content_ends_with: String 41 | content_gt: String 42 | content_gte: String 43 | content_in: [String!] 44 | content_lt: String 45 | content_lte: String 46 | content_not: String 47 | content_not_contains: String 48 | content_not_ends_with: String 49 | content_not_in: [String!] 50 | content_not_starts_with: String 51 | content_starts_with: String 52 | id: ID 53 | id_contains: ID 54 | id_ends_with: ID 55 | id_gt: ID 56 | id_gte: ID 57 | id_in: [ID!] 58 | id_lt: ID 59 | id_lte: ID 60 | id_not: ID 61 | id_not_contains: ID 62 | id_not_ends_with: ID 63 | id_not_in: [ID!] 64 | id_not_starts_with: ID 65 | id_starts_with: ID 66 | NOT: [PostWhereInput!] 67 | OR: [PostWhereInput!] 68 | published: Boolean 69 | published_not: Boolean 70 | title: String 71 | title_contains: String 72 | title_ends_with: String 73 | title_gt: String 74 | title_gte: String 75 | title_in: [String!] 76 | title_lt: String 77 | title_lte: String 78 | title_not: String 79 | title_not_contains: String 80 | title_not_ends_with: String 81 | title_not_in: [String!] 82 | title_not_starts_with: String 83 | title_starts_with: String 84 | } 85 | 86 | type Query { 87 | feed: [Post!]! 88 | filterPosts(searchString: String!): [Post!]! 89 | } 90 | 91 | type User { 92 | email: String! 93 | id: ID! 94 | name: String! 95 | posts(after: String, before: String, first: Int, last: Int, orderBy: PostOrderByInput, skip: Int, where: PostWhereInput): [Post!] 96 | } 97 | 98 | input UserWhereInput { 99 | AND: [UserWhereInput!] 100 | email: String 101 | email_contains: String 102 | email_ends_with: String 103 | email_gt: String 104 | email_gte: String 105 | email_in: [String!] 106 | email_lt: String 107 | email_lte: String 108 | email_not: String 109 | email_not_contains: String 110 | email_not_ends_with: String 111 | email_not_in: [String!] 112 | email_not_starts_with: String 113 | email_starts_with: String 114 | id: ID 115 | id_contains: ID 116 | id_ends_with: ID 117 | id_gt: ID 118 | id_gte: ID 119 | id_in: [ID!] 120 | id_lt: ID 121 | id_lte: ID 122 | id_not: ID 123 | id_not_contains: ID 124 | id_not_ends_with: ID 125 | id_not_in: [ID!] 126 | id_not_starts_with: ID 127 | id_starts_with: ID 128 | name: String 129 | name_contains: String 130 | name_ends_with: String 131 | name_gt: String 132 | name_gte: String 133 | name_in: [String!] 134 | name_lt: String 135 | name_lte: String 136 | name_not: String 137 | name_not_contains: String 138 | name_not_ends_with: String 139 | name_not_in: [String!] 140 | name_not_starts_with: String 141 | name_starts_with: String 142 | NOT: [UserWhereInput!] 143 | OR: [UserWhereInput!] 144 | posts_every: PostWhereInput 145 | posts_none: PostWhereInput 146 | posts_some: PostWhereInput 147 | } 148 | -------------------------------------------------------------------------------- /examples/with-db/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "moduleResolution": "node", 5 | "target": "es5", 6 | "rootDir": "./", 7 | "outDir": "dist", 8 | "sourceMap": true, 9 | "lib": ["es2015", "esnext.asynciterable", "es2017", "dom"], 10 | "noUnusedLocals": true, 11 | "noUnusedParameters": false, 12 | "strict": false, 13 | "skipLibCheck": true 14 | }, 15 | "include": ["./**/*.ts", ".yoga/**/*"], 16 | "exclude": ["node_modules"] 17 | } 18 | -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.0.0", 3 | "npmClient": "yarn", 4 | "useWorkspaces": true 5 | } 6 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "yoga2", 3 | "private": true, 4 | "scripts": { 5 | "bootstrap": "yarn install && lerna bootstrap && cd packages/yoga && npm link", 6 | "bootstrap:ci": "yarn install && lerna bootstrap", 7 | "clean": "lerna clean -y && yarn clean:packages && yarn clean:root", 8 | "clean:packages": "lerna exec -- rm -rf node_modules yarn.lock package-lock.json dist", 9 | "clean:root": "rm -rf node_modules yarn.lock package-lock.json", 10 | "reset": "yarn clean && yarn bootstrap", 11 | "build": "lerna run build", 12 | "build:ci": "lerna run build:ci", 13 | "lint": "lerna exec -- npm run lint" 14 | }, 15 | "workspaces": [ 16 | "packages/*", 17 | "examples/*" 18 | ], 19 | "license": "MIT", 20 | "devDependencies": { 21 | "lerna": "3.13.4" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /packages/create-yoga/README.md: -------------------------------------------------------------------------------- 1 | ## Create yoga 2 | 3 | Creator for yoga command 4 | 5 | ## Getting started with GraphQL Yoga 6 | 7 | Package is available using npm init command: 8 | 9 | ``` 10 | npm init yoga 11 | ``` 12 | 13 | Creator ask for name of template and location where it should be saved 14 | 15 | ``` 16 | ? Choose a GraphQL server template? default-yoga (Default Yoga template ) 17 | ? Where should we scaffold graphql server? ./output 18 | ✔ Downloading starter from https://api.github.com/repos/prisma/yoga2/tarball/master 19 | ✔ Extracting content to yoga2/packages/create-yoga/output 20 | ⠋ Installing dependencies 👩‍🚀 21 | ``` -------------------------------------------------------------------------------- /packages/create-yoga/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "create-yoga", 3 | "version": "0.0.5", 4 | "main": "dist/index.js", 5 | "license": "MIT", 6 | "scripts": { 7 | "prepublish": "npm run build", 8 | "build": "rimraf dist && tsc -d", 9 | "build:ci": "yarn build", 10 | "pretest": "npm run build && npm run lint", 11 | "lint": "tslint {src,test}/**/*.ts", 12 | "start": "ts-node src/bin.ts" 13 | }, 14 | "bin": { 15 | "create-yoga": "dist/bin.js" 16 | }, 17 | "files": [ 18 | "dist", 19 | "README.md" 20 | ], 21 | "dependencies": { 22 | "chalk": "^2.4.1", 23 | "execa": "^1.0.0", 24 | "inquirer": "^6.2.0", 25 | "inquirer-path": "^1.0.0-beta5", 26 | "js-yaml": "^3.12.2", 27 | "meow": "^5.0.0", 28 | "ora": "^3.2.0", 29 | "parse-github-url": "^1.0.2", 30 | "prettier": "^1.16.4", 31 | "prisma-datamodel": "^1.28.3", 32 | "prisma-generate-schema": "^1.28.3", 33 | "prisma-json-schema": "^0.1.3", 34 | "request": "^2.88.0", 35 | "rimraf": "^2.6.3", 36 | "tar": "^4.4.7", 37 | "update-notifier": "^2.5.0" 38 | }, 39 | "devDependencies": { 40 | "@types/execa": "0.9.0", 41 | "@types/inquirer": "6.0.1", 42 | "@types/meow": "5.0.0", 43 | "@types/node": "10.14.5", 44 | "@types/parse-github-url": "1.0.0", 45 | "@types/request": "2.48.1", 46 | "@types/rimraf": "2.0.2", 47 | "@types/tar": "4.0.0", 48 | "@types/tmp": "0.1.0", 49 | "@types/update-notifier": "2.5.0", 50 | "ts-node": "8.1.0", 51 | "tslint": "5.16.0", 52 | "tslint-config-prettier": "1.18.0", 53 | "tslint-config-standard": "8.0.1", 54 | "typescript": "3.4.5" 55 | }, 56 | "prettier": { 57 | "semi": false, 58 | "singleQuote": true, 59 | "trailingComma": "all" 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /packages/create-yoga/src/bin.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | import { createTemplate } from './index' 4 | 5 | // tslint:disable-next-line: no-floating-promises 6 | createTemplate() 7 | -------------------------------------------------------------------------------- /packages/create-yoga/src/bootstrap.ts: -------------------------------------------------------------------------------- 1 | import * as fs from 'fs' 2 | import * as inquirer from 'inquirer' 3 | import * as meow from 'meow' 4 | import * as path from 'path' 5 | import { loadYogaStarter } from './loader' 6 | import { availableTemplates, Template, templatesNames } from './templates' 7 | 8 | export function templateFromFlags(cli: meow.Result): Template { 9 | const selectedTemplate = availableTemplates.find( 10 | t => t.name === cli.flags['template'], 11 | ) 12 | 13 | if (selectedTemplate) { 14 | return selectedTemplate 15 | } else { 16 | console.log(`Unknown template. Available templates: ${templatesNames}`) 17 | return 18 | } 19 | } 20 | 21 | async function askTemplate(): Promise