简体   繁体   English

Vue 3 中的响应式查询 Apollo graphql

[英]Reactive queries Apollo graphql in Vue 3

Trying to make a reactive query as per https://v4.apollo.vuejs.org/guide-option/queries.html#reactive-query-definition , but I can't get them to work.尝试按照https://v4.apollo.vuejs.org/guide-option/queries.html#reactive-query-definition进行反应式查询,但我无法让它们工作。

Error:错误:

Uncaught (in promise) Error: Invalid AST Node: { query: { kind: "Document", definitions: [Array], loc: [Object] }, loadingKey: "loading" }.未捕获(承诺中)错误:无效的 AST 节点:{查询:{种类:“文档”,定义:[数组],位置:[对象]},loadingKey:“加载”}。

Query inside export default (checked is a reactive boolean v-model 'ed to a button defined in data()):在导出默认值内查询(选中的是响应式布尔v-model 'ed 到 data() 中定义的按钮):

apollo: {
    getTags: getTags,
        getPhotos: {
        query() {
            if (this.checked)
                return {
                    query: getPhotos,
                    loadingKey: "loading",
                }
            else {
                return {
                    query: getPhotosByTag,
                    loadingKey: "loading",
                }
            }
        },
        update: (data) => data.getPhotos || data.getPhotos,
        },
},

GQL getPhotosByTag: GQL getPhotosByTag:

const getPhotosByTag = gql`
    query getPhotosByTag {
        getPhotos: findTagByID(id: 326962542206255296) {
            photos {
                data {
                    name
                    description
                    _id
                }
            }
        }
    }
`

GQL getPhotos: GQL 获取照片:

const getPhotos = gql`
    query getPhotos {
        getPhotos: getPhotos(_size: 50) {
            data {
                name
                description
                _id
            }
        }
    }
`

If I take them out into separate queries and try to instead update use skip() via checked and !checked in the query definition, only the initial load delivers a query, if I click the button new query doesn't launch.如果我将它们取出到单独的查询中并尝试通过在查询定义中checked!checked来更新使用 skip(),则只有初始加载会提供查询,如果我单击按钮新查询不会启动。 Queries work by themselves fine.查询本身可以正常工作。

apollo: {
    getPhotos: {
        query() {
            return this.checked ? getPhotos : getPhotosByTag
        },
        loadingKey: "loading",
        update: (data) => data.getPhotos || data.getPhotos,
    },
},

Loading key has to be on the same level as query加载键必须与查询处于同一级别

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM