paljs / prisma-tools

Prisma tools to help you generate CRUD system for GraphQL servers
https://paljs.com
MIT License
681 stars 55 forks source link

PrismaSelect does not select the field in relation #200

Closed raymclee closed 3 years ago

raymclee commented 3 years ago

I have the following code in resolver.

"prisma": "2.21.2", "@paljs/plugins": "^3.0.1",

queryField("shops", {
  type: list("Shop"),
  async resolve(_parent, _args, { prisma }, info) {
    const select = new PrismaSelect(info).value;
    console.log(select);
    return prisma.shop.findMany({
      ...select,
    });
  },
});
{
  shops {
    id
    phone
    owner {
      id
      email
    }
  }
}

and when i use above query. the field from owner are not returning. the output from the console.log(select) is { select: { id: true, phone: true, owner: { select: [Object] } } }. below is the prisma log. as you can see, prisma is not selecting the column in owner

prisma:info Fetched a connection from the pool
prisma:query SELECT "dev"."shops"."id", "dev"."shops"."phone", "dev"."shops"."owner_id" FROM "dev"."shops" WHERE 1=1 OFFSET $1
prisma:query SELECT 1
prisma:info Fetched a connection from the pool
prisma:query SELECT "dev"."shops"."id", "dev"."shops"."owner_id" FROM "dev"."shops" WHERE "dev"."shops"."id" IN ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22,$23,$24,$25,$26,$27,$28,$29,$30,$31,$32,$33,$34,$35,$36,$37,$38,$39,$40,$41,$42,$43,$44,$45,$46,$47,$48,$49,$50) OFFSET $51
AhmedElywa commented 3 years ago

the output from the console.log(select) is { select: { id: true, phone: true, owner: { select: [Object] } } }.

use console.dir(select, {depth: null}) to see owner: { select: [Object] } } details

raymclee commented 3 years ago

the output from the console.log(select) is { select: { id: true, phone: true, owner: { select: [Object] } } }.

use console.dir(select, {depth: null}) to see owner: { select: [Object] } } details

please see the output

{
  select: {
    id: true,
    phone: true,
    owner: { select: { id: true, email: true } }
  }
}
prisma:query SELECT 1
prisma:info Fetched a connection from the pool
prisma:query SELECT "dev"."shops"."id", "dev"."shops"."phone", "dev"."shops"."owner_id" FROM "dev"."shops" WHERE 1=1 OFFSET $1
prisma:info Fetched a connection from the pool
prisma:query SELECT "dev"."shops"."id", "dev"."shops"."owner_id" FROM "dev"."shops" WHERE "dev"."shops"."id" IN ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22,$23,$24,$25,$26,$27,$28,$29,$30,$31,$32,$33,$34,$35,$36,$37,$38,$39,$40,$41,$42,$43,$44,$45,$46,$47,$48,$49,$50) OFFSET $51
AhmedElywa commented 3 years ago

My tool is working fine and converted

{
  shops {
    id
    phone
    owner {
      id
      email
    }
  }
}

to

{
  select: {
    id: true,
    phone: true,
    owner: { select: { id: true, email: true } }
  }
}
raymclee commented 3 years ago

oh sorry, my database got screwed up. i forgot to add the relationship. after i add back the relationship and it works perfectly! Thanks