Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed subscriptionData format problems #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion subscriptions-with-apollo-worldchat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"react-apollo": "^2.0.0",
"react-dom": "^16.0.0",
"react-google-maps": "^9.2.1",
"sillyname": "^0.1.0"
"sillyname": "^0.1.0",
"subscriptions-transport-ws": "^0.9.7"
},
"scripts": {
"start": "react-scripts start",
Expand Down
2 changes: 1 addition & 1 deletion subscriptions-with-apollo-worldchat/src/components/Chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Chat extends Component {
}
`,
updateQuery: (previousState, {subscriptionData}) => {
const newMessage = subscriptionData.Message.node
const newMessage = subscriptionData.data.Message.node
const messages = previousState.allMessages.concat([newMessage])
return {
allMessages: messages
Expand Down
10 changes: 5 additions & 5 deletions subscriptions-with-apollo-worldchat/src/components/WorldChat.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,16 @@ class WorldChat extends Component {
`,
variables: null,
updateQuery: (previousState, {subscriptionData}) => {
if (subscriptionData.Location.mutation === 'CREATED') {
const newLocation = subscriptionData.Location.node
if (subscriptionData.data.Location.mutation === 'CREATED') {
const newLocation = subscriptionData.data.Location.node
const locations = previousState.allLocations.concat([newLocation])
return {
allLocations: locations,
}
}
else if (subscriptionData.Location.mutation === 'UPDATED') {
else if (subscriptionData.data.Location.mutation === 'UPDATED') {
const locations = previousState.allLocations.slice()
const updatedLocation = subscriptionData.Location.node
const updatedLocation = subscriptionData.data.Location.node
const oldLocationIndex = locations.findIndex(location => {
return updatedLocation.id === location.id
})
Expand Down Expand Up @@ -369,4 +369,4 @@ export default compose(
graphql(allLocations, {name: 'allLocationsQuery'}),
graphql(createLocationAndTraveller, {name: 'createLocationAndTravellerMutation'}),
graphql(updateLocation, {name: 'updateLocationMutation'})
)(withApollo(WorldChat))
)(withApollo(WorldChat))