Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { ConnectionHandler } from 'relay-runtime';
- import {
- graphql,
- requestSubscription
- } from 'react-relay'
- import environment from '../network';
- const subscription = graphql`
- subscription chatWithSubscription($id: String){
- chatWith(id: $id){
- textMessage
- id
- chatId
- date
- userType
- translatedMessage
- }
- }
- `;
- function chatWith(id) {
- const variables = { id: id };
- requestSubscription(environment, {
- subscription,
- variables,
- onError: (error) => {
- console.log(error, "error");
- },
- updater: (store) => {
- console.log(store, "store");
- }
- });
- }
- module.exports = chatWith;
- module.exports = createPaginationContainer(
- ChatMessages,
- graphql`
- fragment ChatMessages_query on Query
- @argumentDefinitions(
- count: { type: "Int", defaultValue: 10 }
- cursor: { type: "String" }
- chatId: { type: "ID" }
- ) {
- messages(
- first: $count
- after: $cursor
- chatId: $chatId
- ) @connection(key: "ChatMessages_messages") {
- edges {
- node {
- id
- chatId
- userType
- date
- textMessage
- translatedMessage
- }
- cursor
- }
- totalCount
- pageInfo {
- endCursor
- hasNextPage
- }
- }
- }
- `,
- {
- direction: "forward" | "backward",
- getConnectionFromProps(props) {
- return props.query && props.query.messages;
- },
- // This is also the default implementation of `getFragmentVariables` if it isn't provided.
- getFragmentVariables(prevVars, totalCount) {
- return {
- ...prevVars,
- count: totalCount
- };
- },
- getVariables(props, { count, cursor }, fragmentVariables) {
- return {
- count,
- cursor,
- chatId: fragmentVariables.chatId
- };
- },
- query: graphql`
- query ChatMessagesPaginationQuery(
- $count: Int!
- $cursor: String
- $chatId: ID!
- ) {
- ...ChatMessages_query
- @arguments(
- count: $count
- cursor: $cursor
- chatId: $chatId
- )
- }
- `
- }
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement