-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix optional field filter in apply (#909)
<!-- Pull requests are squashed and merged using: - their title as the commit message - their description as the commit body Having a good title and description is important for the users to get readable changelog. --> <!-- 1. Explain WHAT the change is about --> - Fix the optional field filter on apply: resolve types before matching. <!-- 2. Explain WHY the change cannot be made simpler --> <!-- 3. Explain HOW users should update their code --> #### Migration notes _No migrations needed._ --- - [x] The change comes with new or modified tests - [ ] Hard-to-understand functions have explanatory comments - [ ] End-user documentation is updated to reflect the change
- Loading branch information
Showing
4 changed files
with
118 additions
and
15 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
// Copyright Metatype OÜ, licensed under the Mozilla Public License Version 2.0. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
import { gql, Meta } from "../utils/mod.ts"; | ||
import { randomPGConnStr } from "test-utils/database.ts"; | ||
import { gql, Meta } from "test-utils/mod.ts"; | ||
import { dropSchemas, recreateMigrations } from "test-utils/migrations.ts"; | ||
import { assertEquals } from "@std/assert/equals"; | ||
|
||
Meta.test("(python (sdk): apply)", async (t) => { | ||
const e = await t.engine("params/apply.py", { | ||
|
@@ -253,3 +256,66 @@ Meta.test("nested context access", async (t) => { | |
.on(e); | ||
}); | ||
}); | ||
|
||
Meta.test("apply with prisma generated types", async (t) => { | ||
const { connStr, schema: _ } = randomPGConnStr(); | ||
const e = await t.engine("params/prisma_apply.py", { | ||
secrets: { | ||
"POSTGRES": connStr, | ||
}, | ||
}); | ||
await dropSchemas(e); | ||
await recreateMigrations(e); | ||
|
||
let id: string = null!; | ||
|
||
await t.should("create user", async () => { | ||
await gql` | ||
mutation { | ||
createUser( | ||
name: "Alice" | ||
email: "[email protected]" | ||
age: 30 | ||
) { | ||
id | ||
name | ||
age | ||
} | ||
} | ||
` | ||
.expectBody((body) => { | ||
id = body.data.createUser.id; | ||
assertEquals(body.data.createUser, { | ||
id: id, | ||
name: "Alice", | ||
email: "[email protected]", | ||
age: 30, | ||
}); | ||
}) | ||
.on(e); | ||
}); | ||
|
||
await t.should("find user by id", async () => { | ||
await gql` | ||
query Q($id: ID!) { | ||
findUser(id: $id) { | ||
id | ||
name | ||
age | ||
} | ||
} | ||
` | ||
.withVars({ id }) | ||
.expectData({ | ||
findUser: { | ||
id, | ||
name: "Alice", | ||
email: "[email protected]", | ||
age: 30, | ||
}, | ||
}) | ||
.on(e); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from typegraph import Graph, Policy, t, typegraph | ||
from typegraph.providers import PrismaRuntime | ||
|
||
|
||
@typegraph() | ||
def prisma_apply(g: Graph): | ||
prisma = PrismaRuntime("db", "POSTGRES") | ||
public = Policy.public() | ||
|
||
user = t.struct( | ||
{ | ||
"id": t.uuid(config=["auto"]).id(), | ||
"name": t.string(), | ||
"email": t.email(config=["unique"]), | ||
"age": t.integer(), | ||
}, | ||
name="user", | ||
) | ||
|
||
g.expose( | ||
public, | ||
createUser=prisma.create(user).apply( | ||
{ | ||
"data": { | ||
"name": g.as_arg(), | ||
"email": g.as_arg(), | ||
"age": g.as_arg(), | ||
} | ||
} | ||
), | ||
findUser=prisma.find_unique(user).apply( | ||
{ | ||
"where": { | ||
"id": g.as_arg(), | ||
} | ||
} | ||
), | ||
) |