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

Function TestQueryWithJsonColumn

tests/query_test.go:1609–1656  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1607}
1608
1609func TestQueryWithJsonColumn(t *testing.T) {
1610 skipCassandra(t, "no JSONB/virtual-table support in CQL")
1611 skipClickHouse(t, "JSON virtual-table relationships are not supported")
1612 if dbType == "snowflake" {
1613 t.Skip("snowflake: VARIANT JSON-virtual-table relationship resolution needs shared-code compiler support")
1614 }
1615 skipBigQueryJSONVirtualTablesUnsupported(t)
1616
1617 gql := `query {
1618 users(id: 1) {
1619 id
1620 category_counts(order_by: { category_id: asc }) {
1621 count
1622 category {
1623 name
1624 }
1625 }
1626 }
1627 }`
1628
1629 conf := newConfig(&core.Config{DBType: dbType, DisableAllowList: true})
1630 conf.Tables = []core.Table{
1631 {
1632 Name: "category_counts",
1633 Table: "users",
1634 Type: "json",
1635 Columns: []core.Column{
1636 {Name: "category_id", Type: "int", ForeignKey: "categories.id"},
1637 {Name: "count", Type: "int"},
1638 },
1639 },
1640 }
1641
1642 gj, err := core.NewGraphJin(conf, db)
1643 if err != nil {
1644 t.Fatal(err)
1645 }
1646 defer gj.Close()
1647
1648 res, err := gj.GraphQL(context.Background(), gql, nil, nil)
1649 if err != nil {
1650 t.Fatal(err)
1651 }
1652 exp := `{"users":{"category_counts":[{"category":{"name":"Category 1"},"count":400},{"category":{"name":"Category 2"},"count":600}],"id":1}}`
1653 if stdJSON(res.Data) != exp {
1654 t.Errorf("expected '%s' got '%s'", exp, stdJSON(res.Data))
1655 }
1656}
1657
1658func Example_queryViewByID() {
1659 // Skip for MongoDB: hot_products view not set up

Callers

nothing calls this directly

Calls 7

CloseMethod · 0.95
GraphQLMethod · 0.95
skipCassandraFunction · 0.85
skipClickHouseFunction · 0.85
newConfigFunction · 0.85
stdJSONFunction · 0.85

Tested by

no test coverage detected