Skip to content

Commit

Permalink
..
Browse files Browse the repository at this point in the history
  • Loading branch information
ardatan committed Dec 17, 2024
1 parent cc3067d commit 8e74782
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 7 deletions.
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
1 change: 0 additions & 1 deletion e2e/self-hosting-hive/gateway.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const selfHostingPort = opts.getServicePort('selfHostingHive');
export const gatewayConfig = defineConfig({
reporting: {
type: 'hive',
token: 'secret',
agent: {
maxRetries: 1,
maxSize: 1,
Expand Down
3 changes: 3 additions & 0 deletions e2e/self-hosting-hive/self-hosting-hive.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ 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({
Expand All @@ -20,5 +22,6 @@ describe('Self Hosting Hive', () => {
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}"`);
});
});
12 changes: 8 additions & 4 deletions e2e/self-hosting-hive/services/selfHostingHive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ const selfHostingPort = opts.getServicePort('selfHostingHive');
// Echo server

createServer((req, res) => {
process.stdout.write(`${req.method} ${req.url}\n`);
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) => {
process.stdout.write(chunk);
res.write(chunk);
echo(chunk.toString('utf8'));
});
req.on('end', () => {
req.once('end', () => {
res.end();
});
}).listen(selfHostingPort, () => {
Expand Down
1 change: 1 addition & 0 deletions packages/gateway/src/commands/supergraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export const addCommand: AddCommand = (ctx, cli) =>
ctx.log.info(`Configuring Hive registry reporting`);
registryConfig = {
reporting: {
...loadedConfig.reporting,
type: 'hive',
token: hiveRegistryToken,
},
Expand Down
2 changes: 0 additions & 2 deletions packages/runtime/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,6 @@ export interface GatewayHiveCDNOptions {
export interface GatewayHiveReportingOptions
extends Omit<YamlConfig.HivePlugin, 'experimental__persistedDocuments'> {
type: 'hive';
/** GraphQL Hive registry access token. */
token: string;
}

export interface GatewayGraphOSOptions {
Expand Down

0 comments on commit 8e74782

Please sign in to comment.