TestBuildChildGraphQLQuery tests construction of GraphQL sub-queries for cross-database child table fetching.
(t *testing.T)
| 606 | // TestBuildChildGraphQLQuery tests construction of GraphQL sub-queries |
| 607 | // for cross-database child table fetching. |
| 608 | func TestBuildChildGraphQLQuery(t *testing.T) { |
| 609 | tests := []struct { |
| 610 | name string |
| 611 | sel *qcode.Select |
| 612 | selects []qcode.Select |
| 613 | fkCol sdata.DBColumn |
| 614 | parentID []byte |
| 615 | want string |
| 616 | }{ |
| 617 | { |
| 618 | name: "simple numeric parent ID", |
| 619 | sel: &qcode.Select{ |
| 620 | Table: "orders", |
| 621 | Fields: []qcode.Field{ |
| 622 | {FieldName: "id"}, |
| 623 | {FieldName: "total"}, |
| 624 | }, |
| 625 | }, |
| 626 | selects: []qcode.Select{}, |
| 627 | fkCol: sdata.DBColumn{Name: "user_id", Type: "bigint"}, |
| 628 | parentID: []byte("42"), |
| 629 | want: "query { orders(where: {user_id: {eq: 42}}) { id total } }", |
| 630 | }, |
| 631 | { |
| 632 | name: "string parent ID (quoted)", |
| 633 | sel: &qcode.Select{ |
| 634 | Table: "orders", |
| 635 | Fields: []qcode.Field{ |
| 636 | {FieldName: "id"}, |
| 637 | {FieldName: "total"}, |
| 638 | }, |
| 639 | }, |
| 640 | selects: []qcode.Select{}, |
| 641 | fkCol: sdata.DBColumn{Name: "user_id", Type: "bigint"}, |
| 642 | parentID: []byte(`"abc"`), |
| 643 | want: `query { orders(where: {user_id: {eq: "abc"}}) { id total } }`, |
| 644 | }, |
| 645 | { |
| 646 | name: "with nested children", |
| 647 | sel: &qcode.Select{ |
| 648 | Field: qcode.Field{ID: 0}, |
| 649 | Table: "orders", |
| 650 | Fields: []qcode.Field{ |
| 651 | {FieldName: "id"}, |
| 652 | {FieldName: "total"}, |
| 653 | }, |
| 654 | Children: []int32{1}, |
| 655 | }, |
| 656 | selects: []qcode.Select{ |
| 657 | {}, // placeholder for index 0 (the parent sel itself) |
| 658 | { |
| 659 | Field: qcode.Field{ |
| 660 | FieldName: "items", |
| 661 | SkipRender: qcode.SkipTypeNone, |
| 662 | }, |
| 663 | Table: "items", |
| 664 | Fields: []qcode.Field{ |
| 665 | {FieldName: "name"}, |
nothing calls this directly
no test coverage detected