Yuriy Rypka
Yuriy Rypka

Reputation: 2107

Can I use a directive to calculate field value based on other field value?

I have such a model:

type Email {
  id: ID! @unique
  confirmed: Boolean! @default(value: "false")
  formatted: String! @unique
  raw: String!
}

I need to lowercase value from raw field and put it into formatted field before saving to db.

The thing is that I have already three use cases (contact us, subscribe to news, signup) and I’ll need to write the same code in three different resolvers.

To avoid duplication I thought it would be nice to do this in a directive somehow.

Is it possible to create my own directive which would handle this?

Update: As of Prisma v1.18 it's not possible.

Upvotes: 2

Views: 556

Answers (2)

nburk
nburk

Reputation: 22731

This is currently not possible in Prisma and indeed needs to be implemented on the application layer. There is an open feature request for this though, please join the discussion on GitHub and add your +1 if you're interested in this functionality.

Upvotes: 1

Oleksandr Kovalov
Oleksandr Kovalov

Reputation: 1

Based on the spec doc, I don't think it is possible (unfortunately) because that sounds like you need a computed field

"GraphQL is not a programming language capable of arbitrary computation, but is instead a language used to query application servers that have capabilities defined in this specification."

https://facebook.github.io/graphql/June2018/

Upvotes: 0

Related Questions