Michael
08/06/2021, 8:58 PMMitchell Romney
08/10/2021, 11:00 PMTimo
08/12/2021, 6:38 AMoriginalResolve
where I can check for validity within the resolve
function and either return originalResolve
if it's valid or some default value if not. What to do?Patrick Ayres
08/13/2021, 1:19 PMnexus-plugin-prisma
and trying to determine if I am on the right track/looking for some suggestions. We have a fairly large highly relational schema, ~110 models and ~35 enums. We had our resolvers split up into separate files per model. So my method has been to go through each resolver file, convert based on the documentation (which has been very helpful!) and add input types as necessary. Basically, convert objects
, queries
and mutations
by plucking them straight from the sdl converter and then add the specific inputTypes
that are required. This has been working well except for one issue...because we have so many models and they are highly relational, there are a TON of inputTypes
that we seemingly need. I'm trying to find a sane convention for splitting these up into manageable chunks, but on some of our larger models with a lot of relationships we can have up to ~40k lines of inputTypes
🤯 so 2 questions:
1. Is there something I am just completely missing as far as adding inputTypes
when doing the conversion?
2. Any suggestions for organizing the inputTypes into manageable chunks?
a. so far I have split them into folders by model and then files by create
update
upsert
where
orderBy
but on the larger models the create
and update
files are still close to 20k lines
b. My next thought is to start splitting them further by relationship, so instead of just model-a-create-inputs.ts
have model-a-model-b-create-inputs.ts
, model-a-model-c-create-inputs.ts
etc...Тоше
08/20/2021, 8:21 AM{ name: 'SomeModelCreateNestedOneWithoutAttachmentsInput', definition: [Function: definition] }
• for a given type i want to get something like this
inputObjectType({
name: [type-name],
definition(t) {
t.[is-this-field-nullable].[is-this-field-list-type].[type]([type-name]),//descriptions etc } })
2. Is there a performance difference when doing this
a. t.nonNull.field('id', { type: 'Int' }) versus t.nonNull.int('id')Manthan Mallikarjun
08/28/2021, 5:57 AMimport { idArg, mutationField } from 'nexus';
import { withAuth } from '../../utils/auth';
export const updateUser = mutationField('updateUser', {
type: 'User',
args: {
id: idArg(),
},
authorize: withAuth,
async resolve(_parent, { id }, { res }) {},
});
Here, id
(and anything else I add) all have type of any
. I'm pretty sure I have set up the types properly, because the type: "User"
autofills with no issueManthan Mallikarjun
08/28/2021, 5:57 AMchrisdrackett
08/28/2021, 6:25 PMManthan Mallikarjun
08/29/2021, 8:44 AMManthan Mallikarjun
08/29/2021, 8:45 AMManthan Mallikarjun
08/29/2021, 8:45 AMUser
which is a custom type shows upDaniell
08/30/2021, 6:49 AMnexus-prisma
package not able to resolve relations with a composite unique id? This part in specific:
products {
id
name
productTags {
tags {
id
imageURL
}
}
}
Results in: "message": "Unable to resolve a unique identifier for the Prisma model: ProductTag",
model ProductTag {
productId Int @map("product_id") @db.UnsignedInt
tagId Int @map("tag_id") @db.UnsignedInt
products Product @relation(fields: [productId], references: [id])
tags Tag @relation(fields: [tagId], references: [id])
@@id([productId, tagId])
@@index([productId], name: "products_tags_product_id_foreign")
@@index([tagId], name: "products_tags_tag_id_foreign")
@@map("products_tags")
}
export const productTag = objectType({
name: ProductTag.$name,
description: ProductTag.$description,
definition(t) {
t.field(ProductTag.tags)
},
})
Basically a many to many relationDaniell
09/01/2021, 11:31 AMDaniell
09/01/2021, 1:39 PM8.52s
to execute because of this, is there a way I can optimise?
export const Product = objectType({
name: _Product.$name,
description: _Product.$description,
definition(t) {
t.field(_Product.id)
t.field(_Product.name)
t.field(_Product.description)
t.field(_Product.imageURL)
t.field("tags", {
type: list("Tag"),
async resolve(parent, _, ctx) {
const productTags = await ctx.prisma.productTag.findMany({
where: {
productId: parent.id,
},
include: {
tags: true,
},
})
return productTags.map((pt) => pt.tags)
},
})
},
})
Jonas Rothmann
09/03/2021, 9:03 AMresolve: async (_parent, args, context: Context) => {
return await context.prisma.customer.findFirst({ where: { id: 11 }, include: { visits: { where: { status: "completed" } } } })
}
When I console.log it, it only returns the ones I want, that makes me confused about how the relational data is resolved, since it apparently ignores the ones returned in the resolver?Daniell
09/06/2021, 3:51 PMI just gave it a try and it seems to me like you can “have yourWhat are your thoughts on this?and eat it too“ by just having both.crud
and@kenchi/nexus-plugin-prisma
as dependencies in package.json. Their respective configuration and build-time behavior don't appear to interfere with each other, and you can donexus-prisma
in your `objectType`s andt.field()
in your `queryType`s.t.crud.User()
Josef Henryson
09/08/2021, 9:02 AMHector
09/09/2021, 1:18 AMDmitri Pisarev
09/13/2021, 6:03 AMwhere
query arg to my list field, and I really don’t want to type it manually. Has anyone any examples how you define such stuff?Andrew Ross
09/14/2021, 7:51 AMDaniell
09/15/2021, 8:24 AMDaniell
09/15/2021, 8:32 AMDmitri Pisarev
09/17/2021, 5:41 AMposts
to which users are allowed to append posts. This collection has a relation to collection users
, in which users are not supposed to be allowed to make any modifications.
How do I secure users
from all the dangerous things inside PostCreateInput
, e.g. {data: {user: {create: {name: “You’ve been hacked”}}}}
?
By manually checking all the data.user.create || data.user.connectOrCreate
and throwing? Is there some sort of more declarative way to do this? How you people are handling this?
Basically I’m looking for some declarative layer for security, e.g. saying “these dudes are not allowed to modify this collection”, and probably it has to be somewhere on Prisma side.Andrew Ross
09/19/2021, 2:42 AMnexus.tsconfig.json
instead of tsconfig.nexus.json
TS Intellisense doesn't pick up on the file when named the former but it does when named the latter
why do example repos/other repos use the former if TS isn't detecting it as a tsconfig.json file?
is there some abstraction layer under the hood parsing happening?Andrew Ross
09/19/2021, 5:45 AMglobal.prisma || new PrismaClient()
as typeof Context, then on success it's appended to the previewData body of the ensuing NextApiResponse res
before the PrismaClient is ultimately returned as Promise wrapped Context?
Thoughts?cedric
09/30/2021, 10:14 PMJames Homer
10/01/2021, 9:13 AMJames Homer
10/01/2021, 9:14 AMImage
& ImageExtended
James Homer
10/01/2021, 9:38 AMextendType
work with types other than ’Query`?Josef Henryson
10/06/2021, 12:06 PM