Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
**/generated/**
.eslintrc.cjs
e2e/
6 changes: 0 additions & 6 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ module.exports = {
'unicorn/filename-case': 'off',
},
},
{
files: ['e2e/**'],
rules: {
'no-console': 'off',
},
},
{
files: ['packages/graphiql/**', 'packages/render-graphiql/**'],
rules: {
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/deployment-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
'azure-function',
'aws-lambda',
'vercel-function',
'vercel-edge',
]
name: e2e / ${{ matrix.plan }}

Expand Down
7 changes: 7 additions & 0 deletions e2e/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
extends: ['@theguild'],
parserOptions: {
tsconfigRootDir: __dirname,
project: './tsconfig.json',
},
};
1 change: 1 addition & 0 deletions e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ On each PR, this workflow runs, and tried to deploy and test an actual environme
- [x] [AWS Lambda](./tests/aws-lambda.ts)
- [x] [Docker container](./tests/docker.ts)
- [x] [Vercel Function](./tests/vercel.ts)
- [x] [Vercel Edge Function](./tests/vercel-edge.ts)
- [ ] K8s Pod
- [ ] Docker

Expand Down
2 changes: 2 additions & 0 deletions e2e/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import { dockerDeployment } from './tests/docker'
import { DeploymentConfiguration } from './types'
import { env, getCommitId } from './utils'
import { vercelDeployment } from './tests/vercel'
import { vercelEdgeDeployment } from './tests/vercel-edge'

const AVAILABLE_TEST_PLANS = {
'cf-worker': cloudFlareDeployment,
'cf-modules': cfModulesDeployment,
'azure-function': azureFunctionDeployment,
'aws-lambda': awsLambdaDeployment,
'vercel-function': vercelDeployment,
'vercel-edge': vercelEdgeDeployment,
'docker-node-17': dockerDeployment('node:17.8.0-alpine3.14'),
}

Expand Down
3 changes: 2 additions & 1 deletion e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
"@pulumi/aws": "5.34.0",
"@pulumi/docker": "4.1.2",
"@types/node": "18.15.11",
"execa": "^5.1.0",
"typescript": "5.0.3",
"ts-node": "10.9.1"
},
"scripts": {
"start": "ts-node --transpile-only index.ts",
"check": "exit 0"
"check": "tsc --noEmit --pretty"
}
}
57 changes: 57 additions & 0 deletions e2e/tests/vercel-edge.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import * as pulumi from '@pulumi/pulumi'
import {
assertGraphiQL,
assertQuery,
env,
execPromise,
fsPromises,
waitForEndpoint,
} from '../utils'
import { DeploymentConfiguration } from '../types'
import { VercelDeployment } from './vercel'

export const vercelEdgeDeployment: DeploymentConfiguration<{
functionUrl: string
}> = {
prerequisites: async () => {
// Build and bundle the function
console.info('\t\tℹ️ Bundling the Vercel Function....')
await execPromise('pnpm bundle', {
cwd: '../examples/nextjs-edge',
})
},
program: async () => {
const deployment = new VercelDeployment('vercel-edge-function', {
files: [
{
file: '/api/graphql.js',
data: await fsPromises.readFile(
'../examples/nextjs-edge/dist/index.js',
'utf-8',
),
},
],
name: `yoga-e2e-testing`,
functions: {
'api/graphql.js': {
runtime: 'edge',
memory: 256,
maxDuration: 5,
},
},
projectSettings: {
framework: null,
},
})

return {
functionUrl: pulumi.interpolate`https://${deployment.url}/api/graphql`,
}
},
test: async ({ functionUrl }) => {
console.log(`ℹ️ Vercel Function deployed to URL: ${functionUrl.value}`)
await waitForEndpoint(functionUrl.value, 5, 10000)
await assertGraphiQL(functionUrl.value)
await assertQuery(functionUrl.value)
},
}
2 changes: 1 addition & 1 deletion e2e/tests/vercel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type VercelDeploymentInputs = {
[K in keyof VercelProviderInputs]: pulumi.Input<VercelProviderInputs[K]>
}

class VercelProvider implements pulumi.dynamic.ResourceProvider {
export class VercelProvider implements pulumi.dynamic.ResourceProvider {
private baseUrl = 'https://api.vercel.com'
private authToken = env('VERCEL_AUTH_TOKEN')

Expand Down
5 changes: 4 additions & 1 deletion e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
{
"compilerOptions": {
"baseUrl": ".",
"outDir": "dist",
"target": "es2016",
"lib": ["esnext"],
"module": "commonjs",
"moduleResolution": "node",
"declaration": true,
"sourceMap": true,
"resolveJsonModule": true,
"skipLibCheck": true
},
"include": ["./**/*.ts"]
"files": ["index.ts"],
"exclude": ["**/node_modules", "**/dist"]
}
3 changes: 3 additions & 0 deletions examples/nextjs-edge/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
32 changes: 32 additions & 0 deletions examples/nextjs-edge/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*

