首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >盖茨比似乎不能质疑我的strapi后端

盖茨比似乎不能质疑我的strapi后端
EN

Stack Overflow用户
提问于 2022-05-26 19:54:28
回答 3查看 964关注 0票数 0

我正试图用strapi和gatsby获得一个快速的原型。所有的初学者似乎都不起作用,所以我在strapi网站上尝试了快速启动的方法。

首先,我遵循了这个快速启动指南,以获得strapi后端。https://docs.strapi.io/developer-docs/latest/getting-started/quick-start.html

然后这个让盖茨比跑了。https://docs.strapi.io/developer-docs/latest/developer-resources/content-api/integrations/gatsby.html#create-a-gatsby-app

并且遇到了两个错误。

代码语言:javascript
复制
"gatsby-source-strapi" threw an error while running the sourceNodes lifecycle:

Request failed with status code 403
...

warn The gatsby-source-strapi plugin has generated no Gatsby nodes. Do you need it? This
 could also suggest the plugin is misconfigured.

代码语言:javascript
复制
There was an error in your GraphQL query:

Cannot query field "allStrapiRestaurant" on type "Query".

我已经为餐馆和类别启用了find and。

所有资产都已公布。

我尝试向gatsby配置中添加一个API访问令牌,并获得相同的结果。

我的gatsby配置看起来

代码语言:javascript
复制
...
  plugins: [
    {
      resolve: "gatsby-source-strapi",
      options: {
        apiURL: "http://localhost:1337",
        accessToken: process.env.STRAPI_API_TOKEN,
        collectionTypes: ["restaurant", "category"],
        queryLimit: 1000,
      },
    },
...

我的包裹json看起来就像

代码语言:javascript
复制
{
  "name": "gatsby-starter-default",
  "private": true,
  "description": "A simple starter to get up and developing quickly with Gatsby",
  "version": "0.1.0",
  "author": "Kyle Mathews <mathews.kyle@gmail.com>",
  "dependencies": {
    "gatsby": "^4.15.0",
    "gatsby-plugin-gatsby-cloud": "^4.15.0",
    "gatsby-plugin-image": "^2.15.0",
    "gatsby-plugin-manifest": "^4.15.0",
    "gatsby-plugin-offline": "^5.15.0",
    "gatsby-plugin-react-helmet": "^5.15.0",
    "gatsby-plugin-sharp": "^4.15.0",
    "gatsby-source-filesystem": "^4.15.0",
    "gatsby-source-strapi": "^2.0.0",
    "gatsby-transformer-remark": "^5.15.0",
    "gatsby-transformer-sharp": "^4.15.0",
    "prop-types": "^15.8.1",
    "react": "^17.0.1",
    "react-dom": "^17.0.1",
    "react-helmet": "^6.1.0"
  },
  "devDependencies": {
    "prettier": "^2.6.2"
  },
  "keywords": [
    "gatsby"
  ],
  "license": "0BSD",
  "scripts": {
    "build": "gatsby build",
    "develop": "gatsby develop",
    "format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md,css}\"",
    "start": "gatsby develop",
    "serve": "gatsby serve",
    "clean": "gatsby clean",
    "test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/gatsbyjs/gatsby-starter-default"
  },
  "bugs": {
    "url": "https://github.com/gatsbyjs/gatsby/issues"
  }
}

我注意到的另一件事是,快速启动指南中的查询在使用graphiql时不存在。localhosthost:1337/api/restaurants返回数据(减去关系位)。在石墨库中,我可以像这样查询数据:

代码语言:javascript
复制
query { 
  restaurants{
    data{
      attributes{
        name
      }
    }
  }
}

(这仍然不允许我用strapi做任何有意义的事情,因为我无法得到任何关系或排序,这在盖茨比( gatsby )也不起作用,只是石墨石)

EN

回答 3

Stack Overflow用户

发布于 2022-06-27 19:02:04

您似乎需要将权限授予内容类型生成器。

设置>角色>内容类型构建器-getComponent -getComponents -getContentType -getContentTypes

票数 0
EN

Stack Overflow用户

发布于 2022-07-07 22:11:26

因此,我遇到了同样的问题,并能够通过在我的gatsby-config.js中使用这个strapi 起动器来解决它。集合和单个类型现在是对象数组,而不是上面使用的字符串数组。希望这能有所帮助!

代码语言:javascript
复制
 {
      resolve: "gatsby-source-strapi",
      options: {
        apiURL: process.env.STRAPI_API_URL || "http://localhost:1337",
        accessToken: process.env.STRAPI_TOKEN,
        collectionTypes: [
          {
            singularName: "article",
            queryParams: {
              publicationState:
                process.env.GATSBY_IS_PREVIEW === "true" ? "preview" : "live",
              populate: {
                cover: "*",
                blocks: {
                  populate: "*",
                },
              },
            },
          },
          {
            singularName: "author",
          },
          {
            singularName: "category",
          },
        ],
        singleTypes: [
          {
            singularName: "about",
            queryParams: {
              populate: {
                blocks: {
                  populate: "*",
                },
              },
            },
          },
          {
            singularName: "global",
            queryParams: {
              populate: {
                favicon: "*",
                defaultSeo: {
                  populate: "*",
                },
              },
            },
          },
        ],
      },
    },
    },
票数 0
EN

Stack Overflow用户

发布于 2022-08-04 03:25:41

我工作的方式是:

  1. npm run --prefix backend develop和在http://localhost:1337/admin/上登录到Strapi
  2. http://localhost:1337/admin/settings/api-tokens上创建API令牌,并将其复制以供以后使用
  3. 在项目的前端文件夹中,基于.env.develop文件创建了一个.env.example文件,并将api令牌添加到STRAPI_TOKEN=
  4. 在“”下检查"public“用户角色下的所有选项。应该位于以下网址:http://localhost:1337/admin/settings/users-permissions/roles/2

因此,我不知道快速启动npx选项是否只是设置错误或什么。希望这仍然是安全的,但它已经启动和运行。希望这能有所帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72397360

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档