add ability to query a text tree with a depth variable

This commit is contained in:
axolotle
2021-03-01 15:32:23 +01:00
parent c2c5c99745
commit 0fe388bf7f
3 changed files with 62 additions and 21 deletions
+19 -3
View File
@@ -3,7 +3,7 @@ import { print } from 'graphql/language/printer'
import {
TextsDepart, TextRef, TextdepartRecursive
} from '@/api/queries'
import TextdepartRecursiveWithDepth from '@/api/queries/TextdepartRecursiveWithDepth.gql'
export default {
state: {
@@ -24,14 +24,30 @@ export default {
})
},
'GET_TEXT' ({ state }, { id }) {
'GET_TEXT' (store, { id }) {
return api.post('', { query: print(TextRef), variables: { id } })
.then(data => (data.data.data))
},
'GET_TREE' ({ dispatch }, id) {
'GET_TREE' (store, id) {
return api.post('', { query: print(TextdepartRecursive), variables: { id } })
.then(({ data }) => (data.data.textref))
},
'GET_TREE_WITH_DEPTH' (store, { id, depth }) {
const baseQuery = print(TextdepartRecursiveWithDepth)
function formatQuery (str, depth) {
if (depth > 0) {
return formatQuery(
str.replace('INPUT', '...TextrefTreeFields\ntext_en_rebond {\nINPUT\n}'),
--depth
)
} else {
return str.replace('INPUT', '...TextrefTreeFields')
}
}
return api.post('', { query: formatQuery(baseQuery, depth), variables: { id } })
.then(({ data }) => (data.data.textref))
}
},