Fix createServicesFetcher handle null service url (#563)

This commit is contained in:
Pablo Sáez 2022-10-31 01:32:31 -07:00 committed by GitHub
parent c47df8338a
commit d58a470916
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 3 deletions

View file

@ -0,0 +1,5 @@
---
'@graphql-hive/client': minor
---
Fix createServicesFetcher handling null service url

View file

@ -4,7 +4,7 @@ import type { SchemaFetcherOptions, ServicesFetcherOptions } from './internal/ty
interface Schema {
sdl: string;
url: string;
url: string | null;
name: string;
}
@ -62,7 +62,11 @@ export function createSchemaFetcher({ endpoint, key }: SchemaFetcherOptions) {
return function schemaFetcher() {
return fetcher().then(schema => ({
id: createHash('sha256').update(schema.sdl).update(schema.url).update(schema.name).digest('base64'),
id: createHash('sha256')
.update(schema.sdl)
.update(schema.url || '')
.update(schema.name)
.digest('base64'),
...schema,
}));
};
@ -74,7 +78,11 @@ export function createServicesFetcher({ endpoint, key }: ServicesFetcherOptions)
return function schemaFetcher() {
return fetcher().then(services =>
services.map(service => ({
id: createHash('sha256').update(service.sdl).update(service.url).update(service.name).digest('base64'),
id: createHash('sha256')
.update(service.sdl)
.update(service.url || '')
.update(service.name)
.digest('base64'),
...service,
}))
);