Skip to content

fix names of fields in schema generation #366

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 15, 2024
Merged

fix names of fields in schema generation #366

merged 4 commits into from
Mar 15, 2024

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.

@@ -186,52 +186,59 @@ pub async fn get_schema(
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