Skip to content

bug(gatsby-source-strapi): When locale: "all" is used in a singleTypes error is thrown on a startup #509

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
alexanderT119 opened this issue Jan 13, 2025 · 4 comments
Labels
bug Something isn't working

Comments

@alexanderT119
Copy link

Describe the bug

When locale: "all" is used in a singleTypes error is thrown on a startup:

singleTypes: [
      "bottom-banner",
      "footer",
      {
        singularName: "header",
        pluginOptions: {
          i18n: {
            locale: "all",
          },
        },
        queryParams: {
          populate: {
            logoMobile: "1",
            logoDesktop: "1",
            headerItem: {
              populate: {
                dropdown: "*",
              }
            }
          }
        }
      },
  ]

Error text:

 ERROR #11321  API.NODE.EXECUTION

"gatsby-source-strapi" threw an error while running the sourceNodes lifecycle:

Cannot read properties of undefined (reading 'status')

  62 |   const endpoints = (0, _helpers.getEndpoints)(strapiConfig, schemas);
  63 |   const lastFetched = await cache.get(LAST_FETCHED_KEY);
> 64 |   const allResults = await Promise.all(endpoints.map(({
     |                      ^
  65 |     kind,
  66 |     ...config
  67 |   }) => {

File: node_modules/gatsby-source-strapi/dist/gatsby-node.js:64:22



  TypeError: Cannot read properties of undefined (reading 'status')
  
  - fetch.js:132 fetchEntity
    [frontend_gatsby]/[gatsby-source-strapi]/dist/fetch.js:132:24
**I am using strapi v5.6.0, gatsby-source-strapi v5.0.2**

To Reproduce

  1. Add new locale
  2. Create a singleType in a Strapi
  3. Enable Internalization for this type
  4. Create content in multiple locales
  5. Add new type gatsby-config.js with pluginOptions: { i18n: { locale: "all", }, },
  6. run gatsby develop

Expected behavior

No error on startup, graphql request with filter by locale is available

System Info


  System:
    OS: macOS 14.4.1
    CPU: (12) arm64 Apple M2 Max
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.16.0 - /var/folders/5w/b_rt83v54tz645mqrk24q47h0000gn/T/yarn--1736760325745-0.9108832253904138/node
    Yarn: 1.22.21 - /var/folders/5w/b_rt83v54tz645mqrk24q47h0000gn/T/yarn--1736760325745-0.9108832253904138/yarn
    npm: 9.5.1 - ~/.nvm/versions/node/v18.16.0/bin/npm
  Browsers:
    Chrome: 131.0.6778.265
    Safari: 17.4.1
  npmPackages:
    gatsby: ^5.14.1 => 5.14.1 
    gatsby-plugin-image: ^3.14.0 => 3.14.0 
    gatsby-plugin-manifest: ^5.14.0 => 5.14.0 
    gatsby-plugin-sass: ^6.14.0 => 6.14.0 
    gatsby-plugin-sharp: ^5.14.0 => 5.14.0 
    gatsby-source-filesystem: ^5.14.0 => 5.14.0 
    gatsby-source-graphql: ^5.14.0 => 5.14.0 
    gatsby-source-strapi: ^5.0.2 => 5.0.2 
    gatsby-transformer-remark: ^6.14.0 => 6.14.0 
    gatsby-transformer-sharp: ^5.14.0 => 5.14.0 

@alexanderT119 alexanderT119 added the bug Something isn't working label Jan 13, 2025
@tsvetowntopalov
Copy link

tsvetowntopalov commented Mar 7, 2025

Okay 10th edit. Got it working, with nested relations resolution and full i18n support on all kinds of stuff. Tested all morning

gatsby-source-strapi-src-changes.zip

@beve
Copy link

beve commented Apr 13, 2025

Same problem here.
Thanks for your fix, by I've the same problem with collections.

Please can we have some help from the maintainers ? :)

@moonmeister
Copy link
Contributor

There are no maintainers here in the traditional sense. The GUC is a place for those who use the plugins to be able to contribute as they need. My role as a maintainer is to enable those contributions, not do them specifically. I'm happy to work with anyone who wants to submit a fix to get that merged.

@beve
Copy link

beve commented Apr 13, 2025

Ok thanks for the explanation moonmeister :)
I got it to work.

It seems that if only two languages are configured, in my case "en" and "fr", this kind of configuration crashes the generation:

{
   singularName: "model",
   pluginOptions: {
   i18n: {
     locale: "all",
   },
 },
},

The workaround is to pass only "fr" or "en" as locale, and not use "all".

Then, when retrieving information from Gatsby's graphql database, proceed as follows:

 const queryResult = await graphql(`
 {
   homepage: allStrapiHomepage {
     nodes {
       description
     }
     localizations {
       description
     }
   }
 }}

The first "description" contains the untranslated version, and {localizations: {description}} contains the translated version.

I didn't understand this usage when I read the doc, but this way, everything works.

Thanks again for your quick response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants