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)
| 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 } } } |
| 246 | func 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 | |
| 268 | func writeGraphQLLiteral(buf *bytes.Buffer, col sdata.DBColumn, val []byte) { |
| 269 | s := strings.TrimSpace(string(val)) |