
Product
A New Overview in our Dashboard
We redesigned Socket's first logged-in page to display rich and insightful visualizations about your repositories protected against supply chain threats.
graphql-codegen-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.
We found that graphql-codegen-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.
Product
We redesigned Socket's first logged-in page to display rich and insightful visualizations about your repositories protected against supply chain threats.
Product
Automatically fix and test dependency updates with socket fix—a new CLI tool that turns CVE alerts into safe, automated upgrades.
Security News
CISA denies CVE funding issues amid backlash over a new CVE foundation formed by board members, raising concerns about transparency and program governance.