Skip to content
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

feature: DatoCMS collection helper #76

Merged
merged 5 commits into from
Dec 23, 2023
Merged

Conversation

jbmoelker
Copy link
Member

@jbmoelker jbmoelker commented Nov 29, 2023

Changes

  • Adds a datocmsCollection helper function to fetch all records in a DatoCMS collection.
  • Uses pagination so even if a collection has more than 100 records (DatoCMS query limit) it will still return all records.
  • Is flexible enough for different use cases, by accepting a GraphQL fragment as an argument to use for the given collection.
  • Extends datocmsRequest with retry on rate limit error.

Simplified example (without types):

import { datocmsCollection } from '@lib/datocms';

const pages = await datocmsCollection({ 
  collection: 'Pages',
  fragment: `slugs: _allSlugLocales { locale, value }`,
});

Associated issue

Resolves #74

How to test

  1. Checkout this branch locally
  2. Force pagination, by changing recordsPerPage to 1 in the new datocmsCollection function in lib/datocms.ts
  3. Run a local build
  4. Verify all the pages are still generated in dist/[locale]/
  5. Verify all the pages are also still generated in the Cloudflare deploy preview

Checklist

  • I have performed a self-review of my own code
  • I have made sure that my PR is easy to review (not too big, includes comments)
  • I have added/updated tests to prove that my feature works (if not possible please explain why)
  • I have made changes to the README and if the change affects the project setup (npm commands changed, new service added, environmental variable added) will add this to docs/data-loading.md (see Missing docs #71)
  • I have added a decision log entry if the change affects the architecture or changes a significant technology
  • I have notified a reviewer

@jbmoelker jbmoelker requested a review from decrek November 29, 2023 16:52
@jbmoelker jbmoelker changed the title feat(datocms): collection helper using pagination feature: DatoCMS collection helper Nov 29, 2023
@jbmoelker jbmoelker self-assigned this Nov 29, 2023
@jbmoelker jbmoelker mentioned this pull request Nov 29, 2023
4 tasks
@jbmoelker jbmoelker added the enhancement New feature or request label Dec 11, 2023
jbmoelker added a commit that referenced this pull request Dec 22, 2023
# Changes

- Document CMS Data Loading configuration and available helper methods,
and GraphQL file usage.

Note: already references methods and files, yet to be merged in #76 and
#68 .

# Associated issue

Part of #71 

# How to test

Review `docs/cms-data-loading.md`

# Checklist

- [x] I have performed a self-review of my own code
- [x] I have made sure that my PR is easy to review (not too big,
includes comments)
- ~~I have added/updated tests to prove that my feature works (if not
possible please explain why)~~
- [x] I have made changes to the README and if the change affects the
project setup (npm commands changed, new service added, environmental
variable added)
- ~~I have added a decision log entry if the change affects the
architecture or changes a significant technology~~
- [x] I have notified a reviewer

<!-- Please strike through and check off all items that do not apply
(rather than removing them) -->
Copy link

cloudflare-workers-and-pages bot commented Dec 23, 2023

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: e4e0b68
Status: ✅  Deploy successful!
Preview URL: https://df81fbc6.head-start.pages.dev
Branch Preview URL: https://feat-datocms-collection.head-start.pages.dev

View logs

@jbmoelker jbmoelker merged commit 33994cb into main Dec 23, 2023
2 checks passed
@jbmoelker jbmoelker deleted the feat/datocms-collection branch December 23, 2023 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Paginate Page Query
1 participant