gatsby-source-strapi
gatsby-source-strapi copied to clipboard
null value in data fails gatsby build
Devbuild is failling because map_header is not found.
map_header is defined in schema, but none of the cases have a value. they all return null. in that case the plugin should not fail the build but pass the null value
ERROR #85901 GRAPHQL
There was an error in your GraphQL query:
Cannot query field "map_header" on type "StrapiCase".
File: gatsby-node.js:59:20
ERROR #11321 PLUGIN
"gatsby-node.js" threw an error while running the createPages lifecycle:
Cannot read property 'allStrapiCase' of undefined
TypeError: Cannot read property 'allStrapiCase' of undefined
- gatsby-node.js:75
/home/finn/projects/peats/app/web/gatsby-node.js:75:17
- async Promise.all
- api-runner-node.js:235 async runAPI
[web]/[gatsby]/dist/utils/api-runner-node.js:235:20
- api-runner-node.js:328 async module.exports
[web]/[gatsby]/dist/utils/api-runner-node.js:328:18
- index.js:434 async module.exports
[web]/[gatsby]/dist/bootstrap/index.js:434:3
- develop.js:419 async module.exports
[web]/[gatsby]/dist/commands/develop.js:419:7
failed createPages - 0.103s
gatsby.createPages query:
allStrapiCase {
edges {
node {
id
slug
name
description
map_header
}
}
}
localhost:1337/graphql playground result:
{
"data": {
"cases": [
{
"id": "1",
"slug": "caseSlug",
"name": "case 1",
"description": "description",
"map_header": null
}
]
}
}
permissions on case are given: find, findOne, count
This should be handled on gatsby side and gatsby provides an api createTypes to modify type definition.
Here is an example showing how to fix null value for a string field called title of a content type article:
exports.sourceNodes = ({ actions }) => {
const { createTypes } = actions
const typeDefs = `
type StrapiArticle implements Node {
title: String
}
`
createTypes(typeDefs)
}
You can find out more in the blog and documentation.
I have the same problem. I have at least 80 Strapi Content-types and a least 1000 fields. How it can be easily done for them all.
It also fails if the content-type is empty, not only field. How to avoid that?
i worked around this by creating the schema of each content type inside gatsby on build. for this i pass a schema of each type to:
gatsby-node:
exports.sourceNodes = ({ actions }) => {
const { createTypes } = actions;
createTypes( `
${SharedSchema}
${StrapiArticle}
....
`);
}
example schema of article:
note that all the custom types inside Article are already defined in SharedSchema and passed to createTypes
module.exports = `
type StrapiArticle implements Node {
title: String
slug: String
textbody: String
published: Boolean
abstract: String
thumbnail: Media
cases: [StrapiCase]
tags: [Tag]
anbieter: StrapiAnbieter
berater: StrapiBerater
}`
@FinnFrotscher Thank you for this, what did you use for image/file types? Especially, that I'm using fluid images in Gatsby, thank you.
probably png/jpeg. pretty standard
@FinnFrotscher Thank you for the reply, sorry, I meant I see your thumbnail property is of type Media and wondered what the graphql definition looked like for this type?
I dont have access to the repo anymore but it should look something like this:
type Media {
url: String
name: String
...
}
you can add whatever your business logic requires. dimensions, sources, encoding. go nuts.
When I attempt to define the schema as described, I get this error when running gatsby develop. What am I doing wrong?
"gatsby-source-strapi" threw an error while running the sourceNodes lifecycle:
Request failed with status code 404
Error: Request failed with status code 404
- createError.js:16 createError
[cmg-website]/[gatsby-source-strapi]/[axios]/lib/core/createError.js:16:15
- settle.js:18 settle
[cmg-website]/[gatsby-source-strapi]/[axios]/lib/core/settle.js:18:12
- http.js:202 IncomingMessage.handleStreamEnd
[cmg-website]/[gatsby-source-strapi]/[axios]/lib/adapters/http.js:202:11
- task_queues.js:84 processTicksAndRejections
internal/process/task_queues.js:84:21
- From previous event:
- api-runner-node.js:418 Promise.catch.decorateEvent.pluginName
[cmg-website]/[gatsby]/dist/utils/api-runner-node.js:418:7
- From previous event:
- api-runner-node.js:417
[cmg-website]/[gatsby]/dist/utils/api-runner-node.js:417:12
- timers.js:456 processImmediate
internal/timers.js:456:21
- From previous event:
- api-runner-node.js:411
[cmg-website]/[gatsby]/dist/utils/api-runner-node.js:411:11
- From previous event:
- api-runner-node.js:318 module.exports
[cmg-website]/[gatsby]/dist/utils/api-runner-node.js:318:12
- source-nodes.js:88 _default
[cmg-website]/[gatsby]/dist/utils/source-nodes.js:88:36
- source-nodes.js:29 sourceNodes
[cmg-website]/[gatsby]/dist/services/source-nodes.js:29:34
- interpreter.js:721 Interpreter.exec
[cmg-website]/[xstate]/lib/interpreter.js:721:27
- interpreter.js:223 Interpreter.execute
[cmg-website]/[xstate]/lib/interpreter.js:223:22
- interpreter.js:243 Interpreter.update
[cmg-website]/[xstate]/lib/interpreter.js:243:18
- interpreter.js:144
[cmg-website]/[xstate]/lib/interpreter.js:144:23
- scheduler.js:59 Scheduler.process
[cmg-website]/[xstate]/lib/scheduler.js:59:13
- scheduler.js:43 Scheduler.schedule
[cmg-website]/[xstate]/lib/scheduler.js:43:14
- interpreter.js:140 Interpreter.send
[cmg-website]/[xstate]/lib/interpreter.js:140:29
- interpreter.js:836 actor.id
[cmg-website]/[xstate]/lib/interpreter.js:836:23
warn The gatsby-source-strapi plugin has generated no Gatsby nodes. Do you need it?
When I attempt to define the schema as described, I get this error when running
gatsby develop. What am I doing wrong?"gatsby-source-strapi" threw an error while running the sourceNodes lifecycle: Request failed with status code 404 Error: Request failed with status code 404 - createError.js:16 createError [cmg-website]/[gatsby-source-strapi]/[axios]/lib/core/createError.js:16:15 - settle.js:18 settle [cmg-website]/[gatsby-source-strapi]/[axios]/lib/core/settle.js:18:12 - http.js:202 IncomingMessage.handleStreamEnd [cmg-website]/[gatsby-source-strapi]/[axios]/lib/adapters/http.js:202:11 - task_queues.js:84 processTicksAndRejections internal/process/task_queues.js:84:21 - From previous event: - api-runner-node.js:418 Promise.catch.decorateEvent.pluginName [cmg-website]/[gatsby]/dist/utils/api-runner-node.js:418:7 - From previous event: - api-runner-node.js:417 [cmg-website]/[gatsby]/dist/utils/api-runner-node.js:417:12 - timers.js:456 processImmediate internal/timers.js:456:21 - From previous event: - api-runner-node.js:411 [cmg-website]/[gatsby]/dist/utils/api-runner-node.js:411:11 - From previous event: - api-runner-node.js:318 module.exports [cmg-website]/[gatsby]/dist/utils/api-runner-node.js:318:12 - source-nodes.js:88 _default [cmg-website]/[gatsby]/dist/utils/source-nodes.js:88:36 - source-nodes.js:29 sourceNodes [cmg-website]/[gatsby]/dist/services/source-nodes.js:29:34 - interpreter.js:721 Interpreter.exec [cmg-website]/[xstate]/lib/interpreter.js:721:27 - interpreter.js:223 Interpreter.execute [cmg-website]/[xstate]/lib/interpreter.js:223:22 - interpreter.js:243 Interpreter.update [cmg-website]/[xstate]/lib/interpreter.js:243:18 - interpreter.js:144 [cmg-website]/[xstate]/lib/interpreter.js:144:23 - scheduler.js:59 Scheduler.process [cmg-website]/[xstate]/lib/scheduler.js:59:13 - scheduler.js:43 Scheduler.schedule [cmg-website]/[xstate]/lib/scheduler.js:43:14 - interpreter.js:140 Interpreter.send [cmg-website]/[xstate]/lib/interpreter.js:140:29 - interpreter.js:836 actor.id [cmg-website]/[xstate]/lib/interpreter.js:836:23 warn The gatsby-source-strapi plugin has generated no Gatsby nodes. Do you need it?
API issues 404 not found. check if you are hitting the right api.
Any update on this guys? I have similar problem with components in my single type. To simplify this I'll give an example with text field, because it doesn't work either
I decided to create type schema for my graphql endpoints - I have single type called "Home".
It is available under strapiHome in Gatsby's Graphql Playground. I wanted to have null's in fields which were not filled in Strapi. I tried to type it through createTypes function - I reallt want to avoid keeping dummy data in Strapi, since a lot of people are going to use the CMS.
So I did something like this in my gatsby-config.js
const typeDefs = `
type StrapiHome implements Node @infer {
id: ID!
textField: String
}
`
createTypes(typeDefs)
But the field is always missing in my StrapiHome endpoint. However if I do something like this
const typeDefs = `
type STRAPI_HOME implements Node @infer {
id: ID!
textField: String
}
`
createTypes(typeDefs)
The field exists, but it is always null whether data exists or not in CMS. You have any workaround to this problem?
I'm using:
- Gatsby Source Strapi 2.0.0
- Strapi 4.1.12
- Gatsby 4.14.0
Any update on this guys? I have similar problem with components in my single type. To simplify this I'll give an example with text field, because it doesn't work either
I decided to create type schema for my graphql endpoints - I have single type called "Home". It is available under strapiHome in Gatsby's Graphql Playground. I wanted to have null's in fields which were not filled in Strapi. I tried to type it through
createTypesfunction - I reallt want to avoid keeping dummy data in Strapi, since a lot of people are going to use the CMS.So I did something like this in my gatsby-config.js
const typeDefs = ` type StrapiHome implements Node @infer { id: ID! textField: String } ` createTypes(typeDefs)But the field is always missing in my StrapiHome endpoint. However if I do something like this
const typeDefs = ` type STRAPI_HOME implements Node @infer { id: ID! textField: String } ` createTypes(typeDefs)The field exists, but it is always
nullwhether data exists or not in CMS. You have any workaround to this problem?I'm using:
- Gatsby Source Strapi 2.0.0
- Strapi 4.1.12
- Gatsby 4.14.0
I have the exact same problem!
I'm sourcing a component from Strapi that is optional and can be sometimes null.
When I test on a post that has this component filled out if I query the data in Gatsby everything is present, but if define it in schema as shown below STRAPI__COMPONENT_PRIVATE_HERO is always null.
type STRAPI__COMPONENT_PRIVATE_LINK implements Node {
id: ID!
target: String
text: String
url: String
}
type STRAPI__COMPONENT_PRIVATE_BACKGROUND_IMAGE implements Node {
altDescription: String
image: STRAPI__MEDIA
}
type STRAPI__COMPONENT_PRIVATE_HERO implements Node {
BackgroundImage: STRAPI__COMPONENT_PRIVATE_BACKGROUND_IMAGE
Link: STRAPI__COMPONENT_PRIVATE_LINK
text: String
}
type STRAPI_HOME_PAGE implements Node {
Hero: STRAPI__COMPONENT_PRIVATE_HERO!
}
- Gatsby Source Strapi 2.0.0
- Strapi 4.2.3
- Gatsby 4.20.0
Found a working solution!
You can use this contentful plugin to create a schema that returns a null when the optional field is not present.
https://www.npmjs.com/package/gatsby-plugin-contentful-optional-fields
It uses createResolvers instead of createSchemaCustomization.
Source: https://github.com/gatsbyjs/gatsby/issues/2392#issuecomment-753329440
@kuczaQ we decided to move to gatsby-source-graphql. It works well with Strapi Graphql API but you have to deal with images and markup on your side.
Thanks for your interest in this project. This plugin is moving into the Gatsby User Collective and this repo will be archived. Please open an issue in that repository, submit a PR if you'd like to see this implemented, or join us on Discord if you have questions!