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

Function buildChildGraphQLQuery

core/database_join.go:246–266  ·  view source on GitHub ↗

buildChildGraphQLQuery constructs a GraphQL query for a cross-database child table. For example: query { orders(where: {user_id: {eq: 42}}) { id total items { name qty } } }

(sel *qcode.Select, selects []qcode.Select, fkCol sdata.DBColumn, parentID []byte)

Source from the content-addressed store, hash-verified

244// buildChildGraphQLQuery constructs a GraphQL query for a cross-database child table.
245// For example: query { orders(where: {user_id: {eq: 42}}) { id total items { name qty } } }
246func buildChildGraphQLQuery(sel *qcode.Select, selects []qcode.Select, fkCol sdata.DBColumn, parentID []byte) []byte {
247 var buf bytes.Buffer
248
249 buf.WriteString("query { ")
250 buf.WriteString(sel.Table)
251
252 // Add WHERE filter on the FK column matching the parent ID
253 buf.WriteString("(where: {")
254 buf.WriteString(fkCol.Name)
255 buf.WriteString(": {eq: ")
256 writeGraphQLLiteral(&buf, fkCol, parentID)
257 buf.WriteString("}})")
258
259 // Write the requested fields
260 buf.WriteString(" { ")
261 writeSelectFields(&buf, sel, selects)
262 buf.WriteString(" }")
263
264 buf.WriteString(" }")
265 return buf.Bytes()
266}
267
268func writeGraphQLLiteral(buf *bytes.Buffer, col sdata.DBColumn, val []byte) {
269 s := strings.TrimSpace(string(val))

Calls 3

writeGraphQLLiteralFunction · 0.85
writeSelectFieldsFunction · 0.85
WriteStringMethod · 0.65