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>
import GetSnippetQuery from '../queries/snippet.query.graphql';
import SnippetHeader from './snippet_header.vue';
import SnippetTitle from './snippet_title.vue';
import SnippetBlob from './snippet_blob_view.vue';
import { GlLoadingIcon } from '@gitlab/ui';
import { getSnippetMixin } from '../mixins/snippets';
export default {
components: {
SnippetHeader,
......@@ -12,33 +13,7 @@ export default {
GlLoadingIcon,
SnippetBlob,
},
apollo: {
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;
},
},
mixins: [getSnippetMixin],
};
</script>
<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