我正试图用strapi和gatsby获得一个快速的原型。所有的初学者似乎都不起作用,所以我在strapi网站上尝试了快速启动的方法。
首先,我遵循了这个快速启动指南,以获得strapi后端。https://docs.strapi.io/developer-docs/latest/getting-started/quick-start.html
并且遇到了两个错误。
"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.和
There was an error in your GraphQL query:
Cannot query field "allStrapiRestaurant" on type "Query".我已经为餐馆和类别启用了find and。
所有资产都已公布。
我尝试向gatsby配置中添加一个API访问令牌,并获得相同的结果。
我的gatsby配置看起来
...
plugins: [
{
resolve: "gatsby-source-strapi",
options: {
apiURL: "http://localhost:1337",
accessToken: process.env.STRAPI_API_TOKEN,
collectionTypes: ["restaurant", "category"],
queryLimit: 1000,
},
},
...我的包裹json看起来就像
{
"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返回数据(减去关系位)。在石墨库中,我可以像这样查询数据:
query {
restaurants{
data{
attributes{
name
}
}
}
}(这仍然不允许我用strapi做任何有意义的事情,因为我无法得到任何关系或排序,这在盖茨比( gatsby )也不起作用,只是石墨石)
发布于 2022-06-27 19:02:04
您似乎需要将权限授予内容类型生成器。
设置>角色>内容类型构建器-getComponent -getComponents -getContentType -getContentTypes
发布于 2022-07-07 22:11:26
因此,我遇到了同样的问题,并能够通过在我的gatsby-config.js中使用这个strapi 起动器来解决它。集合和单个类型现在是对象数组,而不是上面使用的字符串数组。希望这能有所帮助!
{
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: "*",
},
},
},
},
],
},
},
},发布于 2022-08-04 03:25:41
我工作的方式是:
npm run --prefix backend develop和在http://localhost:1337/admin/上登录到Strapihttp://localhost:1337/admin/settings/api-tokens上创建API令牌,并将其复制以供以后使用.env.develop文件创建了一个.env.example文件,并将api令牌添加到STRAPI_TOKEN=中http://localhost:1337/admin/settings/users-permissions/roles/2因此,我不知道快速启动npx选项是否只是设置错误或什么。希望这仍然是安全的,但它已经启动和运行。希望这能有所帮助。
https://stackoverflow.com/questions/72397360
复制相似问题