Anyone knows how to have a computed property in Pr...
# prisma-whats-new
p
Anyone knows how to have a computed property in Prisma? E.g. , my datamodel looks something like:
Copy code
type Quotation {
  id: ID! @unique
  costs: [Cost!]!
  prices: [Float!]!  // Sum of costs
}

type Cost {
 ...
 values: [Float!]!
 currency: String!
}
I'd expect to have my own resolver, so this works:
Copy code
export const Quotation = {
    prices: async (parent, args, ctx: Context, info) => {
        return [1,2,3]
    },
}
Yet how do I rerieve the costs? I don't have a `quotation id`/`cost ids` somewhere...
more specifically, the parent and/or the args seem empty
wel... it's only empty when I don't add stuff like an id in the query, e.g.:
Copy code
quotations {
      id
      prices
    }
which completely makes sense 🙂 but I have no clue which pattern to use such that this would work
But that won't work (yet)
p
😮 😮 very nice
so the fragment was the missing piece
I'm still trying to figure out what this means:
fragment NumRatings on Place { id }
How is Home related to Place? I don't see any relation in the schema
or... a better question would be, what should i put here:
Copy code
export const Quotation = {
    prices: {
        fragment: `???`,
        resolve: async (parent, args, ctx: Context, info) => {
            console.log(parent)
            return null
        }
    }
}
@Vakrim? 🙂 or should I ask @schickling?
Ahhh 😄 I see fragmentreplacers in the index, seems to be working now!
n
@patrick_madx iirc
Home
is the type in the application schema, but it is backed by
Place
in the Prisma data model
p
Oh now I get it 🙂 Makes sense
I got it to work with the fragments btw 🙂
Lovely work on the prisma part
Copy code
export const Quotation = {
    prices: {
        fragment: `fragment LaneQuotationPrice on Quotation { id }`,
        resolve: async ({ id }, args, ctx: Context, info) => {

            return await calculateContainerPrice(ctx.db, id)
        }
    }
}
👍 1