mirror of
https://github.com/graphql-hive/console
synced 2026-05-23 09:08:34 +00:00
feat: use new services endpoint in SDK and add redirect for legacy endpoint (#862)
This commit is contained in:
parent
706b1d61c4
commit
d2aa98a574
4 changed files with 27 additions and 11 deletions
5
.changeset/dirty-tools-yell.md
Normal file
5
.changeset/dirty-tools-yell.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@graphql-hive/client': minor
|
||||
---
|
||||
|
||||
Use new CDN endpoint for retrieving the service list
|
||||
|
|
@ -30,7 +30,7 @@ function createFetcher<T>({ endpoint, key }: SchemaFetcherOptions & ServicesFetc
|
|||
}
|
||||
|
||||
return axios
|
||||
.get(endpoint + '/schema', {
|
||||
.get(endpoint + '/services', {
|
||||
headers,
|
||||
responseType: 'json',
|
||||
})
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
|
@ -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')
|
||||
|
|
@ -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')
|
||||
|
|
@ -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')
|
||||
|
|
|
|||
|
|
@ -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'),
|
||||
]),
|
||||
});
|
||||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue