jaybauer
06/28/2018, 5:01 PMconst user = await ctx.db.query.user({ where: { id } })
is working as expected, but it’s not returning any nested data (in this case a nested type containing Stripe customer information is what I want to get back). These two nodes have a relation set up in my datamodel, and I’m correctly able to return the data using the same query in my playground. Am I missing something here? Why am I not able to get the nested data back in my resolver? And how else would I approach this, if it’s not doable?Andrew Mead
06/28/2018, 5:16 PMinfo
argument as the second argument to you prisma-binding methods to get any relational data.Andrew Mead
06/28/2018, 5:16 PMjaybauer
06/28/2018, 5:36 PMmakePayment: async(parent, args, ctx, info) => {
const user = await ctx.db.query.user({ where: { id } }, info)
if(user.stripe.stripeId) { dosomething }
}
Currently, my user
variable, without info
, does not return any nested data but returns everything else associated with the user
. If I include info
, it only returns the node type.Andrew Mead
06/28/2018, 5:40 PMinfo
, it only returns the node type"
Could you clarify what you're getting back?jaybauer
06/28/2018, 5:40 PM{ __typename: 'User' }
is the only thing returned.Andrew Mead
06/28/2018, 5:41 PMjaybauer
06/28/2018, 5:49 PMuser
object has an existing relation to a stripe
object, and find the stripeId
from within that object.
If it does, return it to be used in the createCharge
mutation, which creates a charge to be sent to the Stripe account.
Else, create a new stripe
object and connect it to the user
. Then use it in the createCharge
mutation.
I would copy-paste the whole thing in right now, but it’s kind of a mess, haha. Tried for a while to find some workarounds and/or better ways to approach the problem. Gimme a second and I’ll format it more appropriately.jaybauer
06/28/2018, 5:53 PMAndrew Mead
06/28/2018, 5:54 PMAndrew Mead
06/28/2018, 5:55 PMAndrew Mead
06/28/2018, 5:58 PMjaybauer
06/28/2018, 6:06 PMjaybauer
06/28/2018, 6:07 PMexists
function was something I was playing with, but the problem was that it doesn’t return the data. So it would tell me if it exists, but if it found that it DOES exist, that didn’t help me get the info I need. But I’ve definitely employed it in some other places in my application, very useful.Andrew Mead
06/28/2018, 6:09 PMjaybauer
06/29/2018, 6:42 PMuser
object to return it’s Stripe information when looking for a single instance, Prisma just would not generate a way to query for nested data in this way.
I ended up having to query for an array of stripeCustomer
objects on the user and just return the first (and only) result in the array. Not optimal, but I don’t think it’s necessarily an issue? This approach also forced me to have to run a separate query for the user object so I could retrieve their email address for a different reason in the same mutation.
I would’ve preferred to do one query and get all this data, but I can’t for the life of me get it working the way I would expect it to.