Theo Browne
05/30/2022, 8:36 PMselect
and include
? Seems like it breaks type inference pretty hard. Cut an issue about it here: https://github.com/prisma/prisma/issues/13571Ulises Viña
05/30/2022, 9:05 PMUnknown arg `id` in data.following.connect.id for type FollowsWhereUniqueInput. Available args:
type FollowsWhereUniqueInput {
followerId_followingId?: FollowsFollowerIdFollowingIdCompoundUniqueInput
}
EDIT: I did try to use the followerId_followingId argument in the connect object, but when using it, a different error appears saying it expected type FollowsFollowerIdFollowingIdCompoundUniqueInput but received String.hoe
05/31/2022, 1:44 AMPHANTOM KNIGHT
05/31/2022, 9:05 AMgenerator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model Organisation {
id Int @id @default(autoincrement())
name String @unique
slogan String
logoUrl String?
organisationId String @unique
juniorAdmins JuniorAdmin[]
}
model JuniorAdmin {
id Int @id @default(autoincrement())
name String
number BigInt
photoUrl String?
password String
email String
Organisation Organisation? @relation(fields: [id], references: [id])
}
This is working fine when I add the first entry but when I add more of them I get this errorPHANTOM KNIGHT
05/31/2022, 9:07 AMBrothak
05/31/2022, 9:08 AMPlanning Time: 2.072 ms
Execution Time: 186.830 ms
Brothak
05/31/2022, 9:08 AMBrothak
05/31/2022, 9:08 AMTeerapat
05/31/2022, 10:08 AMDATABASE_URL
DATABASE_URL="<mysql://MY_USER:MY_PASSWORD@localhost/MY_DB?socket=/cloudsql/inbound-BLAH-BLAH-BLAH>"
But I got error as picture below. Any suggestion?Berian Chaiwa
05/31/2022, 11:46 AMprovince
query that might include districts
or not, depending on whether we requested for it. But my Prisma
query for the resolver always includes it in the result, regardless of whether the user wants it or not. Isn't this overfetching?:
Query.ts
function province(_: any, args: any, context: any) {
return context.prisma.province.findUnique({
include: {districts: true},
where: {
id: args.id,
},
});
}
graphql.schema
type Query {
province(id: ID!): Province!
}
type Province {
id: ID!
code: String!
name: String!
country_id: String
country: Country
districts: [District!]!
created_at: String!
created_by: String!
last_modified_at: String!
last_modified_by: String!
}
type District {
id: ID!
name: String!
code: String!
province_id: String!
province: Province!
created_at: String!
created_by: String!
last_modified_at: String!
last_modified_by: String!
}
GraphQL Query that needs districts
query Query($provinceId: ID!){
province(id: $provinceId) {
code
name
districts {
code
name
}
}
}
GraphQL Query that does not need districts but still hits the same resolver
(Prisma loads districts that are not needed by the client) How can I solve this?
query Query($provinceId: ID!){
province(id: $provinceId) {
code
name
}
}
Michael Roberts
05/31/2022, 1:46 PMGe Yang
05/31/2022, 1:57 PM$runCommand
escape hatch?
In Mongo I can write a query that looks like the following:
db.students.update(
{ name: "joe" },
{ $push: { scores: { $each: [ 90, 92, 85 ] } } }
)
and this will give me the following object:
students: {
name: "joe",
scores: [100, 99, 90, 92, 85 ]
}
What I Have Tried
First of all, iterating through the list items item-by-item is infeasible for our application. The example here is simple, but the list items in our application is larger.
So I tried to use $runCommandRaw
let rawQuery = {
insert: "Student",
bypassDocumentValidation: false,
documents: [
text
? {text, deltas}
: {scores: {$push: {$each: deltas}}}
]
}
}
newText = await context.prisma.$runCommandRaw(rawQuery)
How do I do this with Prisma-js? @Nurul @janpioHarsh Singh
05/31/2022, 11:21 PMSiddharth Sharma
06/01/2022, 12:56 AMconst posts = await db.post.findMany({
...paginateArgs,
where: {
galleryId: galleryId,
},
include: { images: true },
orderBy,
})
posts array has many posts (obviously)
and the post essentially has a child array called images
. I’d like to add a computed field called url
to this images array
, and retain type safety on this. I debated adding URL to the DB as a dummy field but that doesnt really sound correct to me. I’m sure im over complicating things, so im curious what the best route to do this is.Chris Tsongas
06/01/2022, 1:06 AMurl
field but computing the value beforehand using JS whenever you do an insert or update. You could write a helper function to do that so it's sure to be consistent.Jonas
06/01/2022, 9:21 AMfindMany()
and return only results where that field has a value. What do I need to do for that?Manish
06/01/2022, 11:00 AMtrial_ends_on DateTime?
I want to set the default value of this to be 14 days from today.
If I was setting it to now, I would add it as follows:
trial_ends_on DateTime? @default(now())
However, instead of now, I actually want to add a date which is 14 days from now. How can I do this with default value?Berian Chaiwa
06/01/2022, 12:14 PMfindUnique
with multiple args and only enable case insensitive
on some of them. I have tried the below but I am getting the error as :
"Argument code: Got invalid value ",
"{",
" equals: 'ZM',",
" mode: 'insensitive'",
"}",
"on prisma.findUniqueCountry. Provided Json, expected String.",
And my query looks like:
country: (_parent: unknown, args, context) => {
return context.prisma.country.findUnique({
where: {
id: args.id || undefined,
code:
args.code ? {
equals: args.code,
mode: "insensitive",
} : undefined,
name:
args.name ? {
equals: args.name,
mode: "insensitive",
} : undefined,
},
});
},
foreverjunior
06/01/2022, 2:16 PMinterface ModelC {
...
}
Interface ModelB extends ModelC {
...
}
Interface ModelA extends ModelB {
...
}
Michael Roberts
06/01/2022, 3:39 PMBerian Chaiwa
06/01/2022, 10:01 PMcontext
. I am using Apollo-Server
with Prisma
and code-generator
for resolver types. The args are type-safe and I can auto-complete in resolvers but I can't do so with context
. In the resolver if I set the context: GraphQLContext
I am getting the below errors but it works without the context type. Here is the error:
Type '(_root: {}, { id, code, name }: Partial<QueryCountryArgs>, context: GraphQLContext) => Prisma__CountryClient<Country | null>' is not assignable to type 'Resolver<Maybe<ResolverTypeWrapper<Country>>, {}, any, Partial<QueryCountryArgs>> | undefined'.
And here is how I am setting up the server and declaring /instantiating the context:
import fs from "fs";
import path from "path";
import { ApolloServer } from "apollo-server-express";
import { ApolloServerPluginDrainHttpServer } from "apollo-server-core";
import { makeExecutableSchema } from "@graphql-tools/schema";
import { WebSocketServer } from "ws";
import { useServer } from "graphql-ws/lib/use/ws";
import { PrismaClient } from "@prisma/client";
import express, { Request } from "express";
import http from "http";
import {
typeDefs as scalarTypeDefs,
resolvers as scalarResolvers,
} from "graphql-scalars";
import { GraphQLSchema } from "graphql";
import { resolvers } from "./api/resolvers/resolvers";
const prisma = new PrismaClient();
export type GraphQLContext = {
req: Request;
prisma: PrismaClient;
};
export async function createContext(
req: Request,
prismaClient: PrismaClient
): Promise<GraphQLContext> {
return {
req,
prisma: prismaClient,
};
}
const typeDefs = fs.readFileSync(
path.join(path.resolve(), "src/api/schema.graphql"),
"utf-8"
);
const schema = makeExecutableSchema({
typeDefs: [typeDefs, ...scalarTypeDefs],
resolvers: { ...resolvers, ...scalarResolvers },
});
async function startApolloServer(
gqlSchema: GraphQLSchema,
prismaClient: PrismaClient
) {
const app = express();
// 1. Http Server
const httpServer = http.createServer(app);
// 2. Websocket Server
const wsServer = new WebSocketServer({
server: httpServer,
path: "/",
});
const wsServerCleanup = useServer({ schema: gqlSchema }, wsServer);
// 3. Apollo Server
const server = new ApolloServer({
schema,
context: ({ req }) => {
return createContext(req, prismaClient);
},
csrfPrevention: true,
plugins: [
// Proper shutdown for the HTTP server.
ApolloServerPluginDrainHttpServer({ httpServer }),
// Proper shutdown for the websocket server
{
async serverWillStart() {
return {
async drainServer() {
await wsServerCleanup.dispose();
},
};
},
},
],
});
await server.start();
server.applyMiddleware({
app,
});
// Modified server startup
await new Promise<any>((resolve: any) =>
httpServer.listen({ port: 4000 }, resolve)
);
console.log(`🚀 Server ready at <http://localhost:4000>${server.graphqlPath}`);
}
startApolloServer(schema, prisma);
And my resolvers fail when I do this:
country: (_root, { id, code, name }, context: GraphQLContext) => { // fails when this type is applied here
return context.prisma.country.findUnique({
where: {
id: id || undefined,
code: code || undefined,
name: name || undefined,
},
});
},
YeonHoPark
06/02/2022, 1:19 AMJosue Quinteros
06/02/2022, 4:58 AMJeremy Monson
06/02/2022, 5:23 AMprisma migrate deploy
on my production database. The command has been running for over 15 minutes, and all it is doing is dropping a unique index. Is this normal? What do i do?
It's stuck in the "Applying Migration" stateThangavel P
06/02/2022, 6:05 AMAdam Boulila
06/02/2022, 3:08 PMreturn this.prismaService.employeeOrderItem.update(
The column `(not available)` does not exist in the current database.
why is prisma unable to tell me the column nameNatalia
Eric Kreis
06/02/2022, 4:07 PMZakaria Mofaddel
06/02/2022, 6:19 PMJohn Smeeth
06/03/2022, 1:10 AM