Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Commit

Permalink
enhancement: transparently add internal types for GraphQL connection …
Browse files Browse the repository at this point in the history
…specification (#1403)

* Implement types for connection specification

* Ensure that internal fields are not used for struct construction

* Make virtual entity check more specific

* Don't create database artifacts for internal types

* clippy fixes

* Fix unit test

* De-dupe redundant code

* Ensure that column position calculated after filtering for internal types

* Address ra0x3 feedback
  • Loading branch information
deekerno authored Oct 17, 2023
1 parent 0eb480f commit a9c3831
Show file tree
Hide file tree
Showing 9 changed files with 507 additions and 50 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 8 additions & 18 deletions packages/fuel-indexer-database/database-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use chrono::{
};
use fuel_indexer_lib::{
graphql::{
extract_foreign_key_info, field_id, is_list_type,
check_for_directive, extract_foreign_key_info, field_id, is_list_type,
types::{IdCol, ObjectCol},
JoinTableMeta, ParsedGraphQLSchema,
},
Expand Down Expand Up @@ -305,10 +305,7 @@ impl Column {
..Self::default()
},
false => {
let unique = f
.directives
.iter()
.any(|d| d.node.name.to_string() == "unique");
let unique = check_for_directive(&f.directives, "unique");

Self {
type_id,
Expand Down Expand Up @@ -884,16 +881,17 @@ impl Table {
let mut columns = o
.fields
.iter()
.filter(|f| !check_for_directive(&f.node.directives, "internal"))
.enumerate()
.map(|(i, f)| {
.map(|(i, f)|
Column::from_field_def(
&f.node,
parsed,
ty_id,
i as i32,
persistence,
)
})
)
.collect::<Vec<Column>>();

let mut constraints = Vec::new();
Expand All @@ -908,19 +906,11 @@ impl Table {
return;
}

let has_index = f
.node
.directives
.iter()
.any(|d| d.node.name.to_string() == "indexed" || d.node.name.to_string() == "unique");
let has_index = check_for_directive(&f.node.directives, "indexed");

let has_unique = f
.node
.directives
.iter()
.any(|d| d.node.name.to_string() == "unique");
let has_unique = check_for_directive(&f.node.directives, "unique");

if has_index {
if has_index || has_unique {
constraints.push(Constraint::Index(SqlIndex {
db_type: DbType::Postgres,
table_name: typ.name.to_string().to_lowercase(),
Expand Down
1 change: 1 addition & 0 deletions packages/fuel-indexer-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ description = "Fuel Indexer Library"
[dependencies]
anyhow = "1.0"
async-graphql-parser = { workspace = true }
async-graphql-value = { workspace = true }
bincode = { workspace = true }
clap = { features = ["cargo", "derive", "env"], workspace = true }
fuel-indexer-types = { workspace = true }
Expand Down
Loading

0 comments on commit a9c3831

Please sign in to comment.