From 7bcedabc7c61520b74ce19a7ee590bdc8aa3af04 Mon Sep 17 00:00:00 2001 From: Jonas Metzener Date: Thu, 18 Jul 2019 12:59:55 +0200 Subject: [PATCH] fix(performance): improve loading performance and caching --- addon/components/cf-content.js | 8 ++++---- .../gql/queries/get-document-answers.graphql | 3 +++ addon/gql/queries/get-document-forms.graphql | 19 ++++++++----------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/addon/components/cf-content.js b/addon/components/cf-content.js index b7c0917df..344db764d 100644 --- a/addon/components/cf-content.js +++ b/addon/components/cf-content.js @@ -143,19 +143,19 @@ export default Component.extend(ComponentQueryManager, { "allDocuments.edges" )).map(({ node }) => node); - const [formDocument] = (yield this.apollo.query( + const [form] = (yield this.apollo.query( { query: getDocumentFormsQuery, networkPolicy: "cache-first", - variables: { id: this.documentId } + variables: { slug: answerDocument.form.slug } }, - "allDocuments.edges" + "allForms.edges" )).map(({ node }) => node); this.calumaStore.clear(); return Document.create(getOwner(this).ownerInjection(), { - raw: parseDocument({ ...answerDocument, ...formDocument }) + raw: parseDocument({ ...answerDocument, form }) }); }) }); diff --git a/addon/gql/queries/get-document-answers.graphql b/addon/gql/queries/get-document-answers.graphql index a25f84c71..289ddf023 100644 --- a/addon/gql/queries/get-document-answers.graphql +++ b/addon/gql/queries/get-document-answers.graphql @@ -5,6 +5,9 @@ query($id: ID!) { edges { node { id + form { + slug + } answers { edges { node { diff --git a/addon/gql/queries/get-document-forms.graphql b/addon/gql/queries/get-document-forms.graphql index 2b8d6bdd5..2e341a2f6 100644 --- a/addon/gql/queries/get-document-forms.graphql +++ b/addon/gql/queries/get-document-forms.graphql @@ -1,18 +1,15 @@ #import 'ember-caluma/gql/fragments/field-question' -query($id: ID!) { - allDocuments(id: $id) { +query($slug: String!) { + allForms(slug: $slug) { edges { node { - id - form { - slug - name - questions { - edges { - node { - ...FieldQuestion - } + slug + name + questions { + edges { + node { + ...FieldQuestion } } }