【问题标题】:Gridsome: Error: Variable of required type "String!" was not providedGridsome:错误:所需类型的变量“字符串!”没有提供
【发布时间】:2022-01-03 17:41:16
【问题描述】:

我正在生成一个运行良好的页面列表,我想添加一个可以根据类别查询对象的类别列表。对于带有节点的页面,这是我在 gridsome.server.js 中所做的:

data.django.jobOfferList.edges.forEach(({ node }) => {
  createPage({
        path: `/${node.category}/${node.id}`,
        component: "./src/templates/JobOfferTemplate.vue",
        context: {
          id: node.id,
        },
      });
}

这与以下名为 JobsListSection.vue 的部分完美配合:

<template>
  <section class="section">
    <h1 class="title">Nos offres d'emploi</h1>
    <div class="columns is-multiline">
      <JobOfferCard
        v-for="(edge, index) in $static.django.jobOfferList.edges"
        :key="index"
        :content="edge.node"
      />
    </div>
  </section>
</template>

<static-query>
query retrieveAllOffersByReverseChronology {
  django {
    jobOfferList(orderBy: "-created_at") {
      edges {
        node {
          id
          description
          company
          category
          active
          createdAt
          title
        }
      }
    }
  }
}
</static-query>

<script>
import JobOfferCard from "@/components/JobOfferCard.vue";
export default {
  name: "JobsListSection",
  components: { JobOfferCard },
};
</script>

现在,我尝试创建基于类别的模板;这是我在gridsome.server.js 中添加它的方式:

createPage({
        path: `/${node.category}`,
        component: "./src/templates/JobsCategoryListSection.vue",
        context: {
          category: node.category,
        },
      });

我们可以看到我传递了一个名为category 的参数;但是当我在我的模板中查询它时:

<static-query>
query ($category: String) {
  django {
    jobOfferList(category_Icontains: $category) {
      edges {
        node {
          id
          description
          company
          category
          active
          createdAt
          title
        }
      }
    }
  }
}
</static-query>

我收到以下错误:

Module build failed (from ./node_modules/gridsome/lib/plugins/vue-components/lib/loaders/static-query.js):
Error: Variable "$category" of required type "String!" was not provided.

我不明白为什么它无法检测到我传递的变量类别。我的代码有问题吗?

【问题讨论】:

    标签: javascript node.js graphql gridsome


    【解决方案1】:

    修好了!这只是一个小错误;必须将&lt;static-query&gt; 更改为&lt;page-query&gt;。现在工作得很好,似乎静态查询不接受 Gridsome 中的变量。

    【讨论】:

      猜你喜欢
      • 2019-05-29
      • 2020-10-18
      • 2021-03-13
      • 2021-07-18
      • 2019-03-22
      • 2021-06-03
      • 2021-03-25
      • 2019-05-01
      • 2020-04-06
      相关资源
      最近更新 更多