Anthony Magnus
04/15/2020, 6:01 PMtype Customer {
id: ID! @id
createdAt: DateTime! @createdAt
updatedAt: DateTime! @updatedAt
name: String
email: String
phone: String
user: User
cart: [CartItem]!
orders: [Order]!
}
type CartItem {
id: ID! @id
quantity: Int! @default(value: 1)
dish: Dish!
customer: Customer!
}
type Dish {
id: ID! @id
name: String!
price: Float!
description: String!
isAvailable: Boolean! @default(value: true)
category: String
restaurant: Restaurant!
}
type Restaurant {
id: ID! @id
createdAt: DateTime! @createdAt
updatedAt: DateTime! @updatedAt
user: User
name: String!
street: String!
number: String !
addition: String
zip: String!
city: String!
dishes: [Dish]!
orders: [Order]!
}
I can query the data inside the playground area with the following query
query {
customer(where: { id: "ck8zwslgs00da0712cq88e3oh" } ) {
id
cart(where: { dish: { restaurant: { id: "ck904gwl400mz0712v0azegm3" } } }) {
quantity
dish {
name
price
restaurant {
id
name
}
}
}
}
}
But I can't figure out how to do this nested filter with the prisma client.
Tried some things
const data = await ctx.db.query.customer({
where: {
AND: [
{
id: args.customerID
},
{
cart: {
dish : {
restaurant: {
id: args.restaurantID
}
}
}
}
]
}
}, info);
const data = await ctx.db.query.customer({
where: {
id: args.customerID
cart: {
dish : {
restaurant: {
id: args.restaurantID
}
}
}
}
}, info);
const data = await ctx.db.query.customer({
where: {
id: args.customerID
},
cart: {
where: {
dish : {
restaurant: {
id: args.restaurantID
}
}
}
}
}, info);
const data = await ctx.db.query.customer({
where: {
id: args.customerID
},
cart: {
dish : {
restaurant: {
where: {
id: args.restaurantID
}
}
}
}
}, info);
The first one returns an error "Field \"cart\" is not defined by type CustomerWhereUniqueInput".
The last two are returning every cartItem from the customer.
Someone can help me out with this?Amin
04/15/2020, 7:00 PMAnthony Magnus
04/15/2020, 7:07 PMCharlie Meaden
04/15/2020, 10:56 PMEthan Pursley
04/15/2020, 11:02 PMCharlie Meaden
04/15/2020, 11:04 PMERROR: There is a relation ambiguity during the migration. Please first name the old relation on your schema. The ambiguity is on a relation between Portfolio and User. Please name relations or change the schema in steps.
{
"data": {
"deploy": null
},
"errors": [
{
"locations": [
{
"line": 2,
"column": 9
}
],
"path": [
"deploy"
],
"code": 3018,
"message": "There is a relation ambiguity during the migration. Please first name the old relation on your schema. The ambiguity is on a relation between Portfolio and User. Please name relations or change the schema in steps.",
"requestId": "local:ck91xed3700bz0853u0gb4tfq"
}
],
"status": 200
}
Ethan Pursley
04/15/2020, 11:07 PMtype Portfolio {
user: User
}
you’ll need to name the relationEthan Pursley
04/15/2020, 11:08 PMtype Portfolio {
user: User! @relation(name: "PortfolioToUser", onDelete: CASCADE)
}
Ethan Pursley
04/15/2020, 11:08 PMCharlie Meaden
04/15/2020, 11:24 PMCharlie Meaden
04/15/2020, 11:26 PMtype Portfolio {
id: ID! @id
name: String!
description: String!
seedCurrency: Currency!
seedBalance: Float!
cashBalance: Float!
founder: User! @relation(name: "PortfolioToUser")
patrons: [User] @relation(name: "PatronsToPortfolios", onDelete: SET_NULL)
microFunds: [MicroFund!]! @relation(name: "MicroFundToPortfolio")
snapShots: [SnapShot!]! @relation(name: "SnapShotToPortfolio")
createdAt: DateTime! @createdAt
updatedAt: DateTime! @updatedAt
}
type User {
id: ID! @id
createdAt: DateTime! @createdAt
updatedAt: DateTime! @updatedAt
username: String! @unique
email: String! @unique
password: String!
status: UserAccountStatus! privileges: [Privilege!]! @scalarList(strategy: RELATION) portfolios: [Portfolio!]! @relation(name: "PortfolioToUser")
patronisedPortfolios: [Portfolio] @relation(name: "PatronsToPortfolios", onDelete: SET_NULL) # @default(value: NULL)
transactions: [StockTransaction!]! @relation(name: "TransactionToUser")
fundUpdates: [FundUpdate!]! @relation(name: "UpdateAuthorToMicroFund")
}
Ethan Pursley
04/15/2020, 11:27 PMpatrons: [User!]!
Charlie Meaden
04/15/2020, 11:28 PMEthan Pursley
04/15/2020, 11:28 PMCharlie Meaden
04/15/2020, 11:29 PMCharlie Meaden
04/15/2020, 11:29 PMEthan Pursley
04/15/2020, 11:30 PMEthan Pursley
04/15/2020, 11:30 PMsentDMs: [DirectMessage!]! @relation(name: "UserSentDMs", onDelete: CASCADE)
Charlie Meaden
04/15/2020, 11:30 PMEthan Pursley
04/15/2020, 11:31 PMsender: User! @relation(name: "UserSentDMs", link: TABLE, onDelete: SET_NULL)
Charlie Meaden
04/15/2020, 11:31 PMEthan Pursley
04/15/2020, 11:35 PMEthan Pursley
04/15/2020, 11:36 PMEthan Pursley
04/15/2020, 11:36 PMCharlie Meaden
04/15/2020, 11:40 PMCharlie Meaden
04/15/2020, 11:40 PMEthan Pursley
04/15/2020, 11:55 PMCharlie Meaden
04/15/2020, 11:57 PMCharlie Meaden
04/15/2020, 11:58 PMEthan Pursley
04/15/2020, 11:59 PM