relate-app / gatsby-source-strapi-graphql

A Gatsby source plugin for building websites using Strapi as a data source
BSD Zero Clause License
32 stars 9 forks source link

Bug with publicationState #24

Closed kesslerdev closed 2 years ago

kesslerdev commented 2 years ago

Hello, I've a problem with this plugin, related to data from the blog article from strapi Build a static blog with Gatsby 4 and Strapi.

In this article the we can query articles (with publishedState) within the categories query (without publishedState) but the variable is not added to query vars :

the generated query:

CategoryQuery failed – Variable "$publicationState" is not defined by operation "CategoryQuery".

===== QUERY =====
query CategoryQuery($pagination: PaginationArg, $updatedAt: DateTime) {
  categories(pagination: $pagination, filters: {updatedAt: {gt: $updatedAt}}) {
    __typename
    data {
      __typename
      id
      attributes {
        __typename
        name
        slug
        articles(pagination: {limit: 1000}, publicationState: $publicationState) {
          __typename
          data {
            __typename
            id
          }
        }
        description
        createdAt
        updatedAt
      }
    }
    meta {
      pagination {
        total
      }
    }
  }
}
===== VARIABLES =====
{
  "pagination": {
    "start": 0,
    "limit": 1000
  },
  "updatedAt": "1990-01-01T00:00:00.000Z"
}
===== ERROR =====
 Variable "$publicationState" is not defined by operation "CategoryQuery".

this fix is not elegant but it works.

I've also added this fix for $locale and $updatedAt, it probably suffer from same "bug"

timbrandin commented 2 years ago

LGTM