Example_multiDBQueryMongoDB tests querying the MongoDB database
()
| 105 | |
| 106 | // Example_multiDBQueryMongoDB tests querying the MongoDB database |
| 107 | func 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) |
nothing calls this directly
no test coverage detected