You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

@last-rev/cms-fs-loader

Package Overview
Dependencies
Maintainers
5
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@last-rev/cms-fs-loader

This library exports a single default function which creates a set of data loaders and fetchers for loading contentful structured content from a file system.

0.2.0
latest
npmnpm
Version published
Weekly downloads
187
-35.52%
Maintainers
5
Weekly downloads
 
Created
Source

Overview

This library exports a single default function which creates a set of data loaders and fetchers for loading contentful structured content from a file system.

Requirements

You must have a directory to which Contentful content has been synced. Please see the documentation for LastRev's cms-sync CLI which will generate this structure for you.

The directory should follow the following structure

dir
└── {contentful space id}
    └── { contentful environment name}
        └── { preview|production }
            ├── assets
            |   ├── {assetId}.json
            |   └── ...
            ├── entries
            |   ├── {entryId}.json
            |   └── ...
            ├── entry_ids_by_content_type
            |   ├── {entryId}
            |   └── ...
            └── content_types
                ├── {contentTypeId}.json
                └── ...

Usage

import createLoaders from '@last-rev/contentful-fs-loader';

async function () {
  const {
    entryLoader,
    assetLoader,
    entriesByContentTypeLoader,
    fetchAllContentTypes
  } = await createLoaders(
    './graphql/content' // root directory
    'saasdfgb34r8ffg7rtt', // contentful space ID
    'master', // contentful environment
    'preview' // one of 'preview' or 'production'
  );
}

entryLoader, assetLoader, and entriesByContentTypeLoader are all instances of dataloader. entryLoader and assetLoader are both keyed by contentful ID (string), and entriesByContentTypeLoader is keyed by a Contentful content type ID (string).

const myEntry = await entryLoader('my-content-id-1234');
const myAsset = await assetLoader('my-asset-id-5432');
const myEntries =  await entriesByContentTypeLoader('pageGeneral');

the other two functions, fetchAllPages and fetchAllContent are just convenience functions that return a list of all page content items (entries which have a slug field) and all content types.

FAQs

Package last updated on 27 Jun 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts