wuichen
02/20/2019, 10:03 AMtype Product @model {
id: ID! @unique
objectID: String! @unique
title: String!
vendor: String
productType: String
categories: [String!]!
hierarchicalCategories: Json
createdAt: DateTime!
updatedAt: DateTime!
productTags: [String!]!
price: Float
priceRange: String
productImage: String
handle: String
sites: [Site!]! @relation(name: "SitesProducts")
}
type Site @model {
id: ID! @unique
createdAt: DateTime!
name: String!
posts: [Post!]! @relation(name: "SiteOnPost")
products: [Product!]! @relation(name: "SitesProducts")
template: String
user: User! @relation(name: "UserOnSite")
}
wuichen
02/20/2019, 10:04 AMasync addProduct(parent, args, context) {
const productExists = await context.prisma.$exists.product({
id: args.productId
});
const siteExists = await context.prisma.$<http://exists.site|exists.site>({
id: args.siteId
});
console.log(productExists, siteExists);
return context.prisma.updateProduct({
data: {
sites: {
connect: {
id: args.siteId
}
}
},
where: {
id: args.productId
}
});
},
wuichen
02/20/2019, 10:04 AMwuichen
02/20/2019, 10:05 AMwuichen
02/20/2019, 10:05 AM{
"data": {
"addProduct": {
"id": "cjscyznfh00m00855o231856w",
"sites": null
}
}
}
Brian
02/20/2019, 11:12 AMposts: forwardTo('db')
What’s the best approach to handle this?ahebwa49
02/20/2019, 12:17 PMahebwa49
02/20/2019, 12:18 PMlewisedc
02/20/2019, 1:34 PMdan
02/20/2019, 2:35 PMdan
02/20/2019, 2:36 PMLars-Jørgen Kristiansen
02/20/2019, 2:38 PMquery {
workspaces {
id
title
workers {
id
name
}
}
}
Resolvers:
{
Query: {
workspaces: (parent, args, ctx) => {
return ctx.prisma.workspaces();
}
},
Workspace: {
workers: (parent, args, ctx) => {
return ctx.prisma
.workspace({
id: parent.id
})
.workers();
}
}
}
But looking at the debug output it does'nt seem to solve the problem at all:
Query:
{
workspaces {
id
title
}
}
Query:
query ($where: WorkspaceWhereUniqueInput!) {
workspace(where: $where) {
workers {
id
name
}
}
}
Variables:
{"where":{"id":"cjsd9u584000b07629ei22dpc"}}
Query:
query ($where: WorkspaceWhereUniqueInput!) {
workspace(where: $where) {
workers {
id
name
}
}
}
Variables:
{"where":{"id":"cjsdab6s8000p0762vxhtca4d"}}
Am i doing something wrong?Luca
02/20/2019, 2:49 PMLars-Jørgen Kristiansen
02/20/2019, 2:53 PMPrisma client has a built-in dataloader, solving the N+1 problem and ensuring the Prisma API is queried efficiently.
Uby
02/20/2019, 3:12 PMrem
02/20/2019, 4:01 PMdortega3000
02/20/2019, 4:09 PMahebwa49
02/20/2019, 4:57 PMahebwa49
02/20/2019, 4:57 PM{
"data": null,
"errors": [
{
"message": "context.request.get is not a function",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"profile"
]
}
]
}
ahebwa49
02/20/2019, 4:58 PMahebwa49
02/20/2019, 4:58 PMimport jwt from "jsonwebtoken";
import { Context } from ".";
export const APP_SECRET = "GraphQL-is-awesome";
export function getUserId(context: Context): string {
const bearerToken = context.request.get("Authorization");
if (!bearerToken) {
throw new Error("Not Authenticated");
}
const token: string = bearerToken.replace("Bearer", "");
const userId: string = jwt.verify(token, APP_SECRET) as string;
return userId;
}
ahebwa49
02/20/2019, 4:59 PMJon
02/20/2019, 5:55 PMtiagomarques
02/20/2019, 8:29 PMtiagomarques
02/20/2019, 8:31 PMLars-Jørgen Kristiansen
02/20/2019, 9:26 PMMatthew Frey
02/21/2019, 12:31 AMMatthew Frey
02/21/2019, 12:31 AMtafelito
02/21/2019, 4:04 AMMartí Crespí
02/21/2019, 8:23 AMtype
string property, and creating a new one based on an enum. But when I try a query, when it's parsing the response, it throws an error.
"Expected a value of type \"CostType\" but received: \"MAINTENANCE\"",
because it's not converting the string to the enum. How can I do it in its resolve function to convert this string to its enum?