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

Function Example_queryMixedRootDBPlusOpenAPI

tests/openapi_toplevel_test.go:142–244  ·  view source on GitHub ↗

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

()

Source from the content-addressed store, hash-verified

140// must not fire; psql skips the remote root; gstate injects a marker
141// for it; execRemoteJoin then resolves the upstream call.
142func 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(`
172openapi: 3.0.0
173info: { title: Audit, version: '1.0' }
174servers:
175 - url: http://localhost:%d
176paths:
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)

Callers

nothing calls this directly

Calls 9

CloseMethod · 0.95
GraphQLMethod · 0.95
newConfigFunction · 0.85
printJSONFunction · 0.85
GetMethod · 0.65
QueryMethod · 0.65
SetMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected