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

Function TestQueryParentAndChildrenViaArrayColumn

tests/array_test.go:14–68  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

12)
13
14func TestQueryParentAndChildrenViaArrayColumn(t *testing.T) {
15 skipCassandra(t, "array/collection columns are not seeded in the cassandra fixture")
16 skipClickHouse(t, "array/collection columns are not seeded in the fixture")
17 if dbType == "mssql" {
18 t.Skip("skipping test for mssql (array column joins not yet supported)")
19 }
20 if dbType == "snowflake" {
21 t.Skip("snowflake: test assumes Postgres-style insertion order; Snowflake doesn't guarantee order without ORDER BY")
22 }
23 if dbType == "bigquery" {
24 t.Skip("bigquery: array-column relationship joins need UNNEST lowering in the dialect/simulator")
25 }
26
27 gql := `
28 query {
29 products(limit: 2, order_by: { id: asc }) {
30 name
31 price
32 categories(order_by: { id: asc }) {
33 id
34 name
35 }
36 }
37 categories(order_by: { id: asc }) {
38 name
39 products(order_by: { id: asc }) {
40 name
41 }
42 }
43 }`
44
45 conf := newConfig(&core.Config{DBType: dbType, DisableAllowList: true, DefaultLimit: 2})
46 conf.Tables = []core.Table{
47 {
48 Name: "products",
49 Columns: []core.Column{
50 {Name: "category_ids", ForeignKey: "categories.id", Array: true},
51 },
52 },
53 }
54
55 gj, err := core.NewGraphJin(conf, db)
56 if err != nil {
57 t.Fatal(err)
58 }
59 defer gj.Close()
60
61 res, err := gj.GraphQL(context.Background(), gql, nil, nil)
62 if err != nil {
63 t.Error(err)
64 }
65
66 exp := `{"categories":[{"name":"Category 1","products":[{"name":"Product 1"},{"name":"Product 2"}]},{"name":"Category 2","products":[{"name":"Product 1"},{"name":"Product 2"}]}],"products":[{"categories":[{"id":1,"name":"Category 1"},{"id":2,"name":"Category 2"}],"name":"Product 1","price":11.5},{"categories":[{"id":1,"name":"Category 1"},{"id":2,"name":"Category 2"}],"name":"Product 2","price":12.5}]}`
67 assert.Equal(t, exp, stdJSON(res.Data))
68}
69
70func TestInsertIntoTableAndConnectToRelatedTableWithArrayColumn(t *testing.T) {
71 skipCassandra(t, "array/collection columns are not seeded in the cassandra fixture")

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
ErrorMethod · 0.65

Tested by

no test coverage detected