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
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
- Do not print information about when the cli decides not to write to a file.
([#365](https://github.com/hasura/ndc-postgres/pull/365))

### Fixed

- Refer to the right column name in the schema endpoint.
([#366](https://github.com/hasura/ndc-postgres/pull/366))

## [v0.5.0] - 2024-03-14

### Added
Expand Down
95 changes: 52 additions & 43 deletions crates/connectors/ndc-postgres/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!

let object_type = models::ObjectType {
description: table.description.clone(),
fields: BTreeMap::from_iter(table.columns.values().map(|column| {
(
column.name.clone(),
models::ObjectField {
description: column.description.clone(),
r#type: column_to_type(column),
},
)
})),
fields: BTreeMap::from_iter(table.columns.iter().map(
|(column_name, column_info)| {
(
column_name.clone(),
models::ObjectField {
description: column_info.description.clone(),
r#type: column_to_type(column_info),
},
)
},
)),
};
(collection_name.clone(), object_type)
}));

let native_queries_types =
BTreeMap::from_iter(metadata.native_queries.0.iter().map(|(name, info)| {
BTreeMap::from_iter(metadata.native_queries.0.iter().map(|(nq_name, nq_info)| {
let object_type = models::ObjectType {
description: info.description.clone(),
fields: BTreeMap::from_iter(info.columns.values().map(|column| {
(
column.name.clone(),
models::ObjectField {
description: column.description.clone(),
r#type: readonly_column_to_type(column),
},
)
})),
description: nq_info.description.clone(),
fields: BTreeMap::from_iter(nq_info.columns.iter().map(
|(column_name, column_info)| {
(
column_name.clone(),
models::ObjectField {
description: column_info.description.clone(),
r#type: readonly_column_to_type(column_info),
},
)
},
)),
};
(name.clone(), object_type)
(nq_name.clone(), object_type)
}));

let composite_types =
BTreeMap::from_iter(metadata.composite_types.0.iter().map(|(name, info)| {
let composite_types = BTreeMap::from_iter(metadata.composite_types.0.iter().map(
|(ctype_name, ctype_info)| {
let object_type = models::ObjectType {
description: info.description.clone(),
fields: BTreeMap::from_iter(info.fields.values().map(|field| {
(
field.name.clone(),
models::ObjectField {
description: field.description.clone(),
r#type: type_to_type(&field.r#type),
},
)
})),
description: ctype_info.description.clone(),
fields: BTreeMap::from_iter(ctype_info.fields.iter().map(
|(field_name, field_info)| {
(
field_name.clone(),
models::ObjectField {
description: field_info.description.clone(),
r#type: type_to_type(&field_info.r#type),
},
)
},
)),
};
(name.clone(), object_type)
}));
(ctype_name.clone(), object_type)
},
));

let mut object_types = table_types;
object_types.extend(native_queries_types);
Expand All @@ -241,24 +248,26 @@ pub async fn get_schema(
.native_queries
.0
.iter()
.filter(|(_, info)| info.is_procedure)
.map(|(name, info)| models::ProcedureInfo {
name: name.clone(),
description: info.description.clone(),
arguments: info
.filter(|(_, nq_info)| nq_info.is_procedure)
.map(|(nq_name, nq_info)| models::ProcedureInfo {
name: nq_name.clone(),
description: nq_info.description.clone(),
arguments: nq_info
.arguments
.iter()
.map(|(name, column_info)| {
.map(|(column_name, column_info)| {
(
name.clone(),
column_name.clone(),
models::ArgumentInfo {
description: column_info.description.clone(),
argument_type: readonly_column_to_type(column_info),
},
)
})
.collect(),
result_type: models::Type::Named { name: name.clone() },
result_type: models::Type::Named {
name: nq_name.clone(),
},
})
.collect();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2123,7 +2123,7 @@ expression: result
},
"artist_below_id": {
"fields": {
"ArtistId": {
"id": {
"type": {
"type": "nullable",
"underlying_type": {
Expand All @@ -2132,7 +2132,7 @@ expression: result
}
}
},
"Name": {
"name": {
"type": {
"type": "nullable",
"underlying_type": {
Expand Down Expand Up @@ -2267,7 +2267,7 @@ expression: result
},
"organization": {
"fields": {
"committees": {
"members": {
"type": {
"type": "array",
"element_type": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1905,7 +1905,7 @@ expression: result
},
"artist_below_id": {
"fields": {
"ArtistId": {
"id": {
"type": {
"type": "nullable",
"underlying_type": {
Expand All @@ -1914,7 +1914,7 @@ expression: result
}
}
},
"Name": {
"name": {
"type": {
"type": "nullable",
"underlying_type": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2207,7 +2207,7 @@ expression: result
},
"artist_below_id": {
"fields": {
"ArtistId": {
"id": {
"type": {
"type": "nullable",
"underlying_type": {
Expand All @@ -2216,7 +2216,7 @@ expression: result
}
}
},
"Name": {
"name": {
"type": {
"type": "nullable",
"underlying_type": {
Expand Down Expand Up @@ -2397,7 +2397,7 @@ expression: result
},
"organization": {
"fields": {
"committees": {
"members": {
"type": {
"type": "array",
"element_type": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"fields": {
"Name": {
"type": "column",
"column": "Name",
"column": "name",
"arguments": {}
}
},
Expand All @@ -14,7 +14,7 @@
"order_direction": "asc",
"target": {
"type": "column",
"name": "ArtistId",
"name": "id",
"path": []
}
}
Expand Down
4 changes: 2 additions & 2 deletions static/aurora/v3-chinook-ndc-metadata/configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -1018,15 +1018,15 @@
"artist_below_id": {
"sql": "SELECT * FROM public.\"Artist\" WHERE \"ArtistId\" < {{id}}",
"columns": {
"ArtistId": {
"id": {
"name": "ArtistId",
"type": {
"scalarType": "int4"
},
"nullable": "nullable",
"description": null
},
"Name": {
"name": {
"name": "Name",
"type": {
"scalarType": "varchar"
Expand Down
4 changes: 2 additions & 2 deletions static/citus/v3-chinook-ndc-metadata/configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -1008,15 +1008,15 @@
"artist_below_id": {
"sql": "SELECT * FROM public.\"Artist\" WHERE \"ArtistId\" < {{id}}",
"columns": {
"ArtistId": {
"id": {
"name": "ArtistId",
"type": {
"scalarType": "int4"
},
"nullable": "nullable",
"description": null
},
"Name": {
"name": {
"name": "Name",
"type": {
"scalarType": "varchar"
Expand Down
4 changes: 2 additions & 2 deletions static/cockroach/v3-chinook-ndc-metadata/configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -993,15 +993,15 @@
"artist_below_id": {
"sql": "SELECT * FROM public.\"Artist\" WHERE \"ArtistId\" < {{id}}",
"columns": {
"ArtistId": {
"id": {
"name": "ArtistId",
"type": {
"scalarType": "int4"
},
"nullable": "nullable",
"description": null
},
"Name": {
"name": {
"name": "Name",
"type": {
"scalarType": "varchar"
Expand Down
4 changes: 2 additions & 2 deletions static/postgres/v3-chinook-ndc-metadata/configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -1265,15 +1265,15 @@
"artist_below_id": {
"sql": "SELECT * FROM public.\"Artist\" WHERE \"ArtistId\" < {{id}}",
"columns": {
"ArtistId": {
"id": {
"name": "ArtistId",
"type": {
"scalarType": "int4"
},
"nullable": "nullable",
"description": null
},
"Name": {
"name": {
"name": "Name",
"type": {
"scalarType": "varchar"
Expand Down
4 changes: 2 additions & 2 deletions static/yugabyte/v3-chinook-ndc-metadata/configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -1008,15 +1008,15 @@
"artist_below_id": {
"sql": "SELECT * FROM public.\"Artist\" WHERE \"ArtistId\" < {{id}}",
"columns": {
"ArtistId": {
"id": {
"name": "ArtistId",
"type": {
"scalarType": "int4"
},
"nullable": "nullable",
"description": null
},
"Name": {
"name": {
"name": "Name",
"type": {
"scalarType": "varchar"
Expand Down