Skip to content

Commit

Permalink
feat(prisma): connect/create many relation (#522)
Browse files Browse the repository at this point in the history
<!--
Pull requests are squash 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 and understand when they need to update his code and
how.
-->

### Describe your change

- Add missing `create: [ ... ]` and `connect: [ ... ]`

### Motivation and context

Solves
[MET-304](https://metatype.atlassian.net/jira/software/c/projects/MET/boards/2?selectedIssue=MET-304)

### Checklist

- [x] The change come with new or modified tests
- [ ] Hard-to-understand functions have explanatory comments
- [ ] End-user documentation is updated to reflect the change
  • Loading branch information
michael-0acf4 authored Dec 12, 2023
1 parent 7815dad commit 236b512
Show file tree
Hide file tree
Showing 12 changed files with 7,463 additions and 4,849 deletions.
36 changes: 36 additions & 0 deletions typegate/tests/runtimes/prisma/full_prisma_mapping_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -847,4 +847,40 @@ Meta.test("prisma full mapping", async (t) => {
})
.on(e);
});

await t.should("work with a create/connect list", async () => {
await gql`
mutation {
createOnePost(
data: {
id: 99999,
title: "New Post",
views: 1,
likes: 9,
published: true,
author: { connect: { id: 1 } },
comments: {
# create: [
# { id: 59999, content: "it works!", author: { connect: { id: 1 } }}
# ]
connect: [ # equiv. {connect: { id: 50001}}
{ id: 50001 },
]
}
}
) {
id
comments { id content }
}
}
`.expectData({
createOnePost: {
id: 99999,
comments: [
{ id: 50001, content: "good" },
],
},
})
.on(e);
});
});
10 changes: 10 additions & 0 deletions typegraph/core/src/runtimes/prisma/type_generation/input_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,17 @@ impl TypeGen for InputType {
},
operation: Operation::Create,
})?;
let create = match prop.quantifier {
Cardinality::Many => t::unionx!(create, t::list(create)).build()?,
_ => create,
};

let connect = context.generate(&Where::new(prop.model_id))?;
let connect = match prop.quantifier {
Cardinality::Many => t::unionx!(connect, t::list(connect)).build()?,
_ => connect,
};

let connect_or_create = t::struct_()
.prop("create", create)
.prop("where", connect)
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
source: typegraph/core/src/runtimes/prisma/type_generation/mod.rs
expression: "tree::print(out)"
---
root: struct #108
└─ [count]: integer #107
root: struct #112
└─ [count]: integer #111

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
source: typegraph/core/src/runtimes/prisma/type_generation/mod.rs
expression: "tree::print(out)"
---
root: struct #80
└─ [count]: integer #79
root: struct #84
└─ [count]: integer #83

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

0 comments on commit 236b512

Please sign in to comment.