@@ -2,12 +2,14 @@ import { GraphQLError, type DocumentNode } from 'graphql';
22import type { ApolloServerPlugin , HTTPGraphQLRequest } from '@apollo/server' ;
33import {
44 autoDisposeSymbol ,
5+ CDNArtifactFetcherCircuitBreakerConfiguration ,
6+ createCDNArtifactFetcher ,
57 createHive as createHiveClient ,
6- createSupergraphSDLFetcher ,
78 HiveClient ,
89 HivePluginOptions ,
910 isHiveClient ,
10- SupergraphSDLFetcherOptions ,
11+ joinUrl ,
12+ Logger ,
1113} from '@graphql-hive/core' ;
1214import { version } from './version.js' ;
1315
@@ -19,12 +21,53 @@ export {
1921} from '@graphql-hive/core' ;
2022export type { SupergraphSDLFetcherOptions } from '@graphql-hive/core' ;
2123
22- export function createSupergraphManager ( {
23- pollIntervalInMs,
24- ...superGraphFetcherOptions
25- } : { pollIntervalInMs ?: number } & SupergraphSDLFetcherOptions ) {
26- pollIntervalInMs = pollIntervalInMs ?? 30_000 ;
27- const fetchSupergraph = createSupergraphSDLFetcher ( superGraphFetcherOptions ) ;
24+ export function createSupergraphManager ( args : {
25+ /**
26+ * The supergraph poll interval in milliseconds
27+ * Default: 30_000
28+ */
29+ pollIntervalInMs ?: number ;
30+ /**
31+ * The artifact endpoint to poll.
32+ * E.g. `https://cdn.graphql-hive.com/<uuid>/supergraph`
33+ */
34+ endpoint : string ;
35+ /**
36+ * The CDN access key for fetching artifact.
37+ */
38+ key : string ;
39+ logger ?: Logger ;
40+ /** Circuit breaker configuration override. */
41+ circuitBreaker ?: CDNArtifactFetcherCircuitBreakerConfiguration ;
42+ fetchImplementation ?: typeof fetch ;
43+ /**
44+ * Client name override
45+ * Default: `@graphql-hive/apollo`
46+ */
47+ name ?: string ;
48+ /**
49+ * Client version override
50+ * Default: currents package version
51+ */
52+ version ?: string ;
53+ } ) {
54+ const pollIntervalInMs = args . pollIntervalInMs ?? 30_000 ;
55+ const endpoint = args . endpoint . endsWith ( '/supergraph' )
56+ ? args . endpoint
57+ : joinUrl ( args . endpoint , 'supergraph' ) ;
58+
59+ const fetchSupergraph = createCDNArtifactFetcher ( {
60+ endpoint,
61+ accessKey : args . key ,
62+ client : {
63+ name : args . name ?? '@graphql-hive/apollo' ,
64+ version : args . version ?? version ,
65+ } ,
66+ logger : args . logger ,
67+ fetch : args . fetchImplementation ,
68+ circuitBreaker : args . circuitBreaker ,
69+ } ) ;
70+
2871 let timer : ReturnType < typeof setTimeout > | null = null ;
2972
3073 return {
@@ -38,8 +81,8 @@ export function createSupergraphManager({
3881 timer = setTimeout ( async ( ) => {
3982 try {
4083 const result = await fetchSupergraph ( ) ;
41- if ( result . supergraphSdl ) {
42- hooks . update ?.( result . supergraphSdl ) ;
84+ if ( result . contents ) {
85+ hooks . update ?.( result . contents ) ;
4386 }
4487 } catch ( error ) {
4588 console . error (
@@ -53,7 +96,7 @@ export function createSupergraphManager({
5396 poll ( ) ;
5497
5598 return {
56- supergraphSdl : initialResult . supergraphSdl ,
99+ supergraphSdl : initialResult . contents ,
57100 cleanup : async ( ) => {
58101 if ( timer ) {
59102 clearTimeout ( timer ) ;
0 commit comments