Example_queryWithOpenAPITopLevel exercises a top-level OpenAPI virtual table — no parent DB row, args coming from the GraphQL field itself. Spec: GET /audit-logs?actorId=… returning {data: [{id, action}, ...]}. Query: { audit_logs(actorId: "u-7") { id action } }. The mock upstream verifies both be
()
| 27 | // remote_join parent-less branch → caller HTTP roundtrip → result-path |
| 28 | // strip → field filter → response. |
| 29 | func Example_queryWithOpenAPITopLevel() { |
| 30 | mux := http.NewServeMux() |
| 31 | mux.HandleFunc("/audit-logs", func(w http.ResponseWriter, r *http.Request) { |
| 32 | if got := r.Header.Get("Authorization"); got != "Bearer top-tok" { |
| 33 | panic(fmt.Sprintf("openapi top-level: missing/wrong auth: %q", got)) |
| 34 | } |
| 35 | actor := r.URL.Query().Get("actorId") |
| 36 | if actor == "" { |
| 37 | panic("openapi top-level: actorId query param missing — args→CallParams broken") |
| 38 | } |
| 39 | w.Header().Set("Content-Type", "application/json") |
| 40 | fmt.Fprintf(w, `{"data":[{"id":"e1","action":"login by %s"},{"id":"e2","action":"export by %s"}]}`, actor, actor) //nolint:errcheck |
| 41 | }) |
| 42 | |
| 43 | server := httptest.NewServer(mux) |
| 44 | defer server.Close() |
| 45 | |
| 46 | specsDir, err := os.MkdirTemp("", "graphjin-openapi-toplevel-*") |
| 47 | if err != nil { |
| 48 | panic(err) |
| 49 | } |
| 50 | defer os.RemoveAll(specsDir) //nolint:errcheck |
| 51 | |
| 52 | specYAML := fmt.Sprintf(` |
| 53 | openapi: 3.0.0 |
| 54 | info: { title: Audit, version: '1.0' } |
| 55 | servers: |
| 56 | - url: %s |
| 57 | paths: |
| 58 | /audit-logs: |
| 59 | get: |
| 60 | operationId: listAuditLogs |
| 61 | parameters: |
| 62 | - { name: actorId, in: query, required: true, schema: { type: string } } |
| 63 | responses: |
| 64 | '200': |
| 65 | description: ok |
| 66 | content: |
| 67 | application/json: |
| 68 | schema: |
| 69 | type: object |
| 70 | properties: |
| 71 | data: |
| 72 | type: array |
| 73 | items: |
| 74 | type: object |
| 75 | properties: |
| 76 | id: { type: string } |
| 77 | action: { type: string } |
| 78 | `, server.URL) |
| 79 | |
| 80 | specPath := filepath.Join(specsDir, "audit.yaml") |
| 81 | if err := os.WriteFile(specPath, []byte(specYAML), 0o644); err != nil { |
| 82 | panic(err) |
| 83 | } |
| 84 | |
| 85 | conf := newConfig(&core.Config{ |
| 86 | DBType: dbType, |