Nima Shoghi
08/02/2021, 4:21 PMPavel Vorontsov
08/02/2021, 8:17 PMconst typeDefs = `
type Query {
hello(name: String): String!
}
`
const resolvers = {
Query: {
hello: (_, { name }) => `Hello ${name || 'World'}`,
},
}
const server = new GraphQLServer({ typeDefs, resolvers })
but I get following
{
"error": "Unexpected token < in JSON at position 0"
}
Any help?
ThanksJay Bell
08/02/2021, 8:32 PMprisma db push
I get
{
"timestamp": "2021-08-02T17:27:04.778303482+00:00",
"level": "ERROR",
"fields": {
"is_panic": false,
"error_code": "P1003",
"message": "Database `<db name>.public` does not exist on the database server at `localhost:5432`."
},
"target": "migration_engine::logger"
}
Shouldn't it create the db if it doesn't already exist? It does on another step in CI (and locally) which is weird... the step that does not work is using docker executor and the one that does work is using ubuntu machine executor (both on circleci)
Anyone have any ideas here? I am at a loss.
This is a fresh postgres instance (using docker-compose up
) so no DBs
(Cross posted as I didn't notice general had 58x the members as the other channel!)user
08/03/2021, 5:07 AMOluwasetemi Ojo
08/03/2021, 9:34 AMOluwasetemi Ojo
08/03/2021, 9:46 AMDaan Helsloot
08/03/2021, 10:54 AMVladi Stevanovic
Georg Wagner
08/03/2021, 12:35 PMPeter Kellner
08/03/2021, 7:34 PMXOR<UserSelect,null>.
That syntax means nothing to me. Is there some page that explains this syntax? I get from the example that somehow, it relates to where: {id: 1}... but I just don't see the connection and normally, I'm not the dumbest pencil in the box (so I had thought)Casey Graff
08/03/2021, 11:29 PMwhere
block in a Prisma *Unique
operation?
In our case, we have a tenantId
on a model and would like users to only be able to read/edit/delete objects with a tenantId
that matches the tenant they belong to. Ideally, we could just pass the tenantId
along with a unique field (like id
) e.g. prisma.model.findUnique({where: {id: <id>, tenantId: <tenantId>}})
. For finds, this isn't really an issue because you can always check the tenantId
after you fetch the object, but for mutations, it currently requires either, fetching the object first, verifying it's tenantId
and then performing the mutation, or using a Prisma updateMany
or deleteMany
and passing both the id
and tenantId
into the where
block of the *Many
operation. Using a *Many
operation concerns me a bit because if the id
is ever undefined
the operation would then apply to significantly more objects than intended; whereas a *Unique
operation would just fail.
I'm going to guess that Prisma doesn't support this as they use the *Many
trick in the soft-deletion middleware docs (here). One workaround we've found is that you can add a @@unique
constraint to id
+ tenantId
(e.g. @@unique([id, tenantId])
). This then allows you to perform any *Unique
operation against an id
+ tenantId
pair. Is this the best way to do this as we are now introducing an additional index? Alternatively, you could make it a composite id with @@id([id, tenantId])
, but then id
field would no longer be required to be unique unless you additionally added @unique
to the id
field. Has anyone used any of these method and found something they recommend?Zestian
08/04/2021, 12:37 AMMateusz Żmijewski
08/04/2021, 11:07 AMRahul Agrawal
08/04/2021, 11:20 AMschema.prisma
based on env variable
But typescript complains that it is not allowed
Is there any way to achieve this?Georg Wagner
08/04/2021, 12:10 PMGeorg Wagner
08/04/2021, 12:15 PMuser
08/04/2021, 2:24 PMIvan Lukianchuk
08/04/2021, 8:03 PMticketId
in data.ticketId for type TemplateItemCreateInput. Did you mean ticket
?
Argument ticket for data.ticket is missing.
const creation = await prisma.templateItem.create({
data: {
ticketId: ticket.id
}
});
And here is the simplified schema:
model TemplateItem {
id Int @id @default(autoincrement())
ticket Ticket @relation(fields: [ticketId], references: [id])
ticketId Int
}
model Ticket {
id Int @id @default(autoincrement())
templateTicketId TemplateItem?
}
I've removed extra stuff that isn't important to simplify the code
So if I've got a 1-1 relationship setup, why won't it let me pass in the ticketId? It sounds like it doesn't even understand that it's in the schema, yet it's clearly there and worked before. Am I missing something or did something change?
I want to make a TemplateItem and reference the id of the existing Ticket.Kent C. Dodds
08/04/2021, 9:00 PMfindUnique
with an include
resulted in two queries rather than one SQL query. Am I doing something wrong/misunderstanding something?
const session = await prisma.session.findUnique({
where: {id: sessionId},
include: {user: true},
})
Results in:
SELECT "public"."Session"."id", "public"."Session"."createdAt", "public"."Session"."userId", "public"."Session"."expirationDate" FROM "public"."Session" WHERE "public"."Session"."id" = $1 LIMIT $2 OFFSET $3
SELECT "public"."User"."id", "public"."User"."createdAt", "public"."User"."updatedAt", "public"."User"."email", "public"."User"."firstName", "public"."User"."discordId", "public"."User"."convertKitId", "public"."User"."role", "public"."User"."team" FROM "public"."User" WHERE "public"."User"."id" IN ($1) OFFSET $2
Is there a reason that can't be combined into a single query?Halvor
08/04/2021, 9:01 PMKent C. Dodds
08/04/2021, 9:13 PMfindMany
it'll be able to combine it into a single query?Kent C. Dodds
08/04/2021, 9:15 PMfindMany
, then here's what I get:
SELECT "public"."Session"."id", "public"."Session"."createdAt", "public"."Session"."userId", "public"."Session"."expirationDate" FROM "public"."Session" WHERE "public"."Session"."id" = $1 OFFSET $2
SELECT "public"."User"."id", "public"."User"."createdAt", "public"."User"."updatedAt", "public"."User"."email", "public"."User"."firstName", "public"."User"."discordId", "public"."User"."convertKitId", "public"."User"."role", "public"."User"."team" FROM "public"."User" WHERE "public"."User"."id" IN ($1) OFFSET $2
The only difference is the LIMIT
🤷♂️nmw03
08/04/2021, 9:16 PMnmw03
08/04/2021, 9:18 PMfeeds
here.nmw03
08/04/2021, 9:18 PMKent C. Dodds
08/04/2021, 9:50 PMnpx prisma generate
after changing the schema?nmw03
08/04/2021, 9:58 PMnmw03
08/04/2021, 9:59 PMprisma save
🤔Kent C. Dodds
08/04/2021, 10:00 PM