![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
graphql-codegen-data-persist
Advanced tools
This plugin for [GraphQL Code Generator](https://www.graphql-code-generator.com/) facilitates fetching data from a GraphQL server using specific queries and subsequently generates static TypeScript files that encapsulate this data.
This plugin for GraphQL Code Generator facilitates fetching data from a GraphQL server using specific queries and subsequently generates static TypeScript files that encapsulate this data.
To install the plugin, run:
npm install --save-dev @graphql-codegen/plugin-helpers graphql-request
In your codegen.yml
file, the plugin should be configured as follows:
schema: "http://localhost:4000/graphql"
documents: "src/**/*.graphql"
generates:
src/generated/staticData.ts:
plugins:
- "path/to/your-plugin"
config:
url: "http://localhost:4000/graphql"
queries:
- |
query {
data {
foo
bar
}
}
- |
query {
otherData {
id
value
}
}
outputFile: "src/generated/staticData.ts"
Define your GraphQL queries to fetch the required static data.
Configure the plugin in your codegen.yml
file as shown above.
Run the GraphQL Code Generator:
npx graphql-codegen
The plugin will generate a TypeScript file containing static constants that hold the data fetched by your queries.
The generated TypeScript file (staticData.ts
) will include static constants representing the results of your queries, structured as follows:
export const Query0 = {
data: {
boo: false,
bar: true
// ... other data
}
};
export const Query1 = {
otherData: {
id: 1,
value: 'example'
// ... other data
}
};
// ... other queries
To build the plugin for both CommonJS and ES Modules:
Ensure TypeScript is installed:
npm install --save-dev typescript
Execute the build scripts:
npm run build:cjs
npm run build:esm
The compiled files will be available in the cjs
and esm
directories.
This project is licensed under the MIT License - see the LICENSE file for details.
FAQs
This plugin for [GraphQL Code Generator](https://www.graphql-code-generator.com/) facilitates fetching data from a GraphQL server using specific queries and subsequently generates static TypeScript files that encapsulate this data.
The npm package graphql-codegen-data-persist receives a total of 0 weekly downloads. As such, graphql-codegen-data-persist popularity was classified as not popular.
We found that graphql-codegen-data-persist demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
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.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.