gatsby-uc / gatsby-source-strapi

Gatsby source plugin for building websites using Strapi as a data source
MIT License
355 stars 183 forks source link

TotalCount is always equal to 1 #307

Closed tomwilson2 closed 2 years ago

tomwilson2 commented 2 years ago

I've encountered an issue where TotalCount always equals 1.

My query at __graphql.

query MyQuery {
  allStrapiWork {
    totalCount
    pageInfo {
      totalCount
    }
  }
}

My plugins configuration at gatsby-config.js.

{
      resolve: `gatsby-source-strapi`,
      options: {
        apiURL: `http://localhost:1337`,
        queryLimit: 1000,
        collectionTypes: [{
          name: "work",
          endpoint: "api/works",
        }]
      },
    },
kicocisco commented 2 years ago

@tomwilson2 Are you using v4?

tomwilson2 commented 2 years ago

Yeah, Gatsby4 and Strapi4.

I've been able to replicate this issue from the most basic setup.

To replicate I've just made a new Strapi app.

npx create-strapi-app@latest my-project --quickstart

Made a content-type; like shoe, for instance. Changed permissions so it is publically viewable.

Then I made a quick Gatsby app.

npm init gatsby
npm install --save gatsby-source-strapi

Installed and setup the gatsby-source-strapi plugin.

module.exports = {
  siteMetadata: {
    title: ``,
    siteUrl: `https://www.yourdomain.tld`,
  },
  plugins: [
    {
      resolve: `gatsby-source-strapi`,
      options: {
        apiURL: `http://localhost:1337`,
        queryLimit: 1000,
        collectionTypes: [{
          name: "shoe",
          endpoint: "api/shoes",
        }]
      },
    },
  ],
}

Gatsby version is 4.10.0. gatsby-source-strapi is at 1.0.3. Strapi is at 4.1.5.

Then I started the Gatsby application and went to ___graphql where I used this query.

query MyQuery {
  allStrapiShoe {
    totalCount
    pageInfo {
      totalCount
    }
  }
}

But after the query the value is still one. I've had no entries, it shows totalCount as 1. I've had four entries, it shows totalCount as 1.

remidej commented 2 years ago

gatsby-source-strapi v1 is not compatible with Strapi v4.

For Strapi v4 support, please use version 2.x.x of this source plugin instead (latest is the beta.0)