Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

graphql-codegen-data-persist

Package Overview
Dependencies
Maintainers
0
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-codegen-data-persist

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.

  • 1.0.0
  • unpublished
  • latest
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

GraphQL Codegen Static Data Plugin

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.

Features

  • Automated Data Fetching: Automatically fetches data from a GraphQL server using predefined queries.
  • Static Data Export: Generates TypeScript files containing static constants with the fetched data.

Installation

To install the plugin, run:

npm install --save-dev @graphql-codegen/plugin-helpers graphql-request

Configuration

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"

Usage

  1. Define your GraphQL queries to fetch the required static data.

  2. Configure the plugin in your codegen.yml file as shown above.

  3. Run the GraphQL Code Generator:

    npx graphql-codegen
    
  4. The plugin will generate a TypeScript file containing static constants that hold the data fetched by your queries.

Output

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

Development

To build the plugin for both CommonJS and ES Modules:

  1. Ensure TypeScript is installed:

    npm install --save-dev typescript
    
  2. Execute the build scripts:

    npm run build:cjs
    npm run build:esm
    
  3. The compiled files will be available in the cjs and esm directories.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgements

FAQs

Package last updated on 18 Aug 2024

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc