Registry / storage / strapi-flatten-graphql

strapi-flatten-graphql

JSON →
library0.1.0jsnpmunverified

A utility library (version 0.1.0) that flattens nested Strapi v4 GraphQL responses, removing the 'attributes' wrapper and preserving 'id' at all levels. It includes TypeScript typings and is designed to work alongside graphql-codegen. Currently requires every level to request 'id'. This is an early-stage, single-contributor project with limited updates. Differentiators: focused solely on Strapi v4 GraphQL flattening with type safety, whereas alternatives like lodash/ramda require manual mapping.

npm install strapi-flatten-graphql
INSTALL
IMPORT
SIG · STRAPI-FLATTEN-GRA
S
strapi-flatten-graphql
storagejavascriptv0.1.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

flattenEntity
import { flattenEntity } from 'strapi-flatten-graphql';
const { flattenEntity } = require('strapi-flatten-graphql');
Package is ESM-only? Check exports. CJS require may fail if not dual-published.
flattenEntityResponse
import { flattenEntityResponse } from 'strapi-flatten-graphql';
import flattenEntityResponse from 'strapi-flatten-graphql';
Named export, not default.
flattenEntityResponseCollection
import { flattenEntityResponseCollection } from 'strapi-flatten-graphql';
import flap from 'strapi-flatten-graphql';
Named export; no default export exists.

Flatten single entity, single response, and collection response from Strapi GraphQL.

import { flattenEntity, flattenEntityResponse, flattenEntityResponseCollection } from 'strapi-flatten-graphql'; const entity = { id: '1', attributes: { name: 'John', age: 30, address: { city: 'NY', country: 'USA' } }, }; console.log(flattenEntity(entity)); // { id: '1', name: 'John', age: 30, address: { city: 'NY', country: 'USA' } } const response = { data: { id: '2', attributes: { title: 'Post' } } }; console.log(flattenEntityResponse(response)); // { id: '2', title: 'Post' } const collection = { data: [ { id: '3', attributes: { content: 'Hello' } }, { id: '4', attributes: { content: 'World' } }, ], }; console.log(flattenEntityResponseCollection(collection)); // [{ id: '3', content: 'Hello' }, { id: '4', content: 'World' }]
Debug
Known issues
gotchaEvery nested entity must include 'id' field in GraphQL query; otherwise the flatten function may fail or omit data.
fix
Always request 'id' in your GraphQL queries at every level.
affects: >=0.0.0
deprecatedPackage is at version 0.1.0 (pre-1.0), API may change without major version bump.
fix
Pin exact version in dependencies.
affects: >=0.0.0
gotchaPackage may not handle null or missing attributes gracefully; expected Strapi v4 shape.
fix
Validate input structure before flattening.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot find module 'strapi-flatten-graphql'
Package not installed or wrong import path.
fix
Run 'npm install strapi-flatten-graphql'
flattenEntity is not a function
Using default import instead of named import.
fix
Use import { flattenEntity } from 'strapi-flatten-graphql'
TypeError: Cannot read properties of undefined
Missing 'id' or 'attributes' in input object.
fix
Ensure each entity has 'id' and 'attributes' fields.
Upgrade
Version history
0.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
21 hits · last 30 days
node
18
OpenAI (training)
1
Resources
strapi-flatten-graphql — npm install strapi-flatten-graphql · libregistry