• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kiva / ui / 14913053437

08 May 2025 06:04PM UTC coverage: 49.059%. Remained the same
14913053437

push

github

emuvente
fix(apollo-plugin): check for contentful preview param in route

1595 of 3417 branches covered (46.68%)

Branch coverage included in aggregate %.

0 of 1 new or added line in 1 file covered. (0.0%)

2393 of 4712 relevant lines covered (50.79%)

286.56 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/plugins/apollo-plugin.js
1
import checkInjections from '#src/util/injectionCheck';
2
import logReadQueryError from '#src/util/logReadQueryError';
3
import { isContentfulQuery } from '#src/util/contentful/isContentfulQuery';
4

5
const injections = ['apollo', 'cookieStore'];
×
6

7
// install method for plugin
8
export default app => {
9
        // export default {
10
        app.mixin({
×
11
                created() {
12
                        if (this.$options.apollo) {
×
13
                                checkInjections(this, injections);
×
14

15
                                const {
16
                                        query,
17
                                        preFetch,
18
                                        preFetchVariables = () => { },
×
19
                                        variables = () => { },
×
20
                                        result = () => { },
×
21
                                } = this.$options.apollo;
×
22

23
                                if (query) {
×
24
                                        const basketId = this.cookieStore.get('kvbskt');
×
NEW
25
                                        const isContentfulPreview = this.$route?.query?.preview === 'true';
×
26

27
                                        // if the query was prefetched, read the data from the cache
28
                                        if (preFetch) {
×
29
                                                try {
×
30
                                                        const data = this.apollo.readQuery({
×
31
                                                                query,
32
                                                                variables: {
33
                                                                        basketId,
34
                                                                        ...preFetchVariables({
35
                                                                                cookieStore: this.cookieStore,
36
                                                                                route: this.$route,
37
                                                                                client: this.apollo,
38
                                                                        }),
39
                                                                        /* Adds `preview: true` variable if the query is a contentful query
40
                                                                        and the preview cookie value exists */
41
                                                                        ...(isContentfulQuery(query) && isContentfulPreview && { preview: true })
×
42
                                                                }
43
                                                        });
44

45
                                                        if (data !== null) {
×
46
                                                                result.call(this, { data });
×
47
                                                        }
48
                                                } catch (e) {
49
                                                        // if there's an error, skip reading from the cache and just wait for the watch query
50
                                                        logReadQueryError(e, `ApolloMixin ${query?.definitions?.[0]?.name?.value}`);
×
51
                                                }
52
                                        }
53

54
                                        if (typeof window !== 'undefined') {
×
55
                                                // Setup an observer to watch for changes to the query result
56
                                                const observer = this.apollo.watchQuery({
×
57
                                                        query,
58
                                                        variables: {
59
                                                                basketId,
60
                                                                ...variables.call(this),
61
                                                                ...(isContentfulQuery(query) && isContentfulPreview && { preview: true })
×
62
                                                        }
63
                                                });
64

65
                                                // Use Vue's $watch to reactively update the query variables when the component data changes
66
                                                // This will cause a new query result to be fetched if it is not available in the cache
67
                                                this.$watch(variables, vars => observer.setVariables({
×
68
                                                        basketId,
69
                                                        ...vars,
70
                                                        ...(isContentfulQuery(query) && isContentfulPreview && { preview: true })
×
71
                                                }), { deep: true });
72

73
                                                // Subscribe to the observer to see each result
74
                                                observer.subscribe({
×
75
                                                        next: apolloResult => result.call(this, apolloResult)
×
76
                                                });
77
                                        }
78
                                }
79
                        }
80
                }
81
        });
82
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc