diff --git a/store/postgres/src/relational/dsl.rs b/store/postgres/src/relational/dsl.rs index df2e4afdab9..6812bbb37e9 100644 --- a/store/postgres/src/relational/dsl.rs +++ b/store/postgres/src/relational/dsl.rs @@ -322,7 +322,8 @@ impl<'a> Table<'a> { table: &'b Table<'b>, column: &'b RelColumn, ) { - let name = format!("{}.{}::text", table.alias.as_str(), &column.name); + let cast = if column.is_list() { "text[]" } else { "text" }; + let name = format!("{}.{}::{}", table.alias.as_str(), &column.name, cast); match (column.is_list(), column.is_nullable()) { (true, true) => select.add_field(sql::>>(&name)), diff --git a/store/test-store/tests/postgres/relational.rs b/store/test-store/tests/postgres/relational.rs index fe366b34509..f1be71a6ed8 100644 --- a/store/test-store/tests/postgres/relational.rs +++ b/store/test-store/tests/postgres/relational.rs @@ -167,6 +167,13 @@ const THINGS_GQL: &str = r#" id: Bytes!, name: String! } + + # For testing handling of enums and enum arrays + type Spectrum @entity { + id: ID!, + main: Color! + all: [Color!]! + } "#; lazy_static! { @@ -739,6 +746,41 @@ fn serialize_bigdecimal() { }); } +#[test] +fn enum_arrays() { + // We had an issue where we would read an array of enums back as a + // single string; for this test, we would get back the string + // "{yellow,red,BLUE}" instead of the array ["yellow", "red", "BLUE"] + run_test(|conn, layout| { + let spectrum = entity! { THINGS_SCHEMA => + id: "rainbow", + main: "yellow", + all: vec!["yellow", "red", "BLUE"] + }; + + insert_entity( + conn, + layout, + &THINGS_SCHEMA.entity_type("Spectrum").unwrap(), + vec![spectrum.clone()], + ); + + let actual = layout + .find( + conn, + &THINGS_SCHEMA + .entity_type("Spectrum") + .unwrap() + .parse_key("rainbow") + .unwrap(), + BLOCK_NUMBER_MAX, + ) + .expect("Failed to read Spectrum[rainbow]") + .unwrap(); + assert_entity_eq!(spectrum, actual); + }); +} + fn count_scalar_entities(conn: &mut PgConnection, layout: &Layout) -> usize { let filter = EntityFilter::Or(vec![ EntityFilter::Equal("bool".into(), true.into()),