Example_queryMixedRootDBPlusOpenAPI exercises a query with one real-table root (users) and one top-level OpenAPI remote root (audit_logs) in the same GraphQL document. The all-remote shortcut must not fire; psql skips the remote root; gstate injects a marker for it; execRemoteJoin then resolves the
()
| 140 | // must not fire; psql skips the remote root; gstate injects a marker |
| 141 | // for it; execRemoteJoin then resolves the upstream call. |
| 142 | func Example_queryMixedRootDBPlusOpenAPI() { |
| 143 | mux := http.NewServeMux() |
| 144 | mux.HandleFunc("/audit-logs", func(w http.ResponseWriter, r *http.Request) { |
| 145 | actor := r.URL.Query().Get("actorId") |
| 146 | w.Header().Set("Content-Type", "application/json") |
| 147 | fmt.Fprintf(w, `{"data":[{"id":"a1","action":"action by %s"}]}`, actor) //nolint:errcheck |
| 148 | }) |
| 149 | listener, err := net.Listen("tcp", "localhost:0") |
| 150 | if err != nil { |
| 151 | panic(err) |
| 152 | } |
| 153 | port := listener.Addr().(*net.TCPAddr).Port |
| 154 | server := &http.Server{Handler: mux} |
| 155 | go func() { log.Fatal(server.Serve(listener)) }() //nolint:gosec |
| 156 | for i := 0; i < 100; i++ { |
| 157 | resp, err := http.Get(fmt.Sprintf("http://localhost:%d/audit-logs?actorId=ping", port)) |
| 158 | if err == nil { |
| 159 | resp.Body.Close() //nolint:errcheck |
| 160 | break |
| 161 | } |
| 162 | time.Sleep(50 * time.Millisecond) |
| 163 | } |
| 164 | |
| 165 | specsDir, err := os.MkdirTemp("", "graphjin-openapi-mixed-*") |
| 166 | if err != nil { |
| 167 | panic(err) |
| 168 | } |
| 169 | defer os.RemoveAll(specsDir) //nolint:errcheck |
| 170 | |
| 171 | specYAML := fmt.Sprintf(` |
| 172 | openapi: 3.0.0 |
| 173 | info: { title: Audit, version: '1.0' } |
| 174 | servers: |
| 175 | - url: http://localhost:%d |
| 176 | paths: |
| 177 | /audit-logs: |
| 178 | get: |
| 179 | operationId: listAuditLogs |
| 180 | parameters: |
| 181 | - { name: actorId, in: query, required: true, schema: { type: string } } |
| 182 | responses: |
| 183 | '200': |
| 184 | description: ok |
| 185 | content: |
| 186 | application/json: |
| 187 | schema: |
| 188 | type: object |
| 189 | properties: |
| 190 | data: |
| 191 | type: array |
| 192 | items: |
| 193 | type: object |
| 194 | properties: |
| 195 | id: { type: string } |
| 196 | action: { type: string } |
| 197 | `, port) |
| 198 | if err := os.WriteFile(filepath.Join(specsDir, "audit.yaml"), []byte(specYAML), 0o644); err != nil { |
| 199 | panic(err) |