MichalLytek / MichalLytek/typegraphql-prisma
small example with uniform graphql mutation handling optional properties
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 918
- Forks
- 130
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the issue**
Hi, I can't craft a uniform mutation using generated CRUD resolvers that can process optional properties.
Example that does work:
variables (phoneNumber is optional but provided):
```json
{"id": "1", "email": "not@us.ed", "name": "mame", "phoneNumber": "123456789"}
```
mutation:
```gql
mutation UpdateUser(
$id: String!
$email: String!
$name: String!
$phoneNumber: String
) {
updateUser(
where: { id: $id }
data: {
email: { set: $email }
name: { set: $name }
phoneNumber: { set: $phoneNumber }
}
) {
updatedAt
name
email
phoneNumber
}
}
```
Which sets the `phoneNumber` field, which is ok.
But when I then leave out the `phoneNumber` I get this error:
```
Argument data.phoneNumber of type NullableStringFieldUpdateOperationsInput needs at least one argument.
```
I would think it is possible to construct a uniform mutation that is idempotent, so we don't have to track what is optional and what is given and then have to adapt our mutation accordingly. (That would suk)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the generated CRUD resolver mutation shown for updateUser, comparing the case where the optional phoneNumber variable is provided with the case where it is omitted. Trace how NullableStringFieldUpdateOperationsInput handles omitted properties and verify that the completed behavior permits a uniform mutation without changing the requested fields.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, typescript
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100