Skip to content

Commit

Permalink
feat: Remove injected fields from generated types for prisma operatio…
Browse files Browse the repository at this point in the history
…ns (#448)

Injected fields are skipped when generating types for prisma.

Additional changes:
- Enable recursive relationships in where filters.
- Add `disconnect`, `update`, `upsert`, `delete`, `updateMany`,
`deleteMany` on nested reletionships for create/update operations.
- Fix optional union arg validation.
  • Loading branch information
Natoandro authored Oct 19, 2023
1 parent 2ca1a92 commit 96f224f
Show file tree
Hide file tree
Showing 101 changed files with 15,575 additions and 5,669 deletions.
14 changes: 7 additions & 7 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion dev/lock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ dev:
WASMEDGE_VERSION: 0.12.1
TYPEGRAPH_VERSION: 0.0.3
PRISMA_VERSION: 5.4.2
METATYPE_VERSION: 0.2.3-0+dev
METATYPE_VERSION: 0.2.3
WASM_OPT_VERSION: 0.114.1
TAGLINE: >-
Declarative API development platform. Build serverless backends with
Expand Down
2 changes: 1 addition & 1 deletion examples/templates/python/compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
typegate:
image: ghcr.io/metatypedev/typegate:v0.2.3-0+dev
image: ghcr.io/metatypedev/typegate:v0.2.3
restart: always
ports:
- "7890:7890"
Expand Down
4 changes: 2 additions & 2 deletions examples/templates/python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[tool.poetry]
name = "example"
version = "0.2.3-0+dev"
version = "0.2.3"
description = ""
authors = []
readme = "README.md"

[tool.poetry.dependencies]
python = ">=3.8,<4.0"
typegraph = "0.2.3-0+dev"
typegraph = "0.2.3"

[build-system]
requires = ["poetry-core"]
Expand Down
2 changes: 1 addition & 1 deletion libs/common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "common"
version = "0.2.3-0+dev"
version = "0.2.3"
edition = "2021"

[dependencies]
Expand Down
89 changes: 88 additions & 1 deletion libs/common/src/typegraph/runtimes/prisma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,101 @@ pub struct Relationship {
pub right: RelationshipModel,
}

#[cfg_attr(feature = "codegen", derive(JsonSchema))]
#[derive(Serialize, Deserialize, Clone, Debug)]
pub enum Injection {
DateNow,
// TODO other dynamic injection?
}

#[cfg_attr(feature = "codegen", derive(JsonSchema))]
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct ManagedInjection {
pub create: Option<Injection>,
pub update: Option<Injection>,
}

#[cfg_attr(feature = "codegen", derive(JsonSchema))]
#[derive(Serialize, Deserialize, Clone, Debug)]
pub enum StringType {
Plain,
Uuid,
DateTime,
}

#[cfg_attr(feature = "codegen", derive(JsonSchema))]
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(tag = "type")]
pub enum ScalarType {
Boolean,
#[serde(rename = "Int")]
Integer,
Float,
String {
format: StringType,
},
}

#[cfg_attr(feature = "codegen", derive(JsonSchema))]
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct ScalarProperty {
pub key: String,
pub prop_type: ScalarType,
pub cardinality: Cardinality,
pub type_idx: u32,
pub injection: Option<ManagedInjection>,
pub unique: bool,
pub auto: bool,
}

#[cfg_attr(feature = "codegen", derive(JsonSchema))]
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "lowercase")]
pub enum Side {
Left,
Right,
}

#[cfg_attr(feature = "codegen", derive(JsonSchema))]
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct RelationshipProperty {
pub key: String,
pub cardinality: Cardinality,
pub type_idx: u32,
pub model_name: String,
pub unique: bool,
pub relationship_name: String,
pub relationship_side: Side,
}

#[cfg_attr(feature = "codegen", derive(JsonSchema))]
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(tag = "type", rename_all = "lowercase")]
pub enum Property {
Scalar(ScalarProperty),
Relationship(RelationshipProperty),
}

#[cfg_attr(feature = "codegen", derive(JsonSchema))]
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Model {
pub type_idx: u32,
pub type_name: String,
pub props: Vec<Property>,
pub id_fields: Vec<String>,
}

#[cfg_attr(feature = "codegen", derive(JsonSchema))]
#[skip_serializing_none]
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(deny_unknown_fields)]
pub struct PrismaRuntimeData {
pub name: String,
pub connection_string_secret: String,
pub models: Vec<u32>,
pub models: Vec<Model>,
pub relationships: Vec<Relationship>,
// if migration_options is not None: migrations will be applied on push
#[serde(default)]
Expand Down
2 changes: 1 addition & 1 deletion libs/macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "macros"
version = "0.2.3-0+dev"
version = "0.2.3"
edition = "2021"

[lib]
Expand Down
2 changes: 1 addition & 1 deletion libs/typescript/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "typescript"
version = "0.2.3-0+dev"
version = "0.2.3"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion libs/xtask/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "xtask"
version = "0.2.3-0+dev"
version = "0.2.3"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion meta-cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "meta-cli"
version = "0.2.3-0+dev"
version = "0.2.3"
edition = "2021"

description = "Declarative API development platform. Build serverless backends with zero-trust and less code, no matter where and how your (legacy) systems are."
Expand Down
Loading

0 comments on commit 96f224f

Please sign in to comment.