Albert Gao
09/07/2020, 6:10 AMmikkelsl
09/07/2020, 2:57 PMMatt
09/09/2020, 12:38 AMMichael
09/09/2020, 10:29 AMctx.res
or like in Apollo Server
return new AuthenticationError("Not authorised");?
I couldnāt find anything about it in the nexus documentation.Wade Tandy
09/10/2020, 9:45 PMcontext.setCustomer('1234')
//... later on
post.findOne({id: 5678})
the resulting query would be
SELECT * FROM posts
WHERE id = 5678 AND customer_id = 1234
This will work no matter where I do the query, as long as it is in the context of a request that has run setCustomer
, which allows our resolvers to not worry about missing an important scoping of user data. Can anyone think of a way this can be done with prisma + nexus?Kohki Shiga
09/13/2020, 4:26 AMThe change you are trying to make would violate the required relation 'DrinkingLocationsToUser' between the `DrinkingLocations` and `User` models.
Prisma/schema.prisma
model User {
id String @default(cuid()) @id
username String
password String
drinkingLocation DrinkingLocations
profile Profile
}
model DrinkingLocations {
id String @default(cuid()) @id
locationName String
longtitude Float
latitude Float
createdAt DateTime @default(now())
user User @relation(fields: [userId], references: [id])
userId String
}
graphql/schema.ts (Nexus side)
schema.objectType({
name: 'User',
definition(t) {
t.string('id', { description: 'Id of the user' });
t.string('username', { description: 'Name of the user' });
t.string('password', { description: 'Encrypted password' });
t.field('DrinkingLocations', {
type: 'DrinkingLocations',
});
t.field('Profile', {
type: 'Profile',
});
},
});
schema.objectType({
name: 'DrinkingLocations',
definition(t) {
t.string('id', { description: 'Id of the Drinking location' });
t.string('locationName', { description: 'Name of the Drinking Location' });
t.float('longtitude', { description: 'Longtitude of the Drinking ' });
t.float('latitude', { description: 'Latitude of the Drinking Location' });
t.date('createdAt', { description: 'Time when the user started drinking' });
t.string('userId', { description: 'Foreign key to User' });
t.field('user', {
type: 'User',
});
},
});
schema.mutationType({
definition(t) {
t.crud.createOneUser();
t.crud.createOneDrinkingLocations();
t.crud.createOneProfile();
},
});
Venu
09/14/2020, 9:52 AMPieter
09/15/2020, 4:29 PMKohki Shiga
09/16/2020, 9:23 AMPieter
09/16/2020, 10:58 AMPieter
09/16/2020, 1:17 PMlewebsimple
09/17/2020, 3:45 AMlewebsimple
09/17/2020, 3:46 AMlewebsimple
09/17/2020, 3:46 AM##[error]src/framework/settings.ts(2,54): error TS2307: Cannot find module '@prisma/client/runtime/getPrismaClient' or its corresponding type declarations.
lewebsimple
09/17/2020, 3:49 AM@prisma/client/runtime
exports everything from index.d.ts in version 2.7.1 (i.e. no .../runtime/getPrismaClient.d.ts)lewebsimple
09/17/2020, 3:49 AMinterface GetPrismaClientOptions
is not exported šMichael Gardner
09/17/2020, 6:40 PMJustin Voitel
09/18/2020, 12:09 AMThevy N
09/18/2020, 7:30 AMreturn ctx.prisma.user.findMany({
where: {
email: {
contains: '<http://prisma.io|prisma.io>',
},
},
include: {
posts: {
where: {
published: false,
},
},
},
orderBy: {
name: 'asc',
},
})
Albert Gao
09/19/2020, 5:34 AMAlbert Gao
09/19/2020, 7:17 AMWithout a database
option, is there an in-memory database? How to seed it?Albert Gao
09/20/2020, 4:58 AMdelet
in afterAll
is not working:The user is still in the database, what I did wrong?Ahmar Suhail
09/21/2020, 3:23 PM[4:22 PM] prisma:query SELECT "public"."conversations"."uuid", "public"."conversations"."booking_id", "public"."conversations"."created", "public"."conversations"."event_request_id", "public"."conversations"."last_message_timestamp", "public"."conversations"."supplier_id", "public"."conversations"."updated" FROM "public"."conversations" WHERE ("public"."conversations"."last_message_timestamp" IS NOT NULL AND "public"."conversations"."supplier_id" = $1) ORDER BY "public"."conversations"."last_message_timestamp" DESC, "public"."conversations"."uuid" ASC OFFSET $2
prisma:query SELECT "public"."conversations_messages"."uuid", "public"."conversations_messages"."content", "public"."conversations_messages"."conversation_id", "public"."conversations_messages"."created", "public"."conversations_messages"."old_message_id", "public"."conversations_messages"."sender_user_id", "public"."conversations_messages"."type", "public"."conversations_messages"."updated", "public"."conversations_messages"."conversation_id" FROM "public"."conversations_messages" WHERE "public"."conversations_messages"."conversation_id" IN ($1) ORDER BY "public"."conversations_messages"."created" DESC, "public"."conversations_messages"."uuid" ASC OFFSET $2
[
{
content: "Hello Hello",
conversation_id: '160ad9a9-56e6-4894-a2a7-94200a03c2c0',
created: 2020-09-19T21:46:20.150Z,
updated: 2020-09-19T21:46:20.150Z,
uuid: '19eb6f94-9a04-4603-853b-f5ccf37f3524'
},
]
// These queries are executed after console.log
prisma:query SELECT "public"."conversations"."uuid" FROM "public"."conversations" WHERE "public"."conversations"."uuid" = $1 LIMIT $2 OFFSET $3
prisma:query SELECT "public"."conversations_messages"."uuid", "public"."conversations_messages"."content", "public"."conversations_messages"."conversation_id", "public"."conversations_messages"."created", "public"."conversations_messages"."old_message_id", "public"."conversations_messages"."sender_user_id", "public"."conversations_messages"."type", "public"."conversations_messages"."updated", "public"."conversations_messages"."conversation_id" FROM "public"."conversations_messages" WHERE "public"."conversations_messages"."conversation_id" IN ($1) OFFSET $2
The resolver seems to be returning data from these second set of queries instead of the first and I can't figure out what's causing the second set of queries to execute? Any help would be really appreciated! :)Ahmar Suhail
09/21/2020, 3:23 PMmodel conversations {
created DateTime?
last_message_timestamp DateTime?
supplier_id String?
uuid String @id
conversations_messages conversations_messages[]
}
model conversations_messages {
content String
conversation_id String
created DateTime?
sender_user_id String
uuid String @id
conversations conversations @relation(fields: [conversation_id], references: [uuid])
I want to get all conversations a supplier has, and last received message in each conversation_id.Ā For this, I've written a custom resolver:
schema.extendType({
type: 'Query',
definition(t) {
t.crud.conversations({filtering: true, ordering: true})
t.list.field('supplierConversations', {
type: "conversations",
args: {
supplier_id: schema.stringArg()
},
resolve: async(_root, args, ctx) => {
const x = await ctx.db.conversations.findMany({
where: {
supplier_id: { equals: args.supplier_id },
last_message_timestamp: {not: null}
},
orderBy: {
last_message_timestamp: 'desc'
},
include: {
conversations_messages: {
orderBy: {created: 'desc'},
}
}
})
console.log(x[0].conversations_messages);
return x;
}
})
},
})
And my graphQl query is
{
supplierConversations(supplier_id: "001C768B-6BD6-4C87-90E1-E8C7B9A580C4") {
conversations_messages {
created
}
}
}
However, this doesn't return the expected result. When I do console.log(x[0].conversations_messages), the messages are in the correct order (with the most recent created date being first). But data returned by this resolver is not in this format.
Two additional queries are executed after the console.log statement. Logging prisma queries gives the following output:iloveprisma
09/22/2020, 8:37 AMiloveprisma
09/22/2020, 8:37 AMiloveprisma
09/22/2020, 8:38 AMiloveprisma
09/22/2020, 8:38 AMiloveprisma
09/22/2020, 8:46 AMAhmar Suhail
09/22/2020, 11:30 AMschema.objectType({
name: 'conversations',
definition(t) {
t.model.uuid()
t.model.conversations_messages({ ordering: true })
t.model.conversations_users()
t.model.last_message_timestamp()
t.model.event_requests()
t.int('unreadCount', {
args: {
supplier_id: schema.stringArg(),
user_id: schema.stringArg()
},
resolve: (conversation, args, ctx) => {
//dummy return value
return 5
}
})
}
})
I want to get all conversations which have unreadCount as 0. Is it possible to filter based on a field which is calculated through a custom resolver?