This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export default createFragmentContainer(ListPage, graphql` | |
| fragment ListPage_viewer on Viewer { | |
| ...Post_viewer | |
| allPosts(last: 100, orderBy: createdAt_DESC) @connection(key: "ListPage_allPosts", filters: []) { | |
| edges { | |
| node { | |
| ...Post_post | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <Post key={node.__id} post={node} viewer={this.props.viewer} /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // subscribe to `CREATED`, `UPDATED` and `DELETED` mutations | |
| this.newMessageObserver = this.props.client.subscribe({ | |
| query: gql` | |
| subscription { | |
| Message { | |
| mutation # contains `CREATED`, `UPDATED` or `DELETED` | |
| node { | |
| text | |
| sentBy { | |
| name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| subscription { | |
| Message { | |
| mutation # contains `CREATED`, `UPDATED` or `DELETED` | |
| # node carries the new values | |
| node { | |
| text | |
| sentBy { | |
| name | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| next(data) { | |
| console.log('Old text: ', data.Message.previousValues.text) | |
| console.log('New text: ', data.Message.node.text) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type Traveller { | |
| id: ID! | |
| createdAt: DateTime! | |
| updatedAt: DateTime! | |
| name: String! | |
| location: Location! @relation(name: "TravellerLocation") | |
| messages: [Message!]! @relation(name: "MessagesFromTraveller") | |
| } | |
| type Message { | |
| id: ID! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import ApolloClient, { createNetworkInterface } from 'apollo-client' | |
| import {SubscriptionClient, addGraphQLSubscriptions} from 'subscriptions-transport-ws' | |
| import { ApolloProvider } from 'react-apollo' | |
| // Create WebSocket client | |
| const wsClient = new SubscriptionClient(`wss://subscriptions.graph.cool/v1/__PROJECT ID__`, { | |
| reconnect: true, | |
| connectionParams: { | |
| // Pass any arguments you want for initialization | |
| } | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class App extends Component { | |
| // ... | |
| render() { | |
| return ( | |
| <ApolloProvider client={client}> | |
| <WorldChat /> | |
| </ApolloProvider> | |
| ) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const allMessages = gql` | |
| query allMessages { | |
| allMessages { | |
| id | |
| text | |
| createdAt | |
| sentBy { | |
| id | |
| name | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export default graphql(createMessage, {name : 'createMessageMutation'})( | |
| graphql(allMessages, {name: 'allMessagesQuery'})(Chat) | |
| ) |