Skip to content

Conversation

@soupi
Copy link
Contributor

@soupi soupi commented Mar 15, 2024

What

The /schema endpoint was exposing the wrong column names in object types. This PR fixes this.

How

columns, referenced by tables, native queries, etc. Have a type that looks somewhat like this: BTreeMap<String, ColumnInfo>.

ColumnInfo looks somewhat like this: ColumnInfo { name: String, ... }.

The String in the map refers to the external name that ndc-spec queries should reference, while the ColumnInfo name refers to the database column name.

By mistake, were reporting the ColumnInfo name in the schema, instead of the String from the map.

We fix this by referring to the right name, and use iter() on the BTreeMap instead of values().

@SamirTalwar
Copy link
Contributor

I wanted to wrap these all in newtypes to catch exactly this kind of issue (we saw something similar before) but I struggled because a lot of this stuff is in the ndc_client::models module.

I still think we should do this, but it requires a bit of thought.

collections.extend(native_queries);

let table_types =
BTreeMap::from_iter(metadata.tables.0.iter().map(|(collection_name, table)| {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, BTreeMap::from_iter might be more idiomatically expressed as .collect().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good to know!

@soupi
Copy link
Contributor Author

soupi commented Mar 15, 2024

@SamirTalwar Perhaps we should rename the field name in column info to pg_name.

@soupi
Copy link
Contributor Author

soupi commented Mar 15, 2024

@SamirTalwar ah, that's a breaking change, and I don't care to make one right now :(

@soupi soupi added this pull request to the merge queue Mar 15, 2024
Merged via the queue into main with commit 67dae07 Mar 15, 2024
@soupi soupi deleted the gil/fix-schema-names branch March 15, 2024 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants