-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
105 additions
and
6 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,22 @@ | ||
import { defineConfig } from '@graphql-hive/gateway'; | ||
import { Opts } from '@internal/testing'; | ||
|
||
const opts = Opts(process.argv); | ||
const selfHostingPort = opts.getServicePort('selfHostingHive'); | ||
|
||
export const gatewayConfig = defineConfig({ | ||
reporting: { | ||
type: 'hive', | ||
token: 'secret', | ||
agent: { | ||
maxRetries: 1, | ||
maxSize: 1, | ||
timeout: 200, | ||
}, | ||
selfHosting: { | ||
applicationUrl: `http://localhost:${selfHostingPort}`, | ||
graphqlEndpoint: `http://localhost:${selfHostingPort}/graphql`, | ||
usageEndpoint: `http://localhost:${selfHostingPort}/usage`, | ||
}, | ||
}, | ||
}); |
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,8 @@ | ||
{ | ||
"name": "@e2e/self-hosting-hive", | ||
"private": true, | ||
"dependencies": { | ||
"@graphql-hive/gateway": "workspace:*", | ||
"graphql": "16.9.0" | ||
} | ||
} |
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,24 @@ | ||
import { setTimeout } from 'node:timers/promises'; | ||
import { createExampleSetup, createTenv } from '@internal/e2e'; | ||
import { describe, expect, it } from 'vitest'; | ||
|
||
describe('Self Hosting Hive', () => { | ||
const { gateway, service } = createTenv(__dirname); | ||
const { supergraph, query, result } = createExampleSetup(__dirname); | ||
it('usage', async () => { | ||
const selfHostingHive = await service('selfHostingHive'); | ||
await using gw = await gateway({ | ||
supergraph: await supergraph(), | ||
services: [selfHostingHive], | ||
}); | ||
await expect( | ||
gw.execute({ | ||
query, | ||
}), | ||
).resolves.toEqual(result); | ||
await setTimeout(300); | ||
const incomingData = selfHostingHive.getStd('out'); | ||
// Check if `/usage` endpoint receives the POST request | ||
expect(incomingData).toContain('POST /usage'); | ||
}); | ||
}); |
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,23 @@ | ||
import { createServer } from 'http'; | ||
import { Opts } from '@internal/testing'; | ||
|
||
const opts = Opts(process.argv); | ||
const selfHostingPort = opts.getServicePort('selfHostingHive'); | ||
|
||
// Echo server | ||
|
||
createServer((req, res) => { | ||
process.stdout.write(`${req.method} ${req.url}\n`); | ||
res.writeHead(200, req.headers); | ||
req.on('data', (chunk) => { | ||
process.stdout.write(chunk); | ||
res.write(chunk); | ||
}); | ||
req.on('end', () => { | ||
res.end(); | ||
}); | ||
}).listen(selfHostingPort, () => { | ||
process.stderr.write( | ||
`Echo server listening on http://localhost:${selfHostingPort}\n`, | ||
); | ||
}); |
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
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
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
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