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

@nftx/subgraph

Package Overview
Dependencies
Maintainers
2
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nftx/subgraph

  • 0.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6
increased by100%
Maintainers
2
Weekly downloads
 
Created
Source

@nftx/subgraph

This library contains a few helpers for querying and fetching from the subgraph

Our subgraph urls can be found at @nftx/constants

Usage

API

gql

(s: string) => string;

"Processes" a graphql string. Under the hood this function does nothing :D but most IDEs and editors like VSCode recognize and provide syntax highlighting when they see gql calls.

const query = gql`
  {
    vaults {
      id
      vaultId
    }
  }
`;

querySubgraph

<T>({
  url: string,
  query: string,
  variables?: object
}): Promise<T>

Sends a graphql request to the subgraph.

This uses the global fetch api under the hood so if you're running in a non-browser environment (or aupporting older browsers), you'll need to polyfill fetch

When writing queries for querySubgraph you can pass variables in by prefixing a name with $.

For example:

const query = gql`{
  vaults(
    first: ${LIMIT}
    where: {
      createdAt_gt: $timestamp
    }
  ) {
    id
  }
}`;

For this string, LIMIT is inserted immediately, like a regular string interpoaltion. However $timestamp will later be passed in as a variable into querySubgraph:

querySubgraph({
  url,
  query,
  variables: { timestamp },
});

Variables are all stringified so if you pass in a string, you don't need to wrap it in quotes:

const query = gql`
  {
    vault(id: $id) {
      id
    }
  }
`;
querySubgraph({ url, query, variables: { id: '0x' } });

This would send a request with this query:

{
  vault(id: "0x") {
    id
  }
}

buildWhere

(obj: object) => string;

This helper function lets you build a where clause string. Where a value is null, it filters it out.

const query = gql`{
  vault(where: ${buildWhere({
    id: idOrNull,
    vaultId: vaultIdOrNull,
  })}) {
    id
  }
}`;

FAQs

Package last updated on 19 Dec 2022

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