marco
05/29/2018, 2:35 PMtype User @model {
id: ID! @isUnique
name: String
conversations: [Conversations!]! @relation(name: "UserConversations")
auth0UserId: String @isUnique
nachrichten: [Message!]! @relation(name: "MessagesSendByUser")
}
type Conversations @model {
id: ID! @isUnique
user: [User!]! @relation(name: "UserConversations")
messages: [Message!]! @relation(name: "MessagesInConversation")
createdAt: DateTime!
updatedAt: DateTime!
}
type Message @model {
id: ID! @isUnique
createdAt: DateTime!
updatedAt: DateTime!
message: String!
conversation: Conversations @relation(name: "MessagesInConversation")
read: Boolean
from: User @relation(name: "MessagesSendByUser")
}
And I want that only the authenticated User can get the Conversations (which contain messages) he is involved in.
How do I extend my shema? I find the graphcool doc rather not so helpful. I tried something along the lines like this.
query getConversations($user_id: ID!, $conversationsUser_id: ID!) {
getSomeConversations(filter: { AND: [{ id: $user_id }, { id: $conversationsUser_id }] })
}
extend type Query {
getSomeConversations(
)
}
But I still don't really get how to, maybe you guys can help me? Thank youSam Jackson
05/29/2018, 2:43 PMUser
and Conversation
(as it appears you have), you should be able to do something as simple as:
query {
getConversationsForUser(id: MY_ID) {
messages {
read
message
from {
name
}
}
}
}
You would just be querying the User
model and retrieving the conversations.Sam Jackson
05/29/2018, 2:44 PMgetUserId(ctx)
to get the user's ID. If that method fails it will throw an authentication error.marco
05/29/2018, 3:06 PMSam Jackson
05/29/2018, 3:08 PMquery {
getConversationsForCurrentUser {
...
}
}
Sam Jackson
05/29/2018, 3:09 PMSam Jackson
05/29/2018, 3:09 PMmarco
05/29/2018, 4:25 PMSam Jackson
05/29/2018, 4:26 PMSam Jackson
05/29/2018, 4:26 PM