Skip to content

Commit 8863ac0

Browse files
saihajenisdenjo
andauthored
test: integration for netlify-edge (#1815)
* build script for edge function * test: integration tests for netlify edge * remove state file * trigger ci * fix script * Update examples/netlify-edge/__integration-tests__/netlify-edge.spec.ts Co-authored-by: Denis Badurina <[email protected]> Co-authored-by: Denis Badurina <[email protected]>
1 parent fdbcc0e commit 8863ac0

File tree

7 files changed

+68
-20
lines changed

7 files changed

+68
-20
lines changed

examples/netlify-edge/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
netlify/edge-functions/*
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"imports": {
3-
"netlify:edge": "https://edge-bootstrap.netlify.app/v1/index.ts"
4-
}
5-
}
1+
{ "imports": { "netlify:edge": "https://edge.netlify.com/v1/index.ts" } }
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import yoga from '../src'
2+
import { createServer, Server } from 'http'
3+
import { AddressInfo } from 'net'
4+
import { fetch } from '@whatwg-node/fetch'
5+
6+
describe('netlify-edge example integration', () => {
7+
it('should execute query', async () => {
8+
const response = await yoga.fetch(
9+
'http://yoga/graphql?query=query{greetings}',
10+
)
11+
const body = await response.json()
12+
expect(body.errors).toBeUndefined()
13+
expect(body.data).toMatchInlineSnapshot(`
14+
{
15+
"greetings": "This is the \`greetings\` field of the root \`Query\` type",
16+
}
17+
`)
18+
})
19+
})

examples/netlify-edge/build.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const { build } = require('esbuild')
2+
3+
async function main() {
4+
await build({
5+
entryPoints: ['./src/index.ts'],
6+
outfile: 'netlify/edge-functions/graphql.js',
7+
format: 'esm',
8+
minify: false,
9+
bundle: true,
10+
platform: 'browser',
11+
target: 'node14',
12+
})
13+
14+
console.info(`Netlify Edge function build done!`)
15+
}
16+
17+
main().catch((e) => {
18+
console.error(e)
19+
process.exit(1)
20+
})

examples/netlify-edge/netlify/edge-functions/graphql.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

examples/netlify-edge/package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,16 @@
33
"private": true,
44
"version": "0.0.0",
55
"scripts": {
6-
"start": "netlify dev",
6+
"start": "yarn build && netlify dev",
7+
"build": "node ./build.js",
78
"check": "exit 0"
89
},
910
"devDependencies": {
10-
"netlify-cli": "^11.0.0"
11+
"netlify-cli": "^11.0.0",
12+
"esbuild": "0.15.9"
13+
},
14+
"dependencies": {
15+
"graphql-yoga": "3.0.0-next.3",
16+
"graphql": "16.6.0"
1117
}
1218
}

examples/netlify-edge/src/index.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { createYoga, createSchema } from 'graphql-yoga'
2+
3+
const yoga = createYoga({
4+
schema: createSchema({
5+
typeDefs: /* GraphQL */ `
6+
type Query {
7+
greetings: String!
8+
}
9+
`,
10+
resolvers: {
11+
Query: {
12+
greetings: () =>
13+
'This is the `greetings` field of the root `Query` type',
14+
},
15+
},
16+
}),
17+
})
18+
19+
export default yoga

0 commit comments

Comments
 (0)