Skip to content

Commit 198b383

Browse files
author
Guillaume Chau
committed
test(e2e): manual add smart query: loadingKey
1 parent 14ea90a commit 198b383

File tree

5 files changed

+63
-0
lines changed

5 files changed

+63
-0
lines changed

tests/demo/apollo-server/resolvers.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ module.exports = {
2626
bad: () => {
2727
throw new Error('An error')
2828
},
29+
loadNumber: () => new Promise((resolve) => {
30+
setTimeout(() => resolve(42), 100)
31+
}),
2932
},
3033

3134
Mutation: {

tests/demo/apollo-server/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ type Query {
6969
channel (id: ID!): Channel @private
7070
good: String
7171
bad: String
72+
loadNumber: Int!
7273
}
7374

7475
type Mutation {
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<template>
2+
<div>
3+
<div v-if="loading > 0">
4+
Loading...
5+
</div>
6+
<div v-else>
7+
{{ number }}
8+
</div>
9+
10+
<div>{{ json(history) }}</div>
11+
</div>
12+
</template>
13+
14+
<script>
15+
import gql from 'graphql-tag'
16+
export default {
17+
data () {
18+
return {
19+
loading: 0,
20+
number: null,
21+
history: [],
22+
}
23+
},
24+
25+
mounted () {
26+
this.$apollo.addSmartQuery('number', {
27+
query: gql`
28+
query {
29+
number: loadNumber
30+
}
31+
`,
32+
loadingKey: 'loading',
33+
watchLoading: (isLoading, countModifier) => {
34+
console.log(isLoading, countModifier)
35+
this.history.push({ isLoading, countModifier })
36+
},
37+
})
38+
},
39+
40+
methods: {
41+
json (value) {
42+
return JSON.stringify(value)
43+
},
44+
},
45+
}
46+
</script>

tests/demo/src/router.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import UserLogin from './components/UserLogin.vue'
44
import WelcomeView from './components/WelcomeView.vue'
55
import ChannelView from './components/ChannelView.vue'
66
import PartialError from './components/PartialError.vue'
7+
import ManualAddSmartQuery from './components/ManualAddSmartQuery.vue'
78

89
Vue.use(Router)
910

@@ -36,5 +37,9 @@ export default new Router({
3637
path: '/partial-error',
3738
component: PartialError,
3839
},
40+
{
41+
path: '/manual-add-smart-query',
42+
component: ManualAddSmartQuery,
43+
},
3944
],
4045
})
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
describe('Manual Smart Query', () => {
2+
it('should support loading key', () => {
3+
cy.visit('/manual-add-smart-query')
4+
cy.contains('Loading...')
5+
cy.contains('42')
6+
cy.contains('[{"isLoading":true,"countModifier":1},{"isLoading":false,"countModifier":-1}]')
7+
})
8+
})

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy