MCPcopy
hub / github.com/dosco/graphjin / handleFederationQuery

Method handleFederationQuery

core/federation.go:290–314  ·  view source on GitHub ↗

handleFederationQuery checks if the request is a federation built-in (`_service` or `_entities`) and produces a JSON response. Returns handled=false when the query is a regular GraphQL document and should flow through the normal pipeline. Detection is intentionally a substring scan over the raw que

(r GraphqlReq)

Source from the content-addressed store, hash-verified

288// literal "_service" or "_entities" inside a string variable, which is
289// vanishingly rare and acceptable for an opt-in mode.
290func (gj *graphjinEngine) handleFederationQuery(r GraphqlReq) (handled bool, data []byte, err error) {
291 q := r.query
292 if len(q) == 0 {
293 return false, nil, nil
294 }
295 hasService := bytesContainsToken(q, []byte("_service"))
296 hasEntities := bytesContainsToken(q, []byte("_entities"))
297 if !hasService && !hasEntities {
298 return false, nil, nil
299 }
300
301 if hasEntities {
302 return true, nil, errFederationEntitiesNotImplemented
303 }
304
305 sdl, err := gj.getFederationSDL()
306 if err != nil {
307 return true, nil, err
308 }
309 resp, err := jsonMarshalServiceSDL(sdl)
310 if err != nil {
311 return true, nil, err
312 }
313 return true, resp, nil
314}
315
316// getFederationSDL returns the cached SDL, building it on first use.
317func (gj *graphjinEngine) getFederationSDL() (string, error) {

Calls 3

getFederationSDLMethod · 0.95
bytesContainsTokenFunction · 0.85
jsonMarshalServiceSDLFunction · 0.85