Skip to content
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

fix(typegraph): prisma where fields types #975

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
13 changes: 10 additions & 3 deletions src/typegraph/core/src/runtimes/prisma/type_generation/filters.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright Metatype OÜ, licensed under the Mozilla Public License Version 2.0.
// SPDX-License-Identifier: MPL-2.0

use tg_schema::runtimes::prisma::StringType;

use crate::errors::Result;
use crate::runtimes::prisma::context::PrismaContext;
use crate::t::{self, TypeBuilder};
Expand Down Expand Up @@ -112,11 +114,16 @@ impl TypeGen for NumberFilter {
}
}

pub(super) struct StringFilter;
pub(super) struct StringFilter {
pub format: StringType,
}

impl TypeGen for StringFilter {
fn generate(&self, context: &PrismaContext) -> Result<TypeId> {
let type_id = t::string().build()?;
let type_id = match &self.format {
StringType::Plain => t::string().build()?,
custom => t::string().format(custom.to_string()).build()?,
};
let opt_type_id = t::optional(type_id).build()?;
let list_type_id = t::list(type_id).build()?;

Expand All @@ -141,7 +148,7 @@ impl TypeGen for StringFilter {
}

fn name(&self, _context: &PrismaContext) -> Result<String> {
Ok("_prisma_string_filter".to_string())
Ok(format!("_prisma_{}_filter", self.format))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,58 @@
source: src/typegraph/core/src/runtimes/prisma/type_generation/mod.rs
expression: tp.print(inp)
---
root: struct 'Post_query_input' #243
├─ [cursor]: optional #236
│ └─ item: union 'Post_cursor' #235
│ ├─ variant_0: struct #232
│ │ └─ [id]: integer #119
│ └─ variant_1: struct #233
│ └─ [title]: string #120
├─ [distinct]: optional #241
│ └─ item: list 'Post_keys_union' #240
│ └─ item: string #238 enum{ '"id"', '"title"', '"author"' }
├─ [orderBy]: optional #228
│ └─ item: list 'Post_order_by' #227
│ └─ item: struct #225
│ ├─ [author]: optional #224
│ │ └─ item: list 'User_order_by_withoutrel_Post_User' #223
│ │ └─ item: struct #221
│ │ ├─ [id]: &_prisma_sort #63
│ │ └─ [name]: &_prisma_sort #63
│ ├─ [id]: &_prisma_sort #63
│ └─ [title]: &_prisma_sort #63
├─ [skip]: optional #230
│ └─ item: &_skip #87
├─ [take]: optional #229
│ └─ item: &_take #83
└─ [where]: optional #218
└─ item: struct 'Post_query_where_input' #217
├─ [AND]: optional #214
│ └─ item: list #213
│ └─ item: &Post_query_where_input #212
├─ [NOT]: optional #215
│ └─ item: &Post_query_where_input #212
├─ [OR]: optional #214
│ └─ item: list #213
│ └─ item: &Post_query_where_input #212
├─ [author]: optional #209
│ └─ item: struct 'User_where_excluding_Post' #208
│ ├─ [id]: optional #196
│ │ └─ item: &_prisma_integer_filter_ex #35
│ ├─ [name]: optional #197
│ │ └─ item: &_prisma_string_filter_ex #13
│ └─ [posts]: optional #206
│ └─ item: union #205
│ ├─ variant_0: struct #200
│ │ └─ [every]: optional #199
│ │ └─ item: &Post_where #198
│ ├─ variant_1: struct #202
│ │ └─ [some]: optional #201
│ │ └─ item: &Post_where #198
│ └─ variant_2: struct #204
│ └─ [none]: optional #203
│ └─ item: &Post_where #198
├─ [id]: optional #193
│ └─ item: &_prisma_integer_filter_ex #35
└─ [title]: optional #194
└─ item: &_prisma_string_filter_ex #13
root: struct 'Post_query_input' #283
├─ [cursor]: optional #276
│ └─ item: union 'Post_cursor' #275
│ ├─ variant_0: struct #272
│ │ └─ [id]: integer #159
│ └─ variant_1: struct #273
│ └─ [title]: string #160
├─ [distinct]: optional #281
│ └─ item: list 'Post_keys_union' #280
│ └─ item: string #278 enum{ '"id"', '"title"', '"author"' }
├─ [orderBy]: optional #268
│ └─ item: list 'Post_order_by' #267
│ └─ item: struct #265
│ ├─ [author]: optional #264
│ │ └─ item: list 'User_order_by_withoutrel_Post_User' #263
│ │ └─ item: struct #261
│ │ ├─ [id]: &_prisma_sort #103
│ │ └─ [name]: &_prisma_sort #103
│ ├─ [id]: &_prisma_sort #103
│ └─ [title]: &_prisma_sort #103
├─ [skip]: optional #270
│ └─ item: &_skip #127
├─ [take]: optional #269
│ └─ item: &_take #123
└─ [where]: optional #258
└─ item: struct 'Post_query_where_input' #257
├─ [AND]: optional #254
│ └─ item: list #253
│ └─ item: &Post_query_where_input #252
├─ [NOT]: optional #255
│ └─ item: &Post_query_where_input #252
├─ [OR]: optional #254
│ └─ item: list #253
│ └─ item: &Post_query_where_input #252
├─ [author]: optional #249
│ └─ item: struct 'User_where_excluding_Post' #248
│ ├─ [id]: optional #236
│ │ └─ item: &_prisma_integer_filter_ex #55
│ ├─ [name]: optional #237
│ │ └─ item: &_prisma_string_filter_ex #34
│ └─ [posts]: optional #246
│ └─ item: union #245
│ ├─ variant_0: struct #240
│ │ └─ [every]: optional #239
│ │ └─ item: &Post_where #238
│ ├─ variant_1: struct #242
│ │ └─ [some]: optional #241
│ │ └─ item: &Post_where #238
│ └─ variant_2: struct #244
│ └─ [none]: optional #243
│ └─ item: &Post_where #238
├─ [id]: optional #233
│ └─ item: &_prisma_integer_filter_ex #55
└─ [title]: optional #234
└─ item: &_prisma_string_filter_ex #34
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
source: src/typegraph/core/src/runtimes/prisma/type_generation/mod.rs
expression: tp.print(out)
---
root: list #247
└─ item: struct 'Post_with_nested_count' #246
├─ [author]: &User #121
├─ [id]: integer #117
└─ [title]: string #120
root: list #287
└─ item: struct 'Post_with_nested_count' #286
├─ [author]: &User #161
├─ [id]: integer #157
└─ [title]: string #160
Loading
Loading