Skip to content

thematters/subgraphs

Repository files navigation

The Graph subgraphs of Matters Lab

We use The Graph to index contract data, for better query performance. And it's a GraphQL API, more flexible than RESTful API.

Subgraphs

Name Network Playground URL API Endpoint
Logbook Polygon Mumbai https://thegraph.com/hosted-service/subgraph/thematters/logbook-mumbai https://api.thegraph.com/subgraphs/name/thematters/logbook-mumbai
Logbook Polygon Mainnet https://thegraph.com/hosted-service/subgraph/thematters/logbook https://api.thegraph.com/subgraphs/name/thematters/logbook

GraphQL Schema

You can open the "Playground URL" and view the schema in the right sidebar, or schema.graphql in this repository.

Usages

// choose any GraphQL client library you like
import {
  ApolloClient,
  InMemoryCache,
  ApolloProvider,
  useQuery,
  gql
} from "@apollo/client";

// initialize the client
const API_ENDPOINT =
  "https://api.thegraph.com/subgraphs/name/thematters/logbook-mumbai";
const client = new ApolloClient({
  uri: API_ENDPOINT,
  cache: new InMemoryCache()
});

// fetch data inside a React component
const LATEST_LOGGED_LOGBOOKS = gql`
  query LatestLogbooks {
    publications(first: 5, orderBy: createdAt, orderDirection: desc) {
      id
      createdAt
      log {
        id
        content
      }
      logbook {
        id
        title
      }
    }
  }
`;

function Feed() {
  const { loading, error, data } = useQuery(LATEST_LOGGED_LOGBOOKS);

  if (loading) return <p>Loading...</p>;
  if (error) return <p>Error :(</p>;

  return data.publications.map(({ id, logbook }) => (
    <div key={id}>
      <p>{logbook.title}</p>
    </div>
  ));
}

More query usages, see GraphQL API.

To interact with the contract, please checkout thematters/contracts.

Development

Install the Graph CLI

npm install -g @graphprotocol/graph-cli

Install dependencies

npm install

Codegen

npm run codegen:logbook

Build

npm run build:logbook

Deploy

npm run deploy:logobok:polygon-mumbai
npm run deploy:logobok:polygon-mainnet

Releases

No releases published

Packages

No packages published