11//! Test mapping of GraphQL schema to a relational schema
2- use diesel :: connection :: SimpleConnection as _ ;
2+ use diesel_async :: SimpleAsyncConnection ;
33use graph:: components:: store:: write:: { EntityModification , RowGroup } ;
44use graph:: data:: store:: scalar;
55use graph:: entity;
@@ -12,7 +12,7 @@ use graph::schema::{EntityKey, EntityType, InputSchema};
1212use graph_store_postgres:: layout_for_tests:: set_account_like;
1313use graph_store_postgres:: layout_for_tests:: LayoutCache ;
1414use graph_store_postgres:: layout_for_tests:: SqlName ;
15- use graph_store_postgres:: { AsyncPgConnection , PgConnection } ;
15+ use graph_store_postgres:: AsyncPgConnection ;
1616use hex_literal:: hex;
1717use lazy_static:: lazy_static;
1818use std:: collections:: BTreeSet ;
@@ -240,14 +240,15 @@ lazy_static! {
240240}
241241
242242/// Removes test data from the database behind the store.
243- fn remove_schema ( conn : & mut PgConnection ) {
243+ async fn remove_schema ( conn : & mut AsyncPgConnection ) {
244244 let query = format ! ( "drop schema if exists {} cascade" , NAMESPACE . as_str( ) ) ;
245245 conn. batch_execute ( & query)
246+ . await
246247 . expect ( "Failed to drop test schema" ) ;
247248}
248249
249250async fn insert_entity_at (
250- conn : & mut PgConnection ,
251+ conn : & mut AsyncPgConnection ,
251252 layout : & Layout ,
252253 entity_type : & EntityType ,
253254 mut entities : Vec < Entity > ,
@@ -280,7 +281,7 @@ async fn insert_entity_at(
280281}
281282
282283async fn insert_entity (
283- conn : & mut PgConnection ,
284+ conn : & mut AsyncPgConnection ,
284285 layout : & Layout ,
285286 entity_type : & EntityType ,
286287 entities : Vec < Entity > ,
@@ -289,7 +290,7 @@ async fn insert_entity(
289290}
290291
291292async fn update_entity_at (
292- conn : & mut PgConnection ,
293+ conn : & mut AsyncPgConnection ,
293294 layout : & Layout ,
294295 entity_type : & EntityType ,
295296 mut entities : Vec < Entity > ,
@@ -320,7 +321,7 @@ async fn update_entity_at(
320321}
321322
322323async fn insert_user_entity (
323- conn : & mut PgConnection ,
324+ conn : & mut AsyncPgConnection ,
324325 layout : & Layout ,
325326 id : & str ,
326327 entity_type : & EntityType ,
@@ -388,7 +389,7 @@ fn make_user(
388389 user
389390}
390391
391- async fn insert_users ( conn : & mut PgConnection , layout : & Layout ) {
392+ async fn insert_users ( conn : & mut AsyncPgConnection , layout : & Layout ) {
392393 insert_user_entity (
393394 conn,
394395 layout,
@@ -443,7 +444,7 @@ async fn insert_users(conn: &mut PgConnection, layout: &Layout) {
443444}
444445
445446async fn update_user_entity (
446- conn : & mut PgConnection ,
447+ conn : & mut AsyncPgConnection ,
447448 layout : & Layout ,
448449 id : & str ,
449450 entity_type : & EntityType ,
@@ -475,7 +476,7 @@ async fn update_user_entity(
475476}
476477
477478async fn insert_pet (
478- conn : & mut PgConnection ,
479+ conn : & mut AsyncPgConnection ,
479480 layout : & Layout ,
480481 entity_type : & EntityType ,
481482 id : & str ,
@@ -491,20 +492,20 @@ async fn insert_pet(
491492 insert_entity_at ( conn, layout, entity_type, vec ! [ pet] , block) . await ;
492493}
493494
494- async fn insert_pets ( conn : & mut PgConnection , layout : & Layout ) {
495+ async fn insert_pets ( conn : & mut AsyncPgConnection , layout : & Layout ) {
495496 insert_pet ( conn, layout, & * DOG_TYPE , "pluto" , "Pluto" , 0 , 0 ) . await ;
496497 insert_pet ( conn, layout, & * CAT_TYPE , "garfield" , "Garfield" , 0 , 1 ) . await ;
497498}
498499
499- async fn create_schema ( conn : & mut PgConnection ) -> Layout {
500+ async fn create_schema ( conn : & mut AsyncPgConnection ) -> Layout {
500501 let schema = InputSchema :: parse_latest ( THINGS_GQL , THINGS_SUBGRAPH_ID . clone ( ) ) . unwrap ( ) ;
501502 let site = make_dummy_site (
502503 THINGS_SUBGRAPH_ID . clone ( ) ,
503504 NAMESPACE . clone ( ) ,
504505 NETWORK_NAME . to_string ( ) ,
505506 ) ;
506507 let query = format ! ( "create schema {}" , NAMESPACE . as_str( ) ) ;
507- conn. batch_execute ( & query) . unwrap ( ) ;
508+ conn. batch_execute ( & query) . await . unwrap ( ) ;
508509
509510 Layout :: create_relational_schema ( conn, Arc :: new ( site) , & schema, BTreeSet :: new ( ) , None )
510511 . await
@@ -552,11 +553,11 @@ macro_rules! assert_entity_eq {
552553/// Test harness for running database integration tests.
553554async fn run_test < F > ( test : F )
554555where
555- F : AsyncFnOnce ( & mut PgConnection , & Layout ) ,
556+ F : AsyncFnOnce ( & mut AsyncPgConnection , & Layout ) ,
556557{
557558 run_test_with_conn ( async |conn| {
558559 // Reset state before starting
559- remove_schema ( conn) ;
560+ remove_schema ( conn) . await ;
560561
561562 // Create the database schema
562563 let layout = create_schema ( conn) . await ;
@@ -836,7 +837,7 @@ async fn enum_arrays() {
836837 . await
837838}
838839
839- async fn count_scalar_entities ( conn : & mut PgConnection , layout : & Layout ) -> usize {
840+ async fn count_scalar_entities ( conn : & mut AsyncPgConnection , layout : & Layout ) -> usize {
840841 let filter = EntityFilter :: Or ( vec ! [
841842 EntityFilter :: Equal ( "bool" . into( ) , true . into( ) ) ,
842843 EntityFilter :: Equal ( "bool" . into( ) , false . into( ) ) ,
@@ -980,7 +981,7 @@ async fn conflicting_entity() {
980981 // `id` is the id of an entity to create, `cat`, `dog`, and `ferret` are
981982 // the names of the types for which to check entity uniqueness
982983 async fn check (
983- conn : & mut PgConnection ,
984+ conn : & mut AsyncPgConnection ,
984985 layout : & Layout ,
985986 id : Value ,
986987 cat : & str ,
@@ -1041,10 +1042,10 @@ async fn conflicting_entity() {
10411042
10421043#[ tokio:: test]
10431044async fn revert_block ( ) {
1044- async fn check_fred ( conn : & mut PgConnection , layout : & Layout ) {
1045+ async fn check_fred ( conn : & mut AsyncPgConnection , layout : & Layout ) {
10451046 let id = "fred" ;
10461047
1047- let set_fred = async |conn : & mut PgConnection , name, block| {
1048+ let set_fred = async |conn : & mut AsyncPgConnection , name, block| {
10481049 let fred = entity ! { layout. input_schema =>
10491050 id: id,
10501051 name: name,
@@ -1057,7 +1058,7 @@ async fn revert_block() {
10571058 }
10581059 } ;
10591060
1060- let assert_fred = async |conn : & mut PgConnection , name : & str | {
1061+ let assert_fred = async |conn : & mut AsyncPgConnection , name : & str | {
10611062 let fred = layout
10621063 . find ( conn, & CAT_TYPE . parse_key ( id) . unwrap ( ) , BLOCK_NUMBER_MAX )
10631064 . await
@@ -1082,8 +1083,8 @@ async fn revert_block() {
10821083 assert_fred ( conn, "one" ) . await ;
10831084 }
10841085
1085- async fn check_marty ( conn : & mut PgConnection , layout : & Layout ) {
1086- let set_marties = async |conn : & mut PgConnection , from, to| {
1086+ async fn check_marty ( conn : & mut AsyncPgConnection , layout : & Layout ) {
1087+ let set_marties = async |conn : & mut AsyncPgConnection , from, to| {
10871088 for block in from..=to {
10881089 let id = format ! ( "marty-{}" , block) ;
10891090 let marty = entity ! { layout. input_schema =>
@@ -1095,7 +1096,7 @@ async fn revert_block() {
10951096 }
10961097 } ;
10971098
1098- let assert_marties = async |conn : & mut PgConnection ,
1099+ let assert_marties = async |conn : & mut AsyncPgConnection ,
10991100 max_block,
11001101 except : Vec < BlockNumber > | {
11011102 let id = DeploymentHash :: new ( "QmXW3qvxV7zXnwRntpj7yoK8HZVtaraZ67uMqaLRvXdxha" ) . unwrap ( ) ;
@@ -1124,7 +1125,7 @@ async fn revert_block() {
11241125 }
11251126 } ;
11261127
1127- let assert_all_marties = async |conn : & mut PgConnection , max_block| {
1128+ let assert_all_marties = async |conn : & mut AsyncPgConnection , max_block| {
11281129 assert_marties ( conn, max_block, vec ! [ ] ) . await
11291130 } ;
11301131
@@ -1152,12 +1153,12 @@ async fn revert_block() {
11521153}
11531154
11541155struct QueryChecker < ' a > {
1155- conn : & ' a mut PgConnection ,
1156+ conn : & ' a mut AsyncPgConnection ,
11561157 layout : & ' a Layout ,
11571158}
11581159
11591160impl < ' a > QueryChecker < ' a > {
1160- async fn new ( conn : & ' a mut PgConnection , layout : & ' a Layout ) -> Self {
1161+ async fn new ( conn : & ' a mut AsyncPgConnection , layout : & ' a Layout ) -> Self {
11611162 insert_users ( conn, layout) . await ;
11621163 update_user_entity (
11631164 conn,
@@ -1912,12 +1913,12 @@ fn ferrets() -> (String, String, String, String) {
19121913}
19131914
19141915struct FilterChecker < ' a > {
1915- conn : & ' a mut PgConnection ,
1916+ conn : & ' a mut AsyncPgConnection ,
19161917 layout : & ' a Layout ,
19171918}
19181919
19191920impl < ' a > FilterChecker < ' a > {
1920- async fn new ( conn : & ' a mut PgConnection , layout : & ' a Layout ) -> Self {
1921+ async fn new ( conn : & ' a mut AsyncPgConnection , layout : & ' a Layout ) -> Self {
19211922 let ( a1, a2, a2b, a3) = ferrets ( ) ;
19221923 insert_pet ( conn, layout, & * FERRET_TYPE , "a1" , & a1, 0 , 0 ) . await ;
19231924 insert_pet ( conn, layout, & * FERRET_TYPE , "a2" , & a2, 0 , 1 ) . await ;
0 commit comments