add ability to query a text tree with a depth variable
This commit is contained in:
@@ -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))
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user