TestHandleFederationQuery_Service verifies the runtime path that makes GraphJin a valid Apollo subgraph: a `_service { sdl }` query must be intercepted before the regular compile pipeline and answered with the federation-flavoured SDL wrapped in the expected JSON shape.
(t *testing.T)
| 40 | // must be intercepted before the regular compile pipeline and answered |
| 41 | // with the federation-flavoured SDL wrapped in the expected JSON shape. |
| 42 | func TestHandleFederationQuery_Service(t *testing.T) { |
| 43 | gj := fedTestEngine(t) |
| 44 | |
| 45 | handled, data, err := gj.handleFederationQuery(GraphqlReq{ |
| 46 | query: []byte(`query { _service { sdl } }`), |
| 47 | }) |
| 48 | if !handled { |
| 49 | t.Fatalf("expected handled=true for _service query") |
| 50 | } |
| 51 | if err != nil { |
| 52 | t.Fatalf("unexpected err: %v", err) |
| 53 | } |
| 54 | |
| 55 | var resp struct { |
| 56 | Service struct { |
| 57 | SDL string `json:"sdl"` |
| 58 | } `json:"_service"` |
| 59 | } |
| 60 | if err := json.Unmarshal(data, &resp); err != nil { |
| 61 | t.Fatalf("response is not the _service envelope: %v\n%s", err, data) |
| 62 | } |
| 63 | if resp.Service.SDL == "" { |
| 64 | t.Fatalf("expected non-empty SDL, got %s", data) |
| 65 | } |
| 66 | for _, want := range []string{ |
| 67 | "@link(url:", |
| 68 | "@key(fields:", |
| 69 | "_Service", |
| 70 | "_entities", |
| 71 | } { |
| 72 | if !strings.Contains(resp.Service.SDL, want) { |
| 73 | t.Errorf("SDL missing %q\n----\n%s\n----", want, resp.Service.SDL) |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | // TestHandleFederationQuery_Entities verifies that `_entities` queries |
| 79 | // return the documented "not yet implemented" error rather than silently |
nothing calls this directly
no test coverage detected