Ich versuche, ein Abonnement zurückzukehren, die aus folgendem besteht:Wie übergibt man die Werte einer Verbindung an ein Abonnement?
const postsSubscription = gql`
subscription postAdded {
postAdded {
id
title
description
author{
name
}
}
}
`
Was passiert ist, dass Autor Art von Benutzer ist, und ich gehe gerade einen authorid. Das bedeutet, dass ich nicht den Namen des Autors, wenn ich die Post erstellen:
createPost: async (root, req, { posts }) => {
const Item = {
id: uuid.v4(),
authorId: '565dbdc0-36f2-4bba-be67-c126d0c71fff',
...req
}
await posts.create({ Item })
pubsub.publish('postAdded', { postAdded: Item })
return Item
},
Hier ist der Autor Resolver:
Post: {
author: async({ authorId }, req, { users }) => {
const Key = { id: authorId }
const { Item } = await users.get({ Key })
return Item
}
}
Hier ist das Schema:
type Post {
id: ID
title: String
description: String
author: User @relation(name: "PostAuthor")
}
type User {
id: ID
name: String
email: String
password: String
posts: [Post] @relation(name: "UserPosts")
}
type PostPayload {
post: Post
}
type CreateUserPayload {
user: User
}
type Query {
allPosts: [Post]
allUsers: [User]
post(id: ID!): Post
user(id: ID!): User
}
type Mutation {
createPost(input: CreatePostInput!): PostPayload
updatePost(input : UpdatePostInput!): PostPayload
createUser(input : CreateUserInput!): CreateUserPayload
}
type Subscription {
postAdded: Post
}
input CreatePostInput {
title: String!
description: String!
}
input UpdatePostInput {
id: ID!
title: String!,
description: String!
}
input CreateUserInput {
name: String!
email: String!
password: String!
}
schema {
query: Query
mutation: Mutation
subscription: Subscription
}
So , meine Frage ist, wie alle erforderlichen Felder (einschließlich der Verbindungen) an das Abonnement übergeben werden?
Wird dieser Feld-Resolver aufgerufen? Kannst du eine Reproduktion erstellen oder das Schema teilen? – Urigo
Da gehts los @Urigo Es funktioniert, denn wenn ich die 'allPosts' oder' post' abfrage bekomme ich den Autor zurück. Aber ich kann diese Information nicht im Abonnement erhalten. Es bricht also und sagt, dass es den Autor braucht – KadoBOT