Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion store/postgres/src/relational/dsl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Nullable<Array<Text>>>(&name)),
Expand Down
42 changes: 42 additions & 0 deletions store/test-store/tests/postgres/relational.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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! {
Expand Down Expand Up @@ -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()),
Expand Down
Loading