Skip to content

Commit

Permalink
Fix Node 14 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Sep 20, 2022
1 parent ea98a34 commit c0e5241
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 113 deletions.
118 changes: 32 additions & 86 deletions examples/bun/__integration-tests__/bun.spec.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
import { spawn } from 'child_process'
import puppeteer from 'puppeteer'

let browser: puppeteer.Browser
let page: puppeteer.Page
let bunProcess: ReturnType<typeof spawn>

const timings = {
waitForSelector: 999,
waitForResponse: 1999,
}

jest.setTimeout(30000)

let toSkip = true
import { getIntrospectionQuery } from 'graphql'

describe('Bun integration', () => {
let bunProcess: ReturnType<typeof spawn>
let serverUrl: string

beforeAll(async () => {
if (process.versions.node.startsWith('18')) {
toSkip = false
return
}
// Start Bun
bunProcess = spawn('yarn', ['workspace', 'example-bun', 'start'])

Expand All @@ -37,83 +22,44 @@ describe('Bun integration', () => {
const chunkString = chunk.toString('utf-8')
console.log(chunk.toString('utf-8'))
if (chunkString.includes('Server is running on')) {
setTimeout(() => {
resolve(chunkString.split('Server is running on ')[1])
}, 5000)
resolve(chunkString.split('Server is running on ')[1])
}
})
})

// Launch puppeteer
browser = await puppeteer.launch({
// If you wanna run tests with open browser
// set your PUPPETEER_HEADLESS env to "false"
headless: process.env.PUPPETEER_HEADLESS !== 'false',
args: ['--incognito'],
})
})

beforeEach(async () => {
if (toSkip) {
return
}
if (page !== undefined) {
await page.close()
}
const context = await browser.createIncognitoBrowserContext()
page = await context.newPage()
})

