@@ -4,7 +4,7 @@ import * as Effect from "effect/Effect";
44import * as Layer from "effect/Layer" ;
55import * as Redacted from "effect/Redacted" ;
66import * as Stream from "effect/Stream" ;
7- import { HttpClient , HttpClientError , HttpClientRequest } from "effect/http" ;
7+ import { HttpClient , HttpClientError } from "effect/http" ;
88import * as Headers from "effect/http/Headers" ;
99import { GraphQLClientError , GraphQLMiddleware , GraphQLProtocol } from "effect/graphql" ;
1010import { SourceControlProviderKind } from "@t3tools/contracts" ;
@@ -27,15 +27,6 @@ export class GitHubGraphQlTarget extends Context.Service<
2727 }
2828> ( ) ( "@t3tools/source-control-github/server/gitHubGraphQlClient/GitHubGraphQlTarget" ) { }
2929
30- /**
31- * The GraphQL endpoint the request in flight is sent to. `GitHubGraphQlAuth` sets it for `next`,
32- * because `GraphQLProtocol.layerHttp` takes one URL and one client serves every GitHub host.
33- */
34- const GraphQlEndpoint = Context . Reference < string | null > (
35- "@t3tools/source-control-github/server/gitHubGraphQlClient/GraphQlEndpoint" ,
36- { defaultValue : ( ) => null } ,
37- ) ;
38-
3930/**
4031 * GitHub's auth and rate limits around a generated GraphQL call: the host's token, the quota
4132 * reserve and the host-wide pause before it is sent, and what GitHub's answer says about them after.
@@ -88,7 +79,6 @@ export class GitHubGraphQlAuth extends GraphQLMiddleware.Service<
8879 authorization : `Bearer ${ Redacted . value ( token ) } ` ,
8980 } ) ,
9081 } ) . pipe (
91- Effect . provideService ( GraphQlEndpoint , GitHubApi . gitHubApiUrls ( host ) . graphql ) ,
9282 Effect . timeout ( GitHubApi . DEFAULT_TIMEOUT ) ,
9383 Effect . catchTags ( {
9484 TimeoutError : ( cause ) =>
@@ -198,26 +188,23 @@ export class GitHubGraphQlAuth extends GraphQLMiddleware.Service<
198188}
199189
200190/**
201- * The HTTP transport, sending each request to the endpoint `GitHubGraphQlAuth` chose for its host.
202- * The middleware's span is the request's: the client's own would add `url.full`, which can carry
203- * SHAs and branch names, so it is off, as for REST.
191+ * The HTTP transport, sending each request to its target host's endpoint. Resolvers batch by this
192+ * URL, so lookups for different hosts never share a request. `GitHubGraphQlAuth` requires the
193+ * target, so every call has one. The middleware's span is the request's: the client's own would add
194+ * `url.full`, which can carry SHAs and branch names, so it is off, as for REST.
204195 */
205- const layerProtocol = GraphQLProtocol . layerHttp ( { url : "https://api.github.com/graphql" } ) . pipe (
196+ const layerProtocol = GraphQLProtocol . layerHttp ( {
197+ url : ( { context } ) =>
198+ GitHubApi . gitHubApiUrls ( Context . getUnsafe ( context , GitHubGraphQlTarget ) . host ) . graphql ,
199+ } ) . pipe (
206200 Layer . provide (
207201 Layer . effect (
208202 HttpClient . HttpClient ,
209203 Effect . gen ( function * ( ) {
210204 const client = yield * HttpClient . HttpClient ;
211- return client . pipe (
212- HttpClient . mapRequestEffect ( ( request ) =>
213- Effect . gen ( function * ( ) {
214- const endpoint = yield * GraphQlEndpoint ;
215- return endpoint === null ? request : HttpClientRequest . setUrl ( request , endpoint ) ;
216- } ) ,
217- ) ,
218- HttpClient . transformResponse (
219- Effect . provideService ( HttpClient . TracerDisabledWhen , ( ) => true ) ,
220- ) ,
205+ return HttpClient . transformResponse (
206+ client ,
207+ Effect . provideService ( HttpClient . TracerDisabledWhen , ( ) => true ) ,
221208 ) ;
222209 } ) ,
223210 ) ,
@@ -231,12 +218,12 @@ const layerProtocol = GraphQLProtocol.layerHttp({ url: "https://api.github.com/g
231218export const layer = Layer . merge ( GitHubGraphQlAuth . layer , layerProtocol ) ;
232219
233220/**
234- * What decides which lookups may share one batched request: the host, and the credential and
235- * rate-limit scope it will be sent under. Read from the context the lookup was made in.
221+ * What decides which lookups to one host may share a batched request: the credential and
222+ * rate-limit scope it will be sent under. Read from the context the lookup was made in. Resolvers
223+ * already keep hosts apart, since they batch by the transport's URL too.
236224 */
237225export const batchKey = ( context : Context . Context < GitHubGraphQlTarget > ) =>
238226 JSON . stringify ( [
239- Context . get ( context , GitHubGraphQlTarget ) . host . toLowerCase ( ) ,
240227 Context . getOrElse ( context , GitHubApi . PinnedGitHubCredential , ( ) => null )
241228 ?. credentialFingerprint ?? null ,
242229 Context . getOrElse ( context , SourceControlRateLimit . CredentialScope , ( ) => "" ) ,
0 commit comments