Skip to content

Commit

Permalink
feat: use new services endpoint in SDK and add redirect for legacy en…
Browse files Browse the repository at this point in the history
…dpoint (#862)
  • Loading branch information
n1ru4l authored Dec 22, 2022
1 parent 706b1d6 commit d2aa98a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/dirty-tools-yell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-hive/client': minor
---

Use new CDN endpoint for retrieving the service list
2 changes: 1 addition & 1 deletion packages/libraries/client/src/gateways.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function createFetcher<T>({ endpoint, key }: SchemaFetcherOptions & ServicesFetc
}

return axios
.get(endpoint + '/schema', {
.get(endpoint + '/services', {
headers,
responseType: 'json',
})
Expand Down
20 changes: 10 additions & 10 deletions packages/libraries/client/tests/gateways.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ test('createServicesFetcher without ETag', async () => {
};
const key = 'secret-key';
nock('http://localhost')
.get('/schema')
.get('/services')
.once()
.matchHeader('X-Hive-CDN-Key', key)
.matchHeader('accept', 'application/json')
.reply(() => [200, [schema]])
.get('/schema')
.get('/services')
.once()
.matchHeader('X-Hive-CDN-Key', key)
.matchHeader('accept', 'application/json')
Expand Down Expand Up @@ -65,20 +65,20 @@ test('createServicesFetcher with ETag', async () => {
};
const key = 'secret-key';
nock('http://localhost')
.get('/schema')
.get('/services')
.once()
.matchHeader('X-Hive-CDN-Key', key)
.matchHeader('accept', 'application/json')
.reply(200, [schema], {
ETag: 'first',
})
.get('/schema')
.get('/services')
.once()
.matchHeader('X-Hive-CDN-Key', key)
.matchHeader('accept', 'application/json')
.matchHeader('If-None-Match', 'first')
.reply(304)
.get('/schema')
.get('/services')
.once()
.matchHeader('X-Hive-CDN-Key', key)
.matchHeader('accept', 'application/json')
Expand Down Expand Up @@ -130,12 +130,12 @@ test('createSchemaFetcher without ETag (older versions)', async () => {
};
const key = 'secret-key';
nock('http://localhost')
.get('/schema')
.get('/services')
.once()
.matchHeader('X-Hive-CDN-Key', key)
.matchHeader('accept', 'application/json')
.reply(() => [200, schema])
.get('/schema')
.get('/services')
.once()
.matchHeader('X-Hive-CDN-Key', key)
.matchHeader('accept', 'application/json')
Expand Down Expand Up @@ -174,20 +174,20 @@ test('createSchemaFetcher with ETag', async () => {
};
const key = 'secret-key';
nock('http://localhost')
.get('/schema')
.get('/services')
.once()
.matchHeader('X-Hive-CDN-Key', key)
.matchHeader('accept', 'application/json')
.reply(200, schema, {
ETag: 'first',
})
.get('/schema')
.get('/services')
.once()
.matchHeader('X-Hive-CDN-Key', key)
.matchHeader('accept', 'application/json')
.matchHeader('If-None-Match', 'first')
.reply(304)
.get('/schema')
.get('/services')
.once()
.matchHeader('X-Hive-CDN-Key', key)
.matchHeader('accept', 'application/json')
Expand Down
11 changes: 11 additions & 0 deletions packages/services/cdn-worker/src/artifact-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const ParamsModel = zod.object({
zod.literal('sdl.graphql'),
zod.literal('sdl.graphqls'),
zod.literal('services'),
zod.literal('schema'),
zod.literal('supergraph'),
]),
});
Expand Down Expand Up @@ -72,6 +73,16 @@ export const createArtifactRequestHandler = (deps: ArtifactRequestHandler) => {

const params = parseResult.data;

/** Legacy handling for old client SDK versions. */
if (params.artifactType === 'schema') {
return new Response('Found.', {
status: 301,
headers: {
Location: request.url.replace('/schema', '/services'),
},
});
}

const maybeResponse = await authenticate(request, params.targetId);

if (maybeResponse !== null) {
Expand Down

0 comments on commit d2aa98a

Please sign in to comment.