Commit 6ae56ad4 authored by Denys Mishunov's avatar Denys Mishunov

Moved GraphQL-related data into a mixin

The same GraphQL props/data/query will be used for the Edit
application as well

Default schema for snippet
parent aa3b1bcf
<script> <script>
import GetSnippetQuery from '../queries/snippet.query.graphql';
import SnippetHeader from './snippet_header.vue'; import SnippetHeader from './snippet_header.vue';
import SnippetTitle from './snippet_title.vue'; import SnippetTitle from './snippet_title.vue';
import SnippetBlob from './snippet_blob_view.vue'; import SnippetBlob from './snippet_blob_view.vue';
import { GlLoadingIcon } from '@gitlab/ui'; import { GlLoadingIcon } from '@gitlab/ui';
import { getSnippetMixin } from '../mixins/snippets';
export default { export default {
components: { components: {
SnippetHeader, SnippetHeader,
...@@ -12,33 +13,7 @@ export default { ...@@ -12,33 +13,7 @@ export default {
GlLoadingIcon, GlLoadingIcon,
SnippetBlob, SnippetBlob,
}, },
apollo: { mixins: [getSnippetMixin],
snippet: {
query: GetSnippetQuery,
variables() {
return {
ids: this.snippetGid,
};
},
update: data => data.snippets.edges[0].node,
},
},
props: {
snippetGid: {
type: String,
required: true,
},
},
data() {
return {
snippet: {},
};
},
computed: {
isLoading() {
return this.$apollo.queries.snippet.loading;
},
},
}; };
</script> </script>
<template> <template>
......
import GetSnippetQuery from '../queries/snippet.query.graphql';
export const getSnippetMixin = {
apollo: {
snippet: {
query: GetSnippetQuery,
variables() {
return {
ids: this.snippetGid,
};
},
update: data => data.snippets.edges[0]?.node,
result(res) {
if (this.onSnippetFetch) {
this.onSnippetFetch(res);
}
},
},
},
props: {
snippetGid: {
type: String,
required: true,
},
},
data() {
return {
snippet: {},
newSnippet: false,
};
},
computed: {
isLoading() {
return this.$apollo.queries.snippet.loading;
},
},
};
export default () => {};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment