## File: README.md

## Quick start

### Install

```sh
pnpm add graphql-yoga graphql
```

### Start

Make a schema, create Yoga and start a Node server:

```ts
import { createServer } from 'node:http'
import { createSchema, createYoga } from 'graphql-yoga'

const yoga = createYoga({
  schema: createSchema({
    typeDefs: /* GraphQL */ `
      type Query {
        hello: String
      }
    `,
    resolvers: {
      Query: {
        hello: () => 'Hello from Yoga!'
      }
    }
  })
})

const server = createServer(yoga)

server.listen(4000, () => {
  console.info('Server is running on http://localhost:4000/graphql')
})
```

## Overview

- **Easiest way to run a GraphQL server:** Sensible defaults & includes everything you need with
  minimal setup (we also export a platform/env-agnostic handler so you can build your own wrappers
  easily).
- **Includes Subscriptions:** Built-in support for GraphQL subscriptions using
  [**S**erver-**S**ent **E**vents](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events).
- **Compatible:** Works with all GraphQL clients
  ([Apollo](https://www.apollographql.com/docs/react/), [Relay](https://relay.dev/),
  [Urql](https://formidable.com/open-source/urql/)...) and fits seamless in your GraphQL workflow.
- **WHATWG Fetch API:** the core package depends on
  [WHATWG Fetch API](https://fetch.spec.whatwg.org/) so it can run and deploy on any environment
  (Serverless, Workers, Deno, Node).
- **Easily Extendable:** New GraphQL-Yoga support all [`envelop`](https://www.envelop.dev) plugins.

## [Features](https://www.the-guild.dev/graphql/yoga-server/docs)

- Fully typed with [TypeScript](https://www.typescriptlang.org)
- [GraphQL over HTTP spec compliant](https://github.com/enisdenjo/graphql-http/tree/master/implementations/graphql-yoga)
- [GraphiQL included](https://www.the-guild.dev/graphql/yoga-server/docs/features/graphiql)
- [File uploads with GraphQL Multipart Request spec](https://www.the-guild.dev/graphql/yoga-server/docs/features/file-uploads)
- [Subscriptions and realtime capabilities](https://www.the-guild.dev/graphql/yoga-server/docs/features/subscriptions)
- [Automatic persisted queries](https://www.the-guild.dev/graphql/yoga-server/docs/features/automatic-persisted-queries)
- [Built-in parsing and validation caching](https://www.the-guild.dev/graphql/yoga-server/docs/features/parsing-and-validation-caching)
- [Testing utilities](https://www.the-guild.dev/graphql/yoga-server/docs/features/testing)
- Supports [ESM](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules)
- Runs **everywhere**, including environments like:
  - [Deno](https://www.the-guild.dev/graphql/yoga-server/docs/integrations/integration-with-deno)
  - [Bun](https://www.the-guild.dev/graphql/yoga-server/docs/integrations/integration-with-bun)
  - [Cloudflare Workers](https://www.the-guild.dev/graphql/yoga-server/docs/integrations/integration-with-cloudflare-workers)
  - [AWS Lambda](https://www.the-guild.dev/graphql/yoga-server/docs/integrations/integration-with-aws-lambda)
  - [_And other..._](https://www.the-guild.dev/graphql/yoga-server/docs/integrations/z-other-environments)
- [_And more..._](https://www.the-guild.dev/graphql/yoga-server/docs)

## [Documentation](https://www.the-guild.dev/graphql/yoga-server/docs)

Our [documentation website](https://www.the-guild.dev/graphql/yoga-server/docs) will help you get
started.

## [Examples](https://github.com/graphql-hive/graphql-yoga/tree/main/examples)

We've made sure developers can quickly start with GraphQL Yoga by providing a comprehensive set of
examples.
[See all of them in the `examples/` folder.](https://github.com/graphql-hive/graphql-yoga/tree/main/examples)

## [Comparison](https://www.the-guild.dev/graphql/yoga-server/docs/comparison)

Read more about how GraphQL Yoga compares to other servers in the ecosystem
[here](https://www.the-guild.dev/graphql/yoga-server/docs/comparison).

## Contributing

If this is your first time contributing to this project, please do read our
[Contributor Workflow Guide](https://github.com/the-guild-org/Stack/blob/master/CONTRIBUTING.md)
before you get started off.

For this project in particular, to get started on `stage/2-failing-test`:

1. Install [Node.js](https://nodejs.org/)
2. Run in your terminal: `npm i pnpm@8 && pnpm install && pnpm build`
3. Add tests to `packages/graphql-yoga/__tests__` using [Jest](https://jestjs.io/docs/api) APIs
4. Run the tests with `pnpm test`

Feel free to open issues and pull requests. We're always welcome support from the community.

## Code of Conduct

Help us keep Yoga open and inclusive. Please read and follow our
[Code of Conduct](https://github.com/the-guild-org/Stack/blob/master/CODE_OF_CONDUCT.md) as adopted
from [Contributor Covenant](https://www.contributor-covenant.org/).

## License

MIT

---

## File: e2e/README.md

## Yoga e2e testing

This project contains everything related to e2e testing for GraphQL-Yoga.

In order to ensure that GraphQL-Yoga is compatible with all popular runtimes.

To do that, we are using [Pulumi](https://www.pulumi.com/) (infrastructure-as-code) (with
TypeScript, and using [Automation API](https://www.pulumi.com/docs/guides/automation-api/)) to
provision a real resource in every env, run smoke tests (`GET -> GraphiQL`,
`POST -> Execute GraphQL`), and then destroy and remove all resources.

On each PR, this workflow runs, and tried to deploy and test an actual environment. This way we can
find issues like compatibility issues / runtime issues during code reviews.

### Tested Enrivonments

- [x] [CloudFlare Worker](./tests/cf-worker.ts)
- [x] [Azure Function](./tests/azure-function.ts)
- [x] [AWS Lambda](./tests/aws-lambda.ts)
- [x] [Docker container](./tests/docker.ts)
- [x] [Vercel Function](./tests/vercel.ts)
- [ ] K8s Pod
- [ ] Docker

### Notes

- This check runs on every PR created to GraphQL-Yoga repo.
- We are using the locally built version of Yoga - so all functions are deployed as built artifact
  (using `esbuild`).

---

## File: examples/sveltekit/README.md

# GraphQL Yoga - SvelteKit

[Learn more](https://www.graphql-yoga.com/docs/integrations/integration-with-sveltekit)

---

## File: examples/subscriptions/README.md

# subscriptions

This directory contains a simple GraphQL subscriptions example based on `graphql-yoga`.

## Get started

**Clone the repository:**

```sh
git clone https://github.com/graphcool/graphql-yoga.git
cd graphql-yoga/examples/subscriptions
```

**Install dependencies and run the app:**

```sh
pnpm install # or npm install
pnpm start   # or npm start
```

## Testing

### Counter

Open your browser at [http://localhost:4000](http://localhost:4000).

Paste the following subscription in the editor (left side) of GraphiQL:

```graphql
subscription {
  counter
}
```

Press the Play (Execute Query) button.

The counter will increment every second and the corresponding data is received in the Playground:

```json
{
  "data": {
    "counter": 1,
  }
}
// ... 1 seconds
{
  "data": {
    "counter": 2,
  }
}
// ... 2 seconds
{
  "data": {
    "counter": 3,
  }
}
// ...
```

### Global counter

Open your browser at [http://localhost:4000](http://localhost:4000)n.

Paste the following subscription in the editor (left side) of GraphiQL:

```graphql
subscription {
  globalCounter
}
```

Press the Play (Execute Query) button.

You will receive this initial result:

```json
{
  "data": {
    "globalCounter": 0
  }
}
```

Open another browser window and execute the following mutation:

```graphql
mutation {
  incrementGlobalCounter
}
```

Press the Play (Execute Query) button.

You will receive this result:

```json
{
  "data": {
    "incrementGlobalCounter": 1
  }
}
```

On the other window that is executing the subscription, you will receive a new result.

```json
{
  "data": {
    "globalCounter": 1
  }
}
```

As you re-execute the mutation the global counter will be further incremented.

---

## File: examples/service-worker/README.md

### Yoga + CloudFlare Worker (bundle)

> [See e2e testing for more information](../../e2e/tests/cf-worker.ts)

> [For example using CloudFlare Wrangler see this page](../cloudflare-modules)

---

## File: examples/redis-pub-sub/README.md

# Redis Pub/Sub Example

## Usage instructions

Start Redis with Docker

```bash
docker run -p "6379:6379" redis:7.0.2
```

Start two server instances running on different ports

```bash
PORT=4000 pnpm --filter example-redis-pub-sub start
PORT=4001 pnpm --filter example-redis-pub-sub start
```

Visit and set up the subscription by pressing the Play button.

```bash
http://127.0.0.1:4000/graphql?query=subscription+%7B%0A++message%0A%7D
```

Visit and execute the mutation by pressing the Play button.

```bash
http://127.0.0.1:4001/graphql?query=mutation+%7B%0A++sendMessage%28message%3A+%22Yo+we+share+a+redis+instance.%22%29%0A%7D
```

See your subscription update appear on `127.0.0.1:4000`, even though you executed the mutation on a
different Node.js server instance running on `127.0.0.1:4001`.

The magic of Redis. 🪄✨

---

## File: examples/nextjs-ws/README.md

# Next.js WebSockets

## Get Started

Run the custom server with:

```sh
npm start
# or
yarn start
# or
pnpm start
```

Navigate to [http://localhost:3000](http://localhost:3000) to see the Next.js app running. You can
start editing the page by modifying `pages/index.js`. The page auto-updates as you edit files.

WebSockets cannot be used with
[Next.js API Routes](https://nextjs.org/docs/api-routes/introduction), we therefore have to create a
[custom Next.js server](https://nextjs.org/docs/advanced-features/custom-server) that will serve the
GraphQL API, WebSockets and the rest of Next.js content.

This custom server implementation can be found in [`server.js`](server.js).

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
- [Next.js custom server](https://nextjs.org/docs/advanced-features/custom-server) - allows you to
  start a server 100% programmatically in order to use custom server patterns

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your
feedback and contributions are welcome!

## No deployment on Vercel

Since this Next.js project uses a
[custom server](https://nextjs.org/docs/advanced-features/custom-server), it cannot be deployed to
Vercel.

---

## File: examples/nextjs-legacy-pages/README.md

This is a [Next.js](https://nextjs.org/) project bootstrapped with
[`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
pnpm dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `pages/index.js`. The page auto-updates as you edit the
file.

[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on
[http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in
`pages/api/hello.js`.

The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as
[API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your
feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the
[Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme)
from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more
details.

---

## File: examples/nextjs-auth/README.md

This is a Next.js example using [next-auth.js](https://next-auth.js.org/).

Before running this example you need to set upa GitHubOAuth App.
[Follow the instructions here](https://docs.github.com/en/developers/apps/building-oauth-apps/creating-an-oauth-app).

Use `http://localhost:3000/` as the homepage URL.

Use `http://localhost:3000/api/auth/callback/github` as the authorization callback URL.

Afterwards, you must copy the `.env.sample` to `.env` (`cp .env.sample .env`) and fill in the
environment variables (`GITHUB_ID` and `GITHUB_SECRET`) you received from your GitHub OAuth
application.

Run the app with `pnpm dev`.

You can log in on `http://localhost:3000`.

Run the following operation on `http://localhost:3000/api/graphql`.

```graphql
query Session {
  session {
    expires
    user {
      id
      email
      image
    }
  }
}
```

---

This is a [Next.js](https://nextjs.org/) project bootstrapped with
[`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).

## Getting Started

First, run the development server:

```bash
pnpm dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `pages/index.js`. The page auto-updates as you edit the
file.

[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on
[http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in
`pages/api/hello.js`.

The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as
[API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your
feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the
[Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme)
from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more
details.

---

## File: examples/nextjs-app/README.md

This is a [Next.js](https://nextjs.org/) project bootstrapped with
[`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).

## Getting Started

First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the
file.

This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to
automatically optimize and load Inter, a custom Google Font.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your
feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the
[Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme)
from the creators of Next.js.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more
details.