afterAll(async () => {
if (toSkip) {
return
}
await browser.close()
afterAll(() => {
bunProcess.kill()
})

it('go to GraphiQL page', async () => {
if (toSkip) {
return
}
// Go the the right route
const body = await page.goto(
`${serverUrl}?query=query+Hello+%7B%0A%09greetings%0A%7D`,
)

let strIntro = ''
try {
// A-1/ Wait for the introspection query result getting our type "greetings"
const resIntro = await page.waitForResponse(
(res) => res.url().endsWith('/graphql'),
{
timeout: timings.waitForResponse,
},
)
const jsonIntro = await resIntro.json()
strIntro = JSON.stringify(jsonIntro, null, 0)
} catch (error) {
// We had an issue grabbing the introspection query result!
// let's see what is in the html with the finafinally
} finally {
const bodyContent = await body?.text()
// B/ Check that GraphiQL is showing
expect(bodyContent).toContain(`Yoga GraphiQL`)
}

// A-2/ Finish the test after the body check
expect(strIntro).toContain(`"name":"greetings"`)
it('shows GraphiQL', async () => {
const response = await fetch(serverUrl, {
method: 'GET',
headers: {
Accept: 'text/html',
},
})
expect(response.status).toEqual(200)
expect(response.headers.get('content-type')).toEqual('text/html')
const htmlContents = await response.text()
expect(htmlContents).toContain('Yoga GraphiQL')
})

// C/ Tigger the default request and wait for the response
const [res] = await Promise.all([
page.waitForResponse((res) => res.url().endsWith('/graphql'), {
timeout: timings.waitForResponse,
it('accepts a query', async () => {
const response = await fetch(serverUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
query: `{ greetings }`,
}),
page.click(`button[class="execute-button"]`),
])

const json = await res.json()
const str = JSON.stringify(json, null, 0)
expect(str).toContain(`{"data":{"greetings":"Hello Bun!"}}`)
})
const result = await response.json()
expect(result).toEqual({
data: {
greetings: 'Hello Bun!',
},
})
})
})
2 changes: 1 addition & 1 deletion examples/error-handling/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"dependencies": {
"graphql-yoga": "2.13.11",
"@whatwg-node/fetch": "0.4.3",
"@whatwg-node/fetch": "0.4.4",
"graphql": "^16.1.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/event-target/redis-event-target/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"author": "Laurin Quast <laurinquast@googlemail.com>",
"license": "MIT",
"dependencies": {
"@whatwg-node/events": "0.0.1",
"@whatwg-node/events": "0.0.2",
"@graphql-yoga/typed-event-target": "^0.1.1"
},
"peerDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/graphql-yoga/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
"@graphql-tools/schema": "^9.0.0",
"@graphql-tools/utils": "^8.8.0",
"@graphql-yoga/subscription": "^2.2.2",
"@whatwg-node/fetch": "0.4.3",
"@whatwg-node/server": "0.4.4",
"@whatwg-node/fetch": "0.4.4",
"@whatwg-node/server": "0.4.5",
"dset": "^3.1.1",
"graphql-config": "^4.1.0",
"tslib": "^2.3.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/apollo-inline-trace/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"graphql-yoga": "^2.13.11"
},
"dependencies": {
"@whatwg-node/fetch": "0.4.3",
"@whatwg-node/fetch": "0.4.4",
"apollo-reporting-protobuf": "^3.3.2"
}
}
2 changes: 1 addition & 1 deletion packages/plugins/apq/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"access": "public"
},
"dependencies": {
"@whatwg-node/fetch": "0.4.3",
"@whatwg-node/fetch": "0.4.4",
"tiny-lru": "^8.0.2"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/subscription/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
},
"dependencies": {
"@graphql-yoga/typed-event-target": "^0.1.1",
"@whatwg-node/events": "0.0.1",
"@whatwg-node/events": "0.0.2",
"@repeaterjs/repeater": "^3.0.4",
"tslib": "^2.3.1"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/subscription/src/createPubSub.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Redis from 'ioredis-mock'
import { createRedisEventTarget } from '@graphql-yoga/redis-event-target'
import { createPubSub } from './createPubSub.js'
import { EventTarget } from '@whatwg-node/fetch'
import { EventTarget } from '@whatwg-node/events'

async function collectAsyncIterableValues<TType>(
asyncIterable: AsyncIterable<TType>,
Expand Down
32 changes: 13 additions & 19 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5724,32 +5724,31 @@
"@webassemblyjs/ast" "1.11.1"
"@xtuc/long" "4.2.2"

"@whatwg-node/events@0.0.1":
version "0.0.1"
resolved "https://registry.yarnpkg.com/@whatwg-node/events/-/events-0.0.1.tgz#bb64b0060fcb413386cdbf4754ccaf8b88f47918"
integrity sha512-ly90EZM/EcFYtCj3dxfZsYsjJ0a3gxc60Dvp1Ix71NT1p8s7yURAPMM/Asf777fEl7E5iz1NPo1PilHV1TbqVQ==
"@whatwg-node/events@0.0.2":
version "0.0.2"
resolved "https://registry.yarnpkg.com/@whatwg-node/events/-/events-0.0.2.tgz#7b7107268d2982fc7b7aff5ee6803c64018f84dd"
integrity sha512-WKj/lI4QjnLuPrim0cfO7i+HsDSXHxNv1y0CrJhdntuO3hxWZmnXCwNDnwOvry11OjRin6cgWNF+j/9Pn8TN4w==

"@whatwg-node/fetch@0.4.3", "@whatwg-node/fetch@^0.4.0":
version "0.4.3"
resolved "https://registry.yarnpkg.com/@whatwg-node/fetch/-/fetch-0.4.3.tgz#6c95c039f0912bbcb1af8e5c496104bbeab242d2"
integrity sha512-+NzflVRaWl48Jdjq7FOxkmb8wLpSWtk6XKAEMfr/yDOqJS7HWxA+Rc5rTVqh2IRi6QZJyKGoaGKjOAqrGq07nA==
"@whatwg-node/fetch@0.4.4", "@whatwg-node/fetch@^0.4.0":
version "0.4.4"
resolved "https://registry.yarnpkg.com/@whatwg-node/fetch/-/fetch-0.4.4.tgz#9f6502177453d48b76d31f33d32dcd60afb9eb54"
integrity sha512-/c2u1blMAXHVXneZjVLyE0AwdRuuFpv2P3ghNz2QtpHed+25WdSkTi7XxICwuaRsl/mMgundCzSy1352rZgWPg==
dependencies:
"@peculiar/webcrypto" "^1.4.0"
abort-controller "^3.0.0"
busboy "^1.6.0"
event-target-polyfill "^0.0.3"
form-data-encoder "^1.7.1"
formdata-node "^4.3.1"
node-fetch "^2.6.7"
undici "^5.8.0"
web-streams-polyfill "^3.2.0"

"@whatwg-node/server@0.4.4":
version "0.4.4"
resolved "https://registry.yarnpkg.com/@whatwg-node/server/-/server-0.4.4.tgz#d773e18e44855c0f23623e1b64afee813eaf3212"
integrity sha512-Ka1NuF2TKKNV4XIt/PAaprYplTWJwCyPThrA9U9m2anDPF+o7vzQWI+dHlTfxdbHMfqQuSu5DdcVONYGsG1Txg==
"@whatwg-node/server@0.4.5":
version "0.4.5"
resolved "https://registry.yarnpkg.com/@whatwg-node/server/-/server-0.4.5.tgz#adbd34134a3cfd7815aef7359c95b65270252eda"
integrity sha512-3wwIFZOuCXBKk08+S12xHtky3c8LLR6V6fKQMZqj6tKCawaUistuXzZtTAKyOg8NWglVGqAAng5vwcKa8j4hcQ==
dependencies:
"@whatwg-node/fetch" "^0.4.0"
"@whatwg-node/fetch" "0.4.4"
tslib "^2.3.1"

"@wry/context@^0.6.0":
Expand Down Expand Up @@ -10091,11 +10090,6 @@ etag@^1.8.1, etag@~1.8.1:
resolved "https://registry.yarnpkg.com/etag/-/etag-1.8.1.tgz#41ae2eeb65efa62268aebfea83ac7d79299b0887"
integrity sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=

event-target-polyfill@^0.0.3:
version "0.0.3"
resolved "https://registry.yarnpkg.com/event-target-polyfill/-/event-target-polyfill-0.0.3.tgz#ed373295f3b257774b5d75afb2599331d9f3406c"
integrity sha512-ZMc6UuvmbinrCk4RzGyVmRyIsAyxMRlp4CqSrcQRO8Dy0A9ldbiRy5kdtBj4OtP7EClGdqGfIqo9JmOClMsGLQ==

event-target-shim@^5.0.0:
version "5.0.1"
resolved "https://registry.yarnpkg.com/event-target-shim/-/event-target-shim-5.0.1.tgz#5d4d3ebdf9583d63a5333ce2deb7480ab2b05789"
Expand Down

0 comments on commit c0e5241

Please sign in to comment.