Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect CLI arguments and configuration when both provided #342

Merged
merged 22 commits into from
Dec 19, 2024
Merged
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
7 changes: 7 additions & 0 deletions .changeset/fuzzy-eels-obey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@graphql-hive/gateway': patch
---

Respect both registry token from CLI arguments and the configuration in the \`gateway.config\`

User can provide the token in the CLI arguments, and have some registry configuration in \`gateway.config\`
5 changes: 5 additions & 0 deletions .changeset/sixty-rice-give.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-hive/gateway-runtime': patch
---

`token` doesn't need to be required for Hive reporting in the configuration because it can be provided by the arguments
28 changes: 28 additions & 0 deletions e2e/self-hosting-hive/gateway.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { defineConfig } from '@graphql-hive/gateway';
import { boolEnv, Opts } from '@internal/testing';

const opts = Opts(process.argv);
const selfHostingHost = String(process.env['E2E_GATEWAY_RUNNER']).includes(
'docker',
)
? boolEnv('CI')
? '172.17.0.1'
: 'host.docker.internal'
: 'localhost';
const selfHostingPort = opts.getServicePort('selfHostingHive');

export const gatewayConfig = defineConfig({
reporting: {
type: 'hive',
agent: {
maxRetries: 1,
maxSize: 1,
timeout: 200,
},
selfHosting: {
applicationUrl: `http://${selfHostingHost}:${selfHostingPort}`,
graphqlEndpoint: `http://${selfHostingHost}:${selfHostingPort}/graphql`,
usageEndpoint: `http://${selfHostingHost}:${selfHostingPort}/usage`,
},
},
});
8 changes: 8 additions & 0 deletions e2e/self-hosting-hive/package.json
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"
}
}
27 changes: 27 additions & 0 deletions e2e/self-hosting-hive/self-hosting-hive.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { setTimeout } from 'node:timers/promises';
import { createExampleSetup, createTenv } from '@internal/e2e';
import { describe, expect, it } from 'vitest';

describe('Self Hosting Hive', () => {
const TEST_TOKEN = 'my-token';
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],
args: [`--hive-registry-token=${TEST_TOKEN}`],
});
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');
expect(incomingData).toContain(`"authorization":"Bearer ${TEST_TOKEN}"`);
});
});
27 changes: 27 additions & 0 deletions e2e/self-hosting-hive/services/selfHostingHive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { createServer } from 'http';
import { Opts } from '@internal/testing';

const opts = Opts(process.argv);
const selfHostingPort = opts.getServicePort('selfHostingHive');

// Echo server

createServer((req, res) => {
function echo(msg: string) {
process.stdout.write(msg);
res.write(msg);
}
res.writeHead(200, req.headers);
echo(`${req.method} ${req.url}\n`);
echo(`headers: ${JSON.stringify(req.headers)}\n`);
req.on('data', (chunk) => {
echo(chunk.toString('utf8'));
});
req.once('end', () => {
res.end();
});
}).listen(selfHostingPort, () => {
process.stderr.write(
`Echo server listening on http://localhost:${selfHostingPort}\n`,
);
});
Loading
Loading