ahebwa49
04/11/2019, 6:53 AMasync order(root, args, context, info) {
//1. make sure they are logged in.
if (!context.request.userId) {
throw new Error("You must be logged in.");
}
//2. query the current order.
const order = await context.prisma.order({
id: args.id
}).$fragment(`{
user{
id
}
}`);
//3. check if they ahve the permissions to see this order
const ownsOrder = order.user.id === context.request.userId;
const hasPermissionToSeeOrder = context.request.user.permissions.includes(
"ADMIN"
);
if (!ownsOrder || !hasPermissionToSeeOrder) {
throw new Error("You don't have permissions to see this.");
}
//4. return the order.
return order;
}
ahebwa49
04/11/2019, 6:55 AMconst SINGLE_ORDER_QUERY = gql`
query SINGLE_ORDER_QUERY($id: ID!) {
order(id: $id) {
id
charge
total
createdAt
user {
id
}
items {
id
title
description
price
image
quantity
}
}
}
`;
ahebwa49
04/11/2019, 6:56 AMconst resolvers = {
Query,
Mutation,
ItemConnection: {
aggregate: (parent, args, context, info) => {
return context.prisma.itemsConnection(args).aggregate();
}
},
User: {
cart(parent, args, context, info) {
return context.prisma.user({ id: context.request.userId }).cart();
}
},
CartItem: {
item(parent, args, context, info) {
return context.prisma.cartItem({ id: parent.id }).item();
}
},
Order: {
user(parent, args, context, info) {
return context.prisma.order({ id: parent.id }).user();
}
},
Order: {
items(parent, args, context, info) {
return context.prisma.order({ id: parent.id }).items();
}
}
};
ahebwa49
04/11/2019, 6:57 AMtype Order {
id: ID! @unique
items: [OrderItem!]!
total: Int!
user: User!
charge: String!
createdAt: DateTime!
updatedAt: DateTime!
}
ahebwa49
04/11/2019, 7:04 AMboennemann
04/11/2019, 10:05 AM.$subscribe
? This one here is a bit to basic for me: https://www.prisma.io/docs/prisma-client/features/realtime-JAVASCRIPT-rsc8/ It doesn't paint a really good picture of all the possible options, and I can't find them documented anywhere. I'm trying to do subscriptions and get information on which fields changed. Right now I'm just getting the full object, with no indication of what actually changed ⦠and that's a bit useless. Thanks for any pointers šNelson Pecora
04/11/2019, 2:27 PMNelson Pecora
04/11/2019, 2:27 PMtype Action {
id: ID! @unique
event: EventType! @default(value: "CREATED")
userID: String! # TODO: Pull user data from other db.
timestamp: DateTime!
state: Json!
}
ahebwa49
04/11/2019, 2:57 PM[GraphQL error]: Message: Could not find argument user for type Order, Location: [object Object],
ahebwa49
04/11/2019, 2:57 PMahebwa49
04/11/2019, 2:58 PMahebwa49
04/11/2019, 3:00 PMorders(root, args, context, info) {
const { userId } = context.request;
if (!userId) {
throw new Error("You must be logged in to do this");
}
return context.prisma.orders({
user: { id: context.request.userId }
});
}
ahebwa49
04/11/2019, 3:01 PMconst USER_ORDERS_QUERY = gql`
query USER_ORDERS_QUERY {
orders(orderBy: createdAt_DESC) {
id
total
createdAt
items {
id
title
description
price
quantity
image
}
}
}
`;
ahebwa49
04/11/2019, 3:03 PMorders
field in the schema on the query root type type Query {
users: [User]!
items(
where: ItemWhereInput
orderBy: ItemOrderByInput
skip: Int
first: Int
): [Item!]!
item(id: ID!): Item
profile: User
itemsConnection(where: ItemWhereInput): ItemConnection!
cart(where: CartItemWhereUniqueInput!): CartItem!
order(id: ID!): Order
orders(orderBy: OrderOrderByInput): [Order]!
}
ahebwa49
04/11/2019, 3:03 PMtype Order {
id: ID! @unique
items: [OrderItem!]!
total: Int!
user: User!
charge: String!
createdAt: DateTime!
updatedAt: DateTime!
}
ahebwa49
04/11/2019, 3:04 PMAlex
04/11/2019, 3:37 PMschickling
04/11/2019, 4:59 PMthecrazyhoodie
04/11/2019, 5:02 PMdnbkr
04/11/2019, 5:15 PMSaidy Barry
04/11/2019, 5:29 PMNelson Pecora
04/11/2019, 5:59 PMNelson Pecora
04/11/2019, 5:59 PMNelson Pecora
04/11/2019, 6:01 PMNelson Pecora
04/11/2019, 6:03 PMAndy Dietler
04/11/2019, 6:38 PMrwatts3
04/11/2019, 7:09 PMJames
04/12/2019, 6:25 AMquery.replace(/\s+/g, ' ')
in my javascript client and haven't had any problems, but I don't perfectly understand the requirements on the server and wonder if I will run into unexpected bugs later.sid bhatta
04/12/2019, 7:00 AMJames
04/12/2019, 7:05 AM