Orderings doesn't work with getAllByType

Orderings does not seem to be working in Nextjs when using getStaticProps and getAllByType.

We can correctly order the response when using getBySomeTags, however.

The following code does not correctly order by a date field:

const newsItems = await client.getAllByType('news', {
    limit: 3,
    orderings: [
      { 
        field: 'my.newsItems.data.first_publication_date',
        direction: 'desc'
      }
    ]
  });

When we use getBySomeTags, the response is correctly ordered:

const newsItems = await client.getBySomeTags(['News'], {
    limit: 3,
    orderings: [
      { 
        field: 'my.newsItems.published_date',
        direction: 'desc'
      }
    ]
  });

What do you get in the API response @jgunderson?

Thank you @Pau,

here is the response:

 {
    id: 'Y6spKhcAAFQCpJid',
    uid: 'employee-generation-study-eps',
    url: '/news/employee-generation-study-eps',
    type: 'news',
    href: 'https://teton-valley-housing.cdn.prismic.io/api/v2/documents/search?ref=ZAeIAxAAACkAu1e9&q=%5B%5B%3Ad+%3D+at%28document.id%2C+%22Y6spKhcAAFQCpJid%22%29+%5D%5D',
    tags: [ 'News' ],
    first_publication_date: '2022-12-27T17:19:42+0000',
    last_publication_date: '2023-03-07T18:52:27+0000',
    slugs: [
      'economic--planning-systems-hired-for-employee-generation-study',
      'bring-to-the-table-win-win-survival-strategies'
    ],
    linked_documents: [],
    lang: 'en-us',
    alternate_languages: [],
    data: {
      title: [Array],
      excerpt: [Array],
      published_date: '2023-02-23',
      featured_image: [Object],
      article: [Array]
    }
  }
]

I'm trying to order by published_date.

Can you tell me what would the expected date of the document?
What's the URL of your repository? I'd like to test it out (you can send it to me via dm if you prefer).

The expected date would be 2023-02-23 for that particular document.

It looks like your profile is hidden so I can't dm you.
Thanks!

I sent you a message. You can see it in your inbox now.

I noticed you're trying to query the last publication date from within the data node. You need to write the query like this instead because this is a metadata field:

{
  orderings: {
    field: 'document.first_publication_date',
  },
}

Hi @Pau,

thank you for your response. I'm not trying to query the metadata field, but rather a custom date field called published_date.

Thanks,
Jansen

I understand. The query has a syntax error. If your Custom type is named newsItems. You need to use the my.[custom-type].[field] path. In this case, it would be my.newsItems.published_date.

const newsItems = await client.getAllByType('news', {
    limit: 3,
    orderings: [
      { 
        field: 'my.newsItems.published_date',
        direction: 'desc'
      }
    ]
  });

Check out the REST API documentation to learn more about date predicates