npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@bootnodedev/db-subgraph

v0.1.2

Published

Subgraph batteries for dAppBooster

Downloads

213

Readme

dAppBooster Subgraph Plugin

This package provides a flexible and reusable solution for generating GraphQL clients using @graphql-codegen/cli, integrated with @tanstack/react-query. It simplifies the process of setting up and managing GraphQL code generation for multiple subgraphs.

Installation

This package uses pnpm as the preferred package manager. First, install the package along with other required dependencies:

pnpm add @bootnodedev/db-subgraph graphql graphql-request

Then, add the development dependencies:

pnpm add -D @graphql-codegen/cli @graphql-typed-document-node/core

This separation ensures that the runtime dependencies are installed in your main dependencies, while the code generation tools are kept in your development dependencies.

Usage

1. Set Up CodeGen Configuration

Create a codegen file (e.g., src/subgraphs/codegen.ts) in your project:

import { generateCodegenConfig } from "@bootnodedev/db-subgraph";
import { loadEnv } from "vite";

const env = loadEnv("subgraphs", process.cwd(), "");

export default generateCodegenConfig({
  subgraphs: [
    {
      apiKey: env.PUBLIC_SUBGRAPHS_API_KEY,
      chainsResourceIds: env.PUBLIC_SUBGRAPHS_CHAINS_RESOURCE_IDS,
      environment: "production",
      productionUrl: env.PUBLIC_SUBGRAPHS_PRODUCTION_URL,
    },
  ],
});

You can use environment variables, hard-coded values, or a combination of both. Adjust the configuration according to your project's needs.

This file uses the generateCodegenConfig function from our package to create the configuration for @graphql-codegen/cli.

2. Run CodeGen

Add a script to your package.json to run the code generation:

{
  "scripts": {
    "subgraph-codegen": "graphql-codegen --config ./src/subgraphs/codegen.ts"
  }
}

Now you can generate your GraphQL clients by running:

pnpm run subgraph-codegen

3. Consume the queries

You can see a how it's been used in the dAppBooster Landing Page.

And for further information refer to the subgraph documentation.

Configuration Options

The PackageConfig interface accepts the following options for each subgraph:

  • apiKey: Your subgraph API key.
  • chainsResourceIds: A string of comma-separated <chainId>:<subgraphId>:<resourceId>.
    • i.e.: 137:uniswap:BvYimJ6vCLkk63oWZy7WB5cVDTVVMugUAF35RAUZpQXE,8453:aave:GQFbb95cE6d8mV989mL5figjaGaKCQB3xqYrr1bRyXqF
  • developmentUrl: The URL for the development environment.
  • productionUrl: The URL for the production environment.
  • environment: Either 'development' or 'production'.
  • queriesDirectory: The directory where your GraphQL queries are located.
    • default: ./src/subgraphs/queries
  • destinationDirectory: The directory where your typed queries will be generated.
    • defult: ./src/subgraphs/gql

Adding Multiple Subgraphs

You can configure multiple subgraphs by adding more objects to the subgraphs array in your configuration:

export default generateCodegenConfig({
  subgraphs: [
    {
      // First subgraph configuration
    },
    {
      // Second subgraph configuration
    },
    // Add more as needed
  ],
});

Generated Files

The package will generate GraphQL clients in the src/subgraphs/gql/ directory, organized by subgraph ID.

Customization

If you need to customize the generation process further, you can modify the codegen.ts file. The package is designed to be flexible, allowing you to define configurations in the way that best suits your project structure and requirements.