# local env files
.env.local
.env.development.local
.env.test.local
.env.production.local

# vercel
.vercel
34 changes: 34 additions & 0 deletions examples/nextjs-edge/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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.
5 changes: 5 additions & 0 deletions examples/nextjs-edge/next-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
8 changes: 8 additions & 0 deletions examples/nextjs-edge/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
reactStrictMode: true,
eslint: {
// Warning: This allows production builds to successfully complete even if
// your project has ESLint errors.
ignoreDuringBuilds: true,
},
}
31 changes: 31 additions & 0 deletions examples/nextjs-edge/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "example-nextjs-edge",
"private": true,
"version": "0.13.11",
"scripts": {
"dev": "next dev",
"build": "next build",
"bundle": "node scripts/bundle.js",
"start": "next start",
"lint": "next lint",
"check": "tsc --pretty --noEmit",
"deploy": "vercel deploy -y"
},
"dependencies": {
"graphql-yoga": "3.7.0",
"@types/react": "18.0.28",
"@types/node": "18.15.11",
"graphql": "^16.1.0",
"next": "13.2.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"tslib": "2.5.0"
},
"devDependencies": {
"@types/react": "18.0.28",
"eslint": "8.34.0",
"eslint-config-next": "13.2.0",
"esbuild": "0.17.15",
"typescript": "4.9.5"
}
}
7 changes: 7 additions & 0 deletions examples/nextjs-edge/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import '../styles/globals.css'

function MyApp({ Component, pageProps }) {
return <Component {...pageProps} />
}

export default MyApp
26 changes: 26 additions & 0 deletions examples/nextjs-edge/pages/api/graphql.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { createYoga, createSchema } from 'graphql-yoga'

// Docs: https://vercel.com/docs/concepts/functions/edge-functions

export const config = {
runtime: 'edge',
}

const yoga = createYoga({
graphqlEndpoint: '/api/graphql',
schema: createSchema({
typeDefs: /* GraphQL */ `
type Query {
greetings: String
}
`,
resolvers: {
Query: {
greetings: () =>
'This is the `greetings` field of the root `Query` type',
},
},
}),
})

export default yoga.handleRequest
38 changes: 38 additions & 0 deletions examples/nextjs-edge/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import Head from 'next/head'
import styles from '../styles/Home.module.css'

export default function Home() {
return (
<div className={styles.container}>
<Head>
<title>GraphQL Yoga</title>
<meta name="description" content="Generated by create next app" />
<link rel="icon" href="/favicon.ico" />
</Head>

<main className={styles.main}>
<h1 className={styles.title}>
Welcome to <a href="https://nextjs.org">Next.js!</a>
</h1>

<p className={styles.description}>
Edit the GraphQL Schema
<a href="/api/graphql" target="_blank">
<code className={styles.code}>pages/api/graphql.js</code>
</a>
</p>

<div className={styles.grid}>
<a href="https://nextjs.org/docs" className={styles.card}>
<h2>Learn &rarr;</h2>
<p>Learn about Next.js</p>
</a>
<a href="https://graphql-yoga.vercel.app" className={styles.card}>
<h2>Learn &rarr;</h2>
<p>Learn about GraphQL Yoga</p>
</a>
</div>
</main>
</div>
)
}
Binary file added examples/nextjs-edge/public/favicon.ico
Binary file not shown.
Loading