-
Notifications
You must be signed in to change notification settings - Fork 580
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bump whatwg-node to fix HTTP/2 stream issue (#3808)
* Bump whatwg-node to fix HTTP/2 stream issue * chore(dependencies): updated changesets for modified dependencies * Fix lint --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
9bd8c3c
commit fbf328c
Showing
4 changed files
with
207 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"graphql-yoga": patch | ||
--- | ||
dependencies updates: | ||
- Updated dependency [`@whatwg-node/fetch@^0.10.5` ↗︎](https://www.npmjs.com/package/@whatwg-node/fetch/v/0.10.5) (from `^0.10.1`, in `dependencies`) | ||
- Updated dependency [`@whatwg-node/server@^0.9.69` ↗︎](https://www.npmjs.com/package/@whatwg-node/server/v/0.9.69) (from `^0.9.64`, in `dependencies`) |
107 changes: 107 additions & 0 deletions
107
packages/graphql-yoga/__integration-tests__/http2.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import { | ||
ClientHttp2Session, | ||
connect, | ||
constants, | ||
createSecureServer, | ||
Http2SecureServer, | ||
} from 'node:http2'; | ||
import { AddressInfo } from 'node:net'; | ||
import { createSchema, createYoga } from 'graphql-yoga'; | ||
import type { CertificateCreationResult } from 'pem'; | ||
|
||
describe('HTTP2', () => { | ||
let client: ClientHttp2Session; | ||
let server: Http2SecureServer; | ||
let keys: CertificateCreationResult; | ||
beforeAll(async () => { | ||
const { createCertificate } = await import('pem'); | ||
keys = await new Promise<CertificateCreationResult>((resolve, reject) => { | ||
createCertificate( | ||
{ | ||
selfSigned: true, | ||
days: 1, | ||
}, | ||
(err, result) => (err ? reject(err) : resolve(result)), | ||
); | ||
}); | ||
const yoga = createYoga({ | ||
schema: createSchema({ | ||
typeDefs: /* GraphQL */ ` | ||
type Query { | ||
hello: String! | ||
} | ||
`, | ||
resolvers: { | ||
Query: { | ||
hello: () => 'world', | ||
}, | ||
}, | ||
}), | ||
}); | ||
|
||
// Create a secure HTTP/2 server | ||
server = createSecureServer( | ||
{ | ||
allowHTTP1: false, | ||
key: keys.serviceKey, | ||
cert: keys.certificate, | ||
}, | ||
yoga, | ||
); | ||
|
||
await new Promise<void>(resolve => server.listen(0, resolve)); | ||
|
||
const serverAddress = server.address() as AddressInfo; | ||
client = await new Promise<ClientHttp2Session>((resolve, reject) => { | ||
const session = connect( | ||
`https://localhost:${serverAddress.port}`, | ||
{ | ||
ca: keys.certificate, | ||
}, | ||
() => { | ||
resolve(session); | ||
}, | ||
); | ||
session.on('error', reject); | ||
}); | ||
}); | ||
afterAll(async () => { | ||
if (client) { | ||
await new Promise<void>(resolve => client.close(resolve)); | ||
} | ||
if (server) { | ||
await new Promise<void>((resolve, reject) => | ||
server.close(err => (err ? reject(err) : resolve())), | ||
); | ||
} | ||
}); | ||
it('works', done => { | ||
const req = client.request({ | ||
[constants.HTTP2_HEADER_METHOD]: 'POST', | ||
[constants.HTTP2_HEADER_PATH]: '/graphql', | ||
[constants.HTTP2_HEADER_CONTENT_TYPE]: 'application/json', | ||
}); | ||
let data: string = ''; | ||
req.on('response', headers => { | ||
expect(headers[':status']).toBe(200); | ||
}); | ||
req.setEncoding('utf8'); | ||
req.on('data', chunk => { | ||
data += Buffer.from(chunk).toString('utf-8'); | ||
}); | ||
req.on('end', () => { | ||
expect(JSON.parse(data)).toEqual({ data: { hello: 'world' } }); | ||
done(); | ||
}); | ||
req.write( | ||
JSON.stringify({ | ||
query: /* GraphQL */ ` | ||
query { | ||
hello | ||
} | ||
`, | ||
}), | ||
); | ||
req.end(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.