Skip to content

Commit 506a6ef

Browse files
committed
feat(gb-9141): empty allowlist filters everything out
1 parent 0ef47dd commit 506a6ef

8 files changed

Lines changed: 2457 additions & 3647 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/postgres/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "grafbase-postgres"
3-
version = "0.3.7"
3+
version = "0.3.8"
44
edition = "2024"
55
license = "Apache-2.0"
66

cli/postgres/README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,9 @@ enable_queries = true
129129

130130
# Schema allowlist: An array of schema names to include in the introspection.
131131
# If provided, only schemas in this list will be included.
132-
# If empty, all schemas will be included (unless in the denylist).
133-
schema_allowlist = []
132+
# If not defined or null, all schemas will be included (unless in the denylist).
133+
# If empty, no schemas will be included.
134+
schema_allowlist = null
134135

135136
# Schema denylist: An array of schema names to exclude from the introspection.
136137
# Schemas in this list will be excluded even if they appear in the allowlist.
@@ -156,8 +157,9 @@ enable_queries = true
156157

157158
# Table allowlist: An array of table names to include in the introspection.
158159
# If provided, only tables in this list will be included for this schema.
159-
# If empty, all tables will be included (unless in the denylist).
160-
table_allowlist = []
160+
# If not defined or null, all tables will be included (unless in the denylist).
161+
# If empty, no tables will be included for the schema.
162+
table_allowlist = null
161163

162164
# Table denylist: An array of table names to exclude from the introspection.
163165
# Tables in this list will be excluded even if they appear in the allowlist.
@@ -459,7 +461,7 @@ You can control which database schemas and tables are included in the introspect
459461

460462
You can include or exclude specific database schemas using the following options:
461463

462-
- `schema_allowlist`: An array of schema names to include. If provided, only schemas in this list will be included in the introspection.
464+
- `schema_allowlist`: An array of schema names to include. If provided, only schemas in this list will be included in the introspection. If empty, no schemas will be included. If not defined, all schemas will be included.
463465
- `schema_denylist`: An array of schema names to exclude. Schemas in this list will be excluded from introspection, even if they appear in the allowlist.
464466

465467
```toml
@@ -473,12 +475,12 @@ schema_denylist = ["internal"]
473475

474476
Within each schema, you can include or exclude specific tables using these options:
475477

476-
- `table_allowlist`: An array of table names to include. If provided, only tables in this list will be included for that schema.
478+
- `table_allowlist`: An array of table names to include. If provided, only tables in this list will be included for that schema. If empty, no tables will be included for the schema. If not defined, all tables will be included.
477479
- `table_denylist`: An array of table names to exclude. Tables in this list will be excluded, even if they appear in the allowlist.
478480

479481
```toml
480482
# Example of table filtering in config.toml
481-
extension_url = "https://grafbase.com/extensions/postgres/0.4.7"
483+
extension_url = "https://grafbase.com/extensions/postgres/0.4.9"
482484

483485
[schemas.public]
484486
table_allowlist = ["users", "posts"]

cli/postgres/install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ if [[ ${OS:-} = Windows_NT ]]; then
66
exit 1
77
fi
88

9-
LATEST_VERSION="0.3.7"
9+
LATEST_VERSION="0.3.8"
1010

1111
# Reset
1212
Color_Off=''

crates/postgres-introspection/src/config.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ pub struct Config {
3737
pub schemas: BTreeMap<String, SchemaConfig>,
3838
/// Optional list of schemas to include in the GraphQL schema.
3939
/// If this list is populated, only schemas in this list will be included.
40-
/// If empty, all schemas will be included.
40+
/// If None, all schemas will be included. If empty, no schemas will be included.
4141
#[serde(default)]
42-
pub schema_allowlist: Vec<String>,
42+
pub schema_allowlist: Option<Vec<String>>,
4343
/// Optional list of schemas to exclude from the GraphQL schema.
4444
/// If this list is populated, schemas in this list will be excluded even if they are in the allowlist.
4545
/// This takes precedence over the allowlist.
@@ -96,8 +96,12 @@ impl Config {
9696
}
9797

9898
pub fn is_schema_included(&self, schema: &str) -> bool {
99+
let Some(allowlist) = self.schema_allowlist.as_ref() else {
100+
return !self.schema_denylist.contains(&schema.to_string());
101+
};
102+
99103
!self.schema_denylist.contains(&schema.to_string())
100-
&& (self.schema_allowlist.is_empty() || self.schema_allowlist.contains(&schema.to_string()))
104+
&& (!allowlist.is_empty() && allowlist.contains(&schema.to_string()))
101105
}
102106

103107
/// Determines whether a table is included in the GraphQL schema based on the configuration.
@@ -109,8 +113,12 @@ impl Config {
109113
return true;
110114
};
111115

116+
let Some(allowlist) = schema_config.table_allowlist.as_ref() else {
117+
return !schema_config.table_denylist.contains(&table.to_string());
118+
};
119+
112120
!schema_config.table_denylist.contains(&table.to_string())
113-
&& (schema_config.table_allowlist.is_empty() || schema_config.table_allowlist.contains(&table.to_string()))
121+
&& (!allowlist.is_empty() && allowlist.contains(&table.to_string()))
114122
}
115123
}
116124

@@ -140,9 +148,9 @@ pub struct SchemaConfig {
140148
pub tables: BTreeMap<String, TableConfig>,
141149
/// Optional list of tables to include in the GraphQL schema.
142150
/// If this list is populated, only tables in this list will be included.
143-
/// If empty, all tables will be included.
151+
/// If None, all tables will be included. If empty, no tables will be included.
144152
#[serde(default)]
145-
pub table_allowlist: Vec<String>,
153+
pub table_allowlist: Option<Vec<String>>,
146154
/// Optional list of tables to exclude from the GraphQL schema.
147155
/// If this list is populated, tables in this list will be excluded even if they are in the allowlist.
148156
/// This takes precedence over the allowlist.

crates/postgres-introspection/src/tables.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,18 @@ pub(crate) async fn introspect_database(
3939
continue;
4040
};
4141

42-
// Skip tables that are not in the allowlist or are in the denylist
43-
if !config.is_table_included(&schema_name, &table_name) {
44-
continue;
45-
};
46-
4742
let kind = match row.get::<i8, _>(3) as u8 as char {
4843
'r' => RelationKind::Relation,
4944
'v' => RelationKind::View,
5045
'm' => RelationKind::MaterializedView,
5146
_ => unreachable!(),
5247
};
5348

49+
// Skip tables that are not in the allowlist or are in the denylist
50+
if !kind.is_view() && !config.is_table_included(&schema_name, &table_name) {
51+
continue;
52+
};
53+
5454
let mut table = Table::<String>::new(schema_id, table_name, kind, None);
5555

5656
if let Some(description) = row.get(2) {

extensions/postgres/tests/integration_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ impl PgTestApi {
266266
schemas: Default::default(),
267267
enable_mutations: true,
268268
enable_queries: true,
269-
schema_allowlist: Vec::new(),
269+
schema_allowlist: None,
270270
schema_denylist: Vec::new(),
271271
})
272272
.await
@@ -282,7 +282,7 @@ impl PgTestApi {
282282
schemas: Default::default(),
283283
enable_mutations: true,
284284
enable_queries: true,
285-
schema_allowlist: Vec::new(),
285+
schema_allowlist: None,
286286
schema_denylist: Vec::new(),
287287
})
288288
.await

0 commit comments

Comments
 (0)