Git Product home page Git Product logo

graphprotocol / graph-node Goto Github PK

View Code? Open in Web Editor NEW
2.8K 87.0 891.0 324.78 MB

Graph Node indexes data from blockchains such as Ethereum and serves it over GraphQL

Home Page: https://thegraph.com

License: Apache License 2.0

Rust 94.47% CSS 0.71% HTML 0.13% TypeScript 2.00% PLpgSQL 2.22% Dockerfile 0.07% Shell 0.28% JavaScript 0.07% Solidity 0.05% Makefile 0.02%
graphql graphql-api blockchain protocol ethereum ipfs graphql-server developer-tools

graph-node's Introduction

Graph Node

Build Status Getting Started Docs

The Graph is a protocol for building decentralized applications (dApps) quickly on Ethereum and IPFS using GraphQL.

Graph Node is an open source Rust implementation that event sources the Ethereum blockchain to deterministically update a data store that can be queried via the GraphQL endpoint.

For detailed instructions and more context, check out the Getting Started Guide.

Quick Start

Prerequisites

To build and run this project you need to have the following installed on your system:

For Ethereum network data, you can either run your own Ethereum node or use an Ethereum node provider of your choice.

Minimum Hardware Requirements:

  • To build graph-node with cargo, 8GB RAM are required.

Docker

The easiest way to run a Graph Node is to use the official Docker compose setup. This will start a Postgres database, IPFS node, and Graph Node. Follow the instructions here.

Running a Local Graph Node

This is a quick example to show a working Graph Node. It is a subgraph for Gravatars.

  1. Install IPFS and run ipfs init followed by ipfs daemon.
  2. Install PostgreSQL and run initdb -D .postgres -E UTF8 --locale=C followed by pg_ctl -D .postgres -l logfile start and createdb graph-node.
  3. If using Ubuntu, you may need to install additional packages:
    • sudo apt-get install -y clang libpq-dev libssl-dev pkg-config
  4. In the terminal, clone https://github.com/graphprotocol/example-subgraph, and install dependencies and generate types for contract ABIs:
yarn
yarn codegen
  1. In the terminal, clone https://github.com/graphprotocol/graph-node, and run cargo build.

Once you have all the dependencies set up, you can run the following:

cargo run -p graph-node --release -- \
  --postgres-url postgresql://USERNAME[:PASSWORD]@localhost:5432/graph-node \
  --ethereum-rpc NETWORK_NAME:[CAPABILITIES]:URL \
  --ipfs 127.0.0.1:5001

Try your OS username as USERNAME and PASSWORD. For details on setting the connection string, check the Postgres documentation. graph-node uses a few Postgres extensions. If the Postgres user with which you run graph-node is a superuser, graph-node will enable these extensions when it initializes the database. If the Postgres user is not a superuser, you will need to create the extensions manually since only superusers are allowed to do that. To create them you need to connect as a superuser, which in many installations is the postgres user:

    psql -q -X -U <SUPERUSER> graph-node <<EOF
create extension pg_trgm;
create extension pg_stat_statements;
create extension btree_gist;
create extension postgres_fdw;
grant usage on foreign data wrapper postgres_fdw to <USERNAME>;
EOF

This will also spin up a GraphiQL interface at http://127.0.0.1:8000/.

  1. With this Gravatar example, to get the subgraph working locally run:
yarn create-local

Then you can deploy the subgraph:

yarn deploy-local

This will build and deploy the subgraph to the Graph Node. It should start indexing the subgraph immediately.

Command-Line Interface

USAGE:
    graph-node [FLAGS] [OPTIONS] --ethereum-ipc <NETWORK_NAME:FILE> --ethereum-rpc <NETWORK_NAME:URL> --ethereum-ws <NETWORK_NAME:URL> --ipfs <HOST:PORT> --postgres-url <URL>

