Prisma 查询解析器失败:"invalid argument for the where selector"
Prisma Query resolver fails: "invalid argument for the where selector"
我使用 graphql yoga
服务器设置了 prisma
并且两个 GraphQL playground 都可用。
我可以成功地创建一个我现在正在尝试检索的对话。我无法让这个简单的解析器在 Yoga GraphQL Playground 中工作:
const resolvers = {
Query: {
conversation(parent: any, { id }: { id: string }, { prisma }: Context) {
return prisma.conversation( { id } )
}
},
Mutation: mutation
}
我使用了这个查询:
query getConversation {
conversation(where: {
id: "cjrqzinj4004e0a30ch4pccml"
}) {
id
title
}
}
错误信息是:
{
"data": {
"conversation": null
},
"errors": [
{
"message": "You provided an invalid argument for the where selector on Conversation.",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"conversation"
],
"code": 3040,
"requestId": "local:cjrsahjoo00ai0a30a5y8mnvp"
}
],
"extensions": {}
}
查询在 Prisma GraphQL 游乐场中有效。
这是我的数据模型:
type User {
id: ID! @unique
oauthId: String! @unique
display: String!
picture: String!
likes: [Comment!]! @relation(name: "Likes")
dislikes: [Comment!]! @relation(name: "Dislikes")
bookmarks: [Comment!]! @relation(name: "Bookmarks")
authorOf: [Comment!]! @relation(name: "Author")
starterOf: [Conversation!]! @relation(name: "Starter")
}
type Attachment {
id: ID! @unique
name: String!
createOn: DateTime!
mediaType: String!
comment: Comment! @relation(name: "Attachments")
}
type Comment {
id: ID! @unique
author: User! @relation(name: "Author")
content: String!
createDate: DateTime!
parentConversation: Conversation @relation(name: "Conversation")
parentComment: Comment @relation(name: "Replies")
comments: [Comment!]! @relation(name: "Replies")
bookmarkedBy: [User!]! @relation(name: "Bookmarks")
likedBy: [User!]! @relation(name: "Likes")
dislikedBy: [User!]! @relation(name: "Dislikes")
attachments: [Attachment!]! @relation(name: "Attachments")
}
enum ParentType {
Organization,
Portfolio,
Project,
WbsComponent,
WorkItem
}
type Parent {
id: ID! @unique
parent: String! @unique
type: ParentType!
conversations: [Conversation!]! @relation(name: "Parent")
}
type Conversation {
id: ID! @unique
parent: Parent! @relation(name: "Parent")
organization: String!
title: String!
author: User! @relation(name: "Starter")
createdOn: DateTime!
comments: [Comment!]! @relation(name: "Conversation")
}
可以尝试将 where
属性 传递给 prisma
客户端
const resolvers = {
Query: {
conversation(parent: any, { id }: { id: string }, { prisma }: Context) {
return prisma.conversation( { where: { id } )
}
},
Mutation: mutation
}
我在 Prisma 论坛上得到了答案。我做错了解构(注意 ConversationWhereUniqueInput
是 prisma 提供的类型):
export const conversation = (
parent: any,
{ where: { id } }: { where: ConversationWhereUniqueInput },
{ prisma }: Context
): ConversationPromise => {
return prisma.conversation({ id })
}
我使用 graphql yoga
服务器设置了 prisma
并且两个 GraphQL playground 都可用。
我可以成功地创建一个我现在正在尝试检索的对话。我无法让这个简单的解析器在 Yoga GraphQL Playground 中工作:
const resolvers = {
Query: {
conversation(parent: any, { id }: { id: string }, { prisma }: Context) {
return prisma.conversation( { id } )
}
},
Mutation: mutation
}
我使用了这个查询:
query getConversation {
conversation(where: {
id: "cjrqzinj4004e0a30ch4pccml"
}) {
id
title
}
}
错误信息是:
{
"data": {
"conversation": null
},
"errors": [
{
"message": "You provided an invalid argument for the where selector on Conversation.",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"conversation"
],
"code": 3040,
"requestId": "local:cjrsahjoo00ai0a30a5y8mnvp"
}
],
"extensions": {}
}
查询在 Prisma GraphQL 游乐场中有效。
这是我的数据模型:
type User {
id: ID! @unique
oauthId: String! @unique
display: String!
picture: String!
likes: [Comment!]! @relation(name: "Likes")
dislikes: [Comment!]! @relation(name: "Dislikes")
bookmarks: [Comment!]! @relation(name: "Bookmarks")
authorOf: [Comment!]! @relation(name: "Author")
starterOf: [Conversation!]! @relation(name: "Starter")
}
type Attachment {
id: ID! @unique
name: String!
createOn: DateTime!
mediaType: String!
comment: Comment! @relation(name: "Attachments")
}
type Comment {
id: ID! @unique
author: User! @relation(name: "Author")
content: String!
createDate: DateTime!
parentConversation: Conversation @relation(name: "Conversation")
parentComment: Comment @relation(name: "Replies")
comments: [Comment!]! @relation(name: "Replies")
bookmarkedBy: [User!]! @relation(name: "Bookmarks")
likedBy: [User!]! @relation(name: "Likes")
dislikedBy: [User!]! @relation(name: "Dislikes")
attachments: [Attachment!]! @relation(name: "Attachments")
}
enum ParentType {
Organization,
Portfolio,
Project,
WbsComponent,
WorkItem
}
type Parent {
id: ID! @unique
parent: String! @unique
type: ParentType!
conversations: [Conversation!]! @relation(name: "Parent")
}
type Conversation {
id: ID! @unique
parent: Parent! @relation(name: "Parent")
organization: String!
title: String!
author: User! @relation(name: "Starter")
createdOn: DateTime!
comments: [Comment!]! @relation(name: "Conversation")
}
可以尝试将 where
属性 传递给 prisma
客户端
const resolvers = {
Query: {
conversation(parent: any, { id }: { id: string }, { prisma }: Context) {
return prisma.conversation( { where: { id } )
}
},
Mutation: mutation
}
我在 Prisma 论坛上得到了答案。我做错了解构(注意 ConversationWhereUniqueInput
是 prisma 提供的类型):
export const conversation = (
parent: any,
{ where: { id } }: { where: ConversationWhereUniqueInput },
{ prisma }: Context
): ConversationPromise => {
return prisma.conversation({ id })
}