Skip to content

Commit

Permalink
Step 15.6: Apply MessagesResult type
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilkisiela authored and Urigo committed May 20, 2020
1 parent e860261 commit 4f22257
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/components/ChatRoomScreen/index.tsx
Expand Up @@ -27,7 +27,7 @@ const Container = styled.div`

// eslint-disable-next-line
const getChatQuery = gql`
query GetChat($chatId: ID!) {
query GetChat($chatId: ID!, $limit: Int!, $after: Float) {
chat(chatId: $chatId) {
...FullChat
}
Expand Down
8 changes: 4 additions & 4 deletions src/graphql/fragments/fullChat.fragment.ts
@@ -1,14 +1,14 @@
import gql from 'graphql-tag';
import chat from './chat.fragment';
import message from './message.fragment';
import messagesResult from './messagesResult.fragment';

export default gql`
fragment FullChat on Chat {
...Chat
messages {
...Message
messages(limit: $limit, after: $after) @connection(key: "messages") {
...MessagesResult
}
}
${chat}
${message}
${messagesResult}
`;
13 changes: 13 additions & 0 deletions src/graphql/fragments/messagesResult.fragment.ts
@@ -0,0 +1,13 @@
import gql from 'graphql-tag';
import message from './message.fragment';

export default gql`
fragment MessagesResult on MessagesResult {
cursor
hasMore
messages {
...Message
}
}
${message}
`;
4 changes: 2 additions & 2 deletions src/services/cache.service.ts
Expand Up @@ -64,9 +64,9 @@ export const writeMessage = (client: Client, message: MessageFragment) => {
if (fullChat === null || fullChat.messages === null) {
return;
}
if (fullChat.messages.some((m: any) => m.id === message.id)) return;
if (fullChat.messages.messages.some((m: any) => m.id === message.id)) return;

fullChat.messages.push(message);
fullChat.messages.messages.push(message);
fullChat.lastMessage = message;

client.writeFragment({
Expand Down

0 comments on commit 4f22257

Please sign in to comment.