FLAGS:
        --debug      Enable debug logging
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
        --admin-port <PORT>                           Port for the JSON-RPC admin server [default: 8020]
        --elasticsearch-password <PASSWORD>
            Password to use for Elasticsearch logging [env: ELASTICSEARCH_PASSWORD]

        --elasticsearch-url <URL>
            Elasticsearch service to write subgraph logs to [env: ELASTICSEARCH_URL=]

        --elasticsearch-user <USER>                   User to use for Elasticsearch logging [env: ELASTICSEARCH_USER=]
        --ethereum-ipc <NETWORK_NAME:[CAPABILITIES]:FILE>
            Ethereum network name (e.g. 'mainnet'), optional comma-separated capabilities (eg full,archive), and an Ethereum IPC pipe, separated by a ':'

        --ethereum-polling-interval <MILLISECONDS>
            How often to poll the Ethereum node for new blocks [env: ETHEREUM_POLLING_INTERVAL=]  [default: 500]

        --ethereum-rpc <NETWORK_NAME:[CAPABILITIES]:URL>
            Ethereum network name (e.g. 'mainnet'), optional comma-separated capabilities (eg 'full,archive'), and an Ethereum RPC URL, separated by a ':'

        --ethereum-ws <NETWORK_NAME:[CAPABILITIES]:URL>
            Ethereum network name (e.g. 'mainnet'), optional comma-separated capabilities (eg `full,archive), and an Ethereum WebSocket URL, separated by a ':'

        --node-id <NODE_ID>
            A unique identifier for this node instance. Should have the same value between consecutive node restarts [default: default]

        --http-port <PORT>                            Port for the GraphQL HTTP server [default: 8000]
        --ipfs <HOST:PORT>                            HTTP address of an IPFS node
        --postgres-url <URL>                          Location of the Postgres database used for storing entities
        --subgraph <[NAME:]IPFS_HASH>                 Name and IPFS hash of the subgraph manifest
        --ws-port <PORT>                              Port for the GraphQL WebSocket server [default: 8001]

Advanced Configuration

The command line arguments generally are all that is needed to run a graph-node instance. For advanced uses, various aspects of graph-node can further be configured through environment variables. Very large graph-node instances can also split the work of querying and indexing across multiple databases.

Project Layout

  • node — A local Graph Node.
  • graph — A library providing traits for system components and types for common data.
  • core — A library providing implementations for core components, used by all nodes.
  • chain/ethereum — A library with components for obtaining data from Ethereum.
  • graphql — A GraphQL implementation with API schema generation, introspection, and more.
  • mock — A library providing mock implementations for all system components.
  • runtime/wasm — A library for running WASM data-extraction scripts.
  • server/http — A library providing a GraphQL server over HTTP.
  • store/postgres — A Postgres store with a GraphQL-friendly interface and audit logs.

Roadmap

🔨 = In Progress

🛠 = Feature complete. Additional testing required.

✅ = Feature complete

Feature Status
Ethereum
Indexing smart contract events
Handle chain reorganizations
Mappings
WASM-based mappings
TypeScript-to-WASM toolchain
Autogenerated TypeScript types
GraphQL
Query entities by ID
Query entity collections
Pagination
Filtering
Block-based Filtering
Entity relationships
Subscriptions

Contributing

Please check CONTRIBUTING.md for development flow and conventions we use. Here's a list of good first issues.

License

Copyright © 2018-2019 Graph Protocol, Inc. and contributors.

The Graph is dual-licensed under the MIT license and the Apache License, Version 2.0.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either expressed or implied. See the License for the specific language governing permissions and limitations under the License.

graph-node's People

Contributors

adklempner avatar azf20 avatar davekaj avatar dependabot-preview[bot] avatar dependabot[bot] avatar dotansimha avatar eduard-voiculescu avatar evaporei avatar fordn avatar gusinacio avatar html5cat avatar incrypto32 avatar jannis avatar kamilkisiela avatar leoyvens avatar lutter avatar mangas avatar maoueh avatar neysofu avatar pienkowb avatar saihaj avatar sduchesneau avatar that3percent avatar theodus avatar tilacog avatar timmclean avatar vrmiguel avatar yaroshkvorets avatar zerim avatar zorancv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

graph-node's Issues

Implement a Data Source Runtime wrapper (index.js)

This script would load the data-source.json file, load the files referenced in the data source definition (from files/), instantiate contracts using web3, set up IPC and eventually pass everything to the default export function of mapping.js.

Implement missing schema introspection features

These are:

  • __type arguments: the signature should be __type(name: String!): __Type but we don't currently support the name argument).
  • Union types (we only handle unions when looking at whether fragments apply; everywhere else they are not supported yet).
  • The "interfaces" field of any types inside "possibleTypes" (with the current eager construction of the introspection schema, filling this in would result in infinite recursion).
  • Deprecation support.

Report store errors back to client instead of panicking

Example: We won't support all filters for all types, so we should

  • Try to only expose filters that we support in the GraphQL schema
  • Allow the Store to return useful errors when filters are not supported for certain value types.

Track crashes and other errors using Sentry

This would allow us to be notified whenever our deployed instance(s) crash or trigger an error that we consider a bug. It would also allow us to create GitHub issues from automatically generated crash reports and assign these to developers for fixing.

Implement a RuntimeAdapter in thegraph-runtime-nodejs

This DataSourceConnector would take in a DataSourceDefinition (see #60) and instantiate data source runtime that lives in another process and is based on Node.js.

This involves:

  1. Create a temporary directory.
  2. Creating a package.json with default dependencies (like web3, and IPFS)
  3. Serialize the data source definition to a data-source.json file in the temporary directory using serde_json
  4. Copy the files referenced in the data source definition into the temporary directory under files/
  5. Write the mapping script from the data source definition to an mapping.js.
  6. Create a index.js that connects the indexing code in mapping.js to the DataSourceConnector
    • This means we need to stand up an IPC interface
    • Run index.js with Node, calling the default exported function from mapping.js with data initialized from data-source.json
    • Connect to the IPC interface

Implement the DataSourceDefinitionLoader

This would be a trait in thegraph and a default implementation in thegraph-core.

The default implementation should

  1. Load the data source definition YAML using serde_yaml
  2. Resolve the schema file referenced from the definition and parse it into a GraphQL schema

The output of the loader should a newtype DataSourceDefinition struct that essentially stores a nested map with the definition data:

pub struct DataSourceDefinition(serde_yaml::Value)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.