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

Function Example_multiDBQueryMongoDB

tests/multidb_test.go:107–137  ·  view source on GitHub ↗

Example_multiDBQueryMongoDB tests querying the MongoDB database

()

Source from the content-addressed store, hash-verified

105
106// Example_multiDBQueryMongoDB tests querying the MongoDB database
107func Example_multiDBQueryMongoDB() {
108 // Skip if not in multi-DB mode
109 if !requireMultiDB() {
110 fmt.Println(`{"events":[{"id":1,"type":"page_view"}]}`)
111 return
112 }
113
114 gql := `query {
115 events(limit: 1, order_by: { id: asc }) {
116 id
117 type
118 }
119 }`
120
121 conf := newMultiDBConfig(&core.Config{DisableAllowList: true})
122 conf.Tables = multiDBTables()
123
124 gj, err := newMultiDBGraphJin(conf)
125 if err != nil {
126 fmt.Println(err)
127 return
128 }
129
130 res, err := gj.GraphQL(context.Background(), gql, nil, nil)
131 if err != nil {
132 fmt.Println(err)
133 } else {
134 printJSON(res.Data)
135 }
136 // Output: {"events":[{"id":1,"type":"page_view"}]}
137}
138
139// Example_multiDBCacheKeyIsolation tests that same query name against different databases
140// doesn't share cached SQL (which would be incorrect)

Callers

nothing calls this directly

Calls 6

requireMultiDBFunction · 0.85
newMultiDBConfigFunction · 0.85
multiDBTablesFunction · 0.85
newMultiDBGraphJinFunction · 0.85
printJSONFunction · 0.85
GraphQLMethod · 0.45

Tested by

no test coverage detected