Skip to content

Commit 54b4e98

Browse files
committed
Fixed router issue
1 parent 2110cd3 commit 54b4e98

File tree

3 files changed

+39
-19
lines changed

3 files changed

+39
-19
lines changed

basic/src/components/CreatePage.vue

+30-9
Original file line numberDiff line numberDiff line change
@@ -43,32 +43,53 @@
4343
}
4444
}
4545
`
46+
const FEED_QUERY = gql `
47+
query feed {
48+
feed {
49+
id
50+
text
51+
title
52+
isPublished
53+
}
54+
}
55+
`
56+
4657
export default {
4758
data: () => ({
4859
title: '',
4960
text: ''
5061
}),
51-
62+
5263
// Attribute
5364
methods: {
5465
create() {
5566
const title = this.title
5667
const text = this.text
57-
68+
5869
this.title = ''
5970
this.text = ''
60-
71+
6172
// Mutation
6273
this.$apollo.mutate({
6374
mutation: CREATE_POST,
6475
variables: {
6576
title,
6677
text,
6778
},
79+
// Update the cache with the result
80+
// and then with the real result of the mutation
81+
update: (store, { data: { createDraft } }) => {
82+
// Read the data from our cache for this query.
83+
const data = store.readQuery({ query: FEED_QUERY })
84+
// Add our post from the mutation to the end
85+
data.tags.push(createDraft)
86+
// Write our data back to the cache.
87+
store.writeQuery({ query: FEED_QUERY, data })
88+
}
6889
}).then((data) => {
6990
// Result
7091
console.log(data);
71-
router.push({ path: 'Drafts' })
92+
this.$router.push({ path: 'Drafts' })
7293
}).catch((error) => {
7394
// Error
7495
alert(`Error from ${error}`)
@@ -102,24 +123,24 @@
102123
margin-top: 35px;
103124
float: left;
104125
}
105-
126+
106127
.createPost:hover {
107128
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2);
108129
}
109-
130+
110131
.newPost {
111132
border: none;
112133
color: gray;
113134
background-color: white;
114135
}
115-
136+
116137
.plusImage {
117138
opacity: 0.4;
118139
margin-top: 25%;
119140
width: 25%;
120141
height: 25%;
121142
}
122-
143+
123144
.modal-mask {
124145
position: fixed;
125146
z-index: 9998;
@@ -179,4 +200,4 @@
179200
justify-content: flex-start;
180201
flex-direction: column;
181202
}*/
182-
</style>
203+
</style>

basic/src/components/DetailPage.vue

+8-9
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
post: {},
6161
loading: 0,
6262
}),
63-
63+
6464
// Apollo GraphQL
6565
apollo: {
6666
post: {
@@ -73,7 +73,7 @@
7373
}
7474
},
7575
},
76-
76+
7777
// Attribute
7878
methods: {
7979
deletePost() {
@@ -86,15 +86,14 @@
8686
}).then((data) => {
8787
// Result
8888
console.log(data);
89-
router.push({ path: 'Feed' })
89+
this.$router.push({ path: 'Feed' })
9090
}).catch((error) => {
9191
// Error
9292
console.error(error)
9393
})
9494
},
9595
publishDraft() {
9696
const postId = this.$route.params.id
97-
9897
// Mutation
9998
this.$apollo.mutate({
10099
mutation: PUBLISH_MUTATION,
@@ -104,7 +103,7 @@
104103
}).then((data) => {
105104
// Result
106105
console.log(data);
107-
router.push({ path: 'Drafts' })
106+
this.$router.push({ path: 'Drafts' })
108107
}).catch((error) => {
109108
// Error
110109
console.error(error)
@@ -124,24 +123,24 @@
124123
margin-top: 35px;
125124
float: left;
126125
}
127-
126+
128127
.createPost:hover {
129128
box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2);
130129
}
131-
130+
132131
.newPost {
133132
border: none;
134133
color: gray;
135134
background-color: white;
136135
}
137-
136+
138137
.plusImage {
139138
opacity: 0.4;
140139
margin-top: 25%;
141140
width: 25%;
142141
height: 25%;
143142
}
144-
143+
145144
.modal-mask {
146145
position: fixed;
147146
z-index: 9998;

basic/src/main.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import ApolloClient, { createNetworkInterface } from 'apollo-client'
44
import VueApollo from 'vue-apollo'
55
import router from './router'
66

7-
const networkInterface = createNetworkInterface({ uri: 'http://localhost:4000'});
7+
const networkInterface = createNetworkInterface({ uri: 'https://uniserver.now.sh/'});
88

99
const apolloClient = new ApolloClient({
1010
networkInterface,

0 commit comments

Comments
 (0)