├── papers
└── whitepaper
│ ├── media
│ ├── image10.png
│ ├── image6.png
│ ├── image7.png
│ ├── image8.png
│ └── image9.png
│ ├── the-graph-whitepaper.pdf
│ ├── README.md
│ └── the-graph-whitepaper.tex
├── .gitignore
├── specs
├── graph-protocol-hybrid-network
│ ├── graphql-api
│ │ └── README.md
│ ├── graph-protocol-v1-spec.pdf
│ ├── assets
│ │ ├── query-node-architecture.png
│ │ └── query-client-architecture.png
│ ├── CHANGELOG.md
│ ├── SUMMARY.md
│ ├── DOCUMENT-CONVERSION.md
│ ├── deeplists.tex
│ ├── README.md
│ ├── datasets
│ │ └── README.md
│ ├── subgraph-manifest
│ │ └── README.md
│ ├── data-modeling
│ │ └── README.md
│ ├── mappings-api
│ │ └── README.md
│ ├── rpc-api
│ │ └── README.md
│ ├── query-processing
│ │ └── README.md
│ ├── payment-channels
│ │ └── README.md
│ ├── architecture-overview
│ │ └── README.md
│ ├── mechanism-design
│ │ └── README.md
│ ├── messages
│ │ └── README.md
│ └── read-interface
│ │ └── README.md
└── book.toml
├── .travis.yml
└── README.md
/papers/whitepaper/media/image10.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/graphprotocol/research/HEAD/papers/whitepaper/media/image10.png
--------------------------------------------------------------------------------
/papers/whitepaper/media/image6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/graphprotocol/research/HEAD/papers/whitepaper/media/image6.png
--------------------------------------------------------------------------------
/papers/whitepaper/media/image7.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/graphprotocol/research/HEAD/papers/whitepaper/media/image7.png
--------------------------------------------------------------------------------
/papers/whitepaper/media/image8.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/graphprotocol/research/HEAD/papers/whitepaper/media/image8.png
--------------------------------------------------------------------------------
/papers/whitepaper/media/image9.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/graphprotocol/research/HEAD/papers/whitepaper/media/image9.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | **/*.aux
3 | **/*.fdb_latexmk
4 | **/*.fls
5 | **/*.log
6 | **/*.out
7 | **/*.synctex.gz
8 | specs/book
9 |
--------------------------------------------------------------------------------
/papers/whitepaper/the-graph-whitepaper.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/graphprotocol/research/HEAD/papers/whitepaper/the-graph-whitepaper.pdf
--------------------------------------------------------------------------------
/specs/graph-protocol-hybrid-network/graphql-api/README.md:
--------------------------------------------------------------------------------
1 | This spec has been moved to: https://github.com/graphprotocol/specs/tree/master/graphql-api
2 |
--------------------------------------------------------------------------------
/specs/graph-protocol-hybrid-network/graph-protocol-v1-spec.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/graphprotocol/research/HEAD/specs/graph-protocol-hybrid-network/graph-protocol-v1-spec.pdf
--------------------------------------------------------------------------------
/specs/graph-protocol-hybrid-network/assets/query-node-architecture.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/graphprotocol/research/HEAD/specs/graph-protocol-hybrid-network/assets/query-node-architecture.png
--------------------------------------------------------------------------------
/specs/graph-protocol-hybrid-network/assets/query-client-architecture.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/graphprotocol/research/HEAD/specs/graph-protocol-hybrid-network/assets/query-client-architecture.png
--------------------------------------------------------------------------------
/specs/book.toml:
--------------------------------------------------------------------------------
1 | [book]
2 | title = "Hybrid Network"
3 | authors = ["Developers of The Graph project"]
4 | description = "Hybrid Network Spec."
5 | src = "graph-protocol-hybrid-network"
6 |
7 | [build]
8 | create-missing = false
9 |
10 | [output.html]
11 | mathjax-support = true
12 |
--------------------------------------------------------------------------------
/specs/graph-protocol-hybrid-network/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # Changelog
2 | ## Unreleased
3 | ### Changed
4 | - Participation reward for Indexers is now a function of curation signal, rather than query volume. See [#85](https://github.com/graphprotocol/research/issues/85) for additional context.
5 | - Curation reward now paid through fees rather than inflation.
6 | - `v` field on Attestation and Balance Proof messages changed to type `uint8`
7 |
8 | ## 0.0.1 - 2019-01-25
9 |
10 | ### Added
11 | - Specification open-sourced!
12 | - Changelog created
13 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: rust
2 | sudo: false
3 |
4 | cache:
5 | - cargo
6 |
7 | rust:
8 | - stable
9 |
10 | before_script:
11 | - (test -x $HOME/.cargo/bin/cargo-install-update || cargo install cargo-update)
12 | - (test -x $HOME/.cargo/bin/mdbook || cargo install mdbook)
13 | - cargo install-update -a
14 |
15 | script:
16 | - mdbook build specs && mdbook test specs
17 |
18 | deploy:
19 | provider: pages
20 | skip-cleanup: true
21 | github-token: $GITHUB_TOKEN
22 | local-dir: specs
23 | keep-history: false
24 | on:
25 | branch: master
26 |
--------------------------------------------------------------------------------
/specs/graph-protocol-hybrid-network/SUMMARY.md:
--------------------------------------------------------------------------------
1 | [Hybrid Network](README.md)
2 | - [Architecture Overview](architecture-overview/README.md)
3 | - [Mechanism Design](mechanism-design/README.md)
4 | - [Query Processing](query-processing/README.md)
5 | - [Payment Channels](payment-channels/README.md)
6 | - [Read Interface](read-interface/README.md)
7 | - [Messages](messages/README.md)
8 | - [JSON-RPC API](rpc-api/README.md)
9 | - [Datasets](datasets/README.md)
10 | - [Data Modeling](data-modeling/README.md)
11 | - [Subgraph Manifest](subgraph-manifest/README.md)
12 | - [Mappings API](mappings-api/README.md)
13 |
--------------------------------------------------------------------------------
/specs/graph-protocol-hybrid-network/DOCUMENT-CONVERSION.md:
--------------------------------------------------------------------------------
1 | # Document Conversion
2 |
3 | Below are instructions for converting the markdown specification to a PDF.
4 |
5 | 1. Install [Pandoc](https://pandoc.org/installing.html)
6 | 1. Install [LaTeX](https://www.latex-project.org/) on your machine
7 | 1. (Mac OSX) You may also need to install `rsvg-convert` by running `brew install librsvg` in the terminal.
8 | 1. Navigate to *this folder* in your Terminal
9 | - Run the following command:
10 | ```bash
11 | pandoc -f gfm -H deeplists.tex --resource-path ./architecture-overview -s \
12 | -o graph-protocol-v1-spec.pdf README.md ./architecture-overview/README.md \
13 | ./mechanism-design/README.md ./query-processing/README.md ./payment-channels/README.md \
14 | ./read-interface/README.md ./messages/README.md ./rpc-api/README.md \
15 | ./datasets/README.md ./data-modeling/README.md ./subgraph-manifest/README.md \
16 | ./mappings-api/README.md
17 | ```
18 |
--------------------------------------------------------------------------------
/specs/graph-protocol-hybrid-network/deeplists.tex:
--------------------------------------------------------------------------------
1 | \usepackage{enumitem}
2 | \setlistdepth{9}
3 |
4 | \setlist[itemize,1]{label=$\bullet$}
5 | \setlist[itemize,2]{label=$\bullet$}
6 | \setlist[itemize,3]{label=$\bullet$}
7 | \setlist[itemize,4]{label=$\bullet$}
8 | \setlist[itemize,5]{label=$\bullet$}
9 | \setlist[itemize,6]{label=$\bullet$}
10 | \setlist[itemize,7]{label=$\bullet$}
11 | \setlist[itemize,8]{label=$\bullet$}
12 | \setlist[itemize,9]{label=$\bullet$}
13 | \renewlist{itemize}{itemize}{9}
14 |
15 | \setlist[enumerate,1]{label=$\arabic*.$}
16 | \setlist[enumerate,2]{label=$\alph*.$}
17 | \setlist[enumerate,3]{label=$\roman*.$}
18 | \setlist[enumerate,4]{label=$\arabic*.$}
19 | \setlist[enumerate,5]{label=$\alpha*$}
20 | \setlist[enumerate,6]{label=$\roman*.$}
21 | \setlist[enumerate,7]{label=$\arabic*.$}
22 | \setlist[enumerate,8]{label=$\alph*.$}
23 | \setlist[enumerate,9]{label=$\roman*.$}
24 | \renewlist{enumerate}{enumerate}{9}
25 |
--------------------------------------------------------------------------------
/papers/whitepaper/README.md:
--------------------------------------------------------------------------------
1 | # The Graph Whitepaper [Deprecated]
2 |
3 | See the [v1 protocol specification](../../specs/graph-protocol-v1/README.md) for the latest protocol design.
4 |
5 | ## Install MacTeX / TeX Live
6 |
7 | ```sh
8 | brew cask install mactex
9 | ```
10 |
11 | After this, log in to a fresh shell to make sure all TeX Live commands are
12 | available in your `$PATH`.
13 |
14 | ## Build PDF
15 |
16 | ```sh
17 | pdflatex the-graph-whitepaper
18 | ```
19 |
20 | ## Fonts
21 |
22 | A list of font packages that are available in TeXlive out of the box is available
23 | here: https://tex.stackexchange.com/questions/59403/what-font-packages-are-installed-in-tex-live
24 |
25 | To use any of these, you'd typically add
26 | ```latex
27 | \usepackage{gentium}
28 | ```
29 | to the header section of `the-graph-whitepaper.tex`, however, oftentimes the
30 | documentation of the packages describe additional parameters that are worth paying
31 | attention to.
32 |
33 | These are typically found by going to the package on CTAN and following
34 | `Package Documentation` link under `Documentation`. See
35 | https://ctan.org/pkg/psnfss for an example.
36 |
--------------------------------------------------------------------------------
/specs/graph-protocol-hybrid-network/README.md:
--------------------------------------------------------------------------------
1 | # Graph Protocol Specification
2 |
3 | **Version**: 0.0.1
4 |
5 | **Stage**:
6 | 
7 |
8 | **Authors**:
9 | - [Brandon Ramirez](github.com/zerim)
10 |
11 | ## Abstract
12 | This document presents *Graph Protocol* ("the protocol"), a protocol for indexing public blockchain data and querying this data via a decentralized network. The canonical network implementing the protocol is referred to as *The Graph* ("the network").
13 |
14 | Graph Protocol falls into a category we refer to as a *layer 2 read-scalability* solution. Its purpose is to enable decentralized applications (dApps) to query public blockchain data efficiently and trustlessly via a service that, like blockchains and the Internet itself, operates as a public utility. This is in the interest of minimizing the role of brittle, centralized infrastructure seen in many "decentralized" application architectures today.
15 |
16 | This specification covers the network architecture, protocol interfaces, algorithms, and economic incentives required to build a network that is robust, performant, cost-efficient, and enables a high margin of economic security for queries processed via the network.
17 |
18 | ## Philosophy
19 | This spec defines a hybrid network design in which the core mechanisms are decentralized and run on the blockchain, but some building blocks are still centralized. A future version of this specification will target full decentralization. This is in keeping with our team's philosophy of shipping early and delivering immediate value, while incrementally decentralizing, as research and the state of external ecosystem dependencies progress.
20 |
21 | See [this slide](https://www.slideshare.net/secret/AnB7pWnqZhiW2d/17) from this [recent research talk](https://www.youtube.com/watch?v=eRnYgXHQnlA&t=586s) for more info on this approach.
22 |
23 | ## Disclaimer
24 | This spec defines a protocol that is still being implemented. Until a fully stable reference implementation exists, the specification is likely to change in breaking ways.
25 |
--------------------------------------------------------------------------------
/specs/graph-protocol-hybrid-network/datasets/README.md:
--------------------------------------------------------------------------------
1 | # Datasets
2 |
3 | ## Object Diagram
4 | ```ascii
5 | +--------------+ +-------------------+
6 | | | | |
7 | Ethereum | GNS Registry | | Staking Contract |
8 | | | | (Indexing Records)|
9 | | | | |
10 | +--------------+ +-------------------+
11 | |1 |1
12 | | |
13 | +---------------------------------------------------------------------------------+
14 | | |
15 | | +------------+ | +------------+
16 | | | | | | |
17 | | *| Subgraph | *| | Index |
18 | IPFS +-----> Manifest +--v--+ Records |
19 | | |1 *| |
20 | +-----+------+ +------------+
21 | |
22 | +------------+----------+
23 | | |
24 | +--------v-------+ +-------v-------+
25 | | | | |
26 | | Mapping | | Data Model |
27 | | (WASM Module) | | (GraphQL IDL) |
28 | | | | |
29 | +----------------+ +---------------+
30 |
31 | ```
32 |
33 | ## Overview
34 | Datasets that may be queried through The Graph are referred to as *subgraphs* because they represent a subset of the data that is available to query in the network. Subgraphs are defined in a *subgraph manifest*, which is a top-level IPLD document that defines how Ethereum and IPFS data is ingested and loaded into The Graph. Importantly, while the subgraph manifest includes a logical data model for the dataset, it does not specify a specific storage format, database model, or index method. These are defined as *Index Records* and are associated with a subgraph manifest by indexing nodes in the Staking Contract on-chain.
35 |
36 | Subgraph manifests are immutable and referenced according to the [IPLD CID v1 specification](https://github.com/ipld/cid#cidv1). This CID is referred to in this specification as a *Subgraph ID*. Mutable names may be assigned to subgraph IDs via the Graph Name Service (GNS). These are not consumed on-chain anywhere in the protocol and are mainly a convenience for users interacting with The Graph. These names may also be used in composing a unified global schema in the query interface of Query Nodes. See [Query Processing](../query-processing) for more information. In future versions of the protocol, names will play a more useful role in various forms of the subgraph composition.
37 |
38 | ## Subgraph Creation
39 | Creating a subgraph involves the following steps, in no specific order:
40 | - Create subgraph manifest ([Subgraph Manifest](../subgraph-manifest))
41 | - Define data model ([Data Modeling](../data-modeling))
42 | - Define mappings ([Mappings API](../mappings-api))
43 |
44 | ## Subgraph Deployment
45 | Deploying a subgraph involves the following steps:
46 | 1. Deploy subgraph manifest to IPLD and get subgraph ID.
47 | 1. Curate or index the subgraph, referenced by subgraph ID, in the Staking Contract ([Mechanism Design](../mechanism-design)).
48 | 1. (Optional) Associate a human-friendly name with the SubgraphID in the Graph Name Service.
49 |
--------------------------------------------------------------------------------
/specs/graph-protocol-hybrid-network/subgraph-manifest/README.md:
--------------------------------------------------------------------------------
1 | # Subgraph Manifest
2 |
3 | **TODO** This file has moved to https://github.com/graphprotocol/graph-node. Please confirm. Datasets references this file with ../subgraph-manifest, so it needs to remain in this repo.
4 |
5 | ## Overview
6 | The Subgraph manifest specifies all the information required to index and query a specific subgraph. It is the entry point to your subgraph, so to speak.
7 |
8 | The subgraph manifest, and all the files linked from it, are what is deployed to IPFS, and hashed to produce a subgraph ID that can be referenced on Ethereum and used to retrieve your subgraph in The Graph.
9 |
10 | ## Format
11 | The subgraph manifest follows the IPLD specification, which defines a data model for linking decentralized and universally addressable data structures.[1](#footnotes) Supported formats include YAML and JSON. All examples in this section are written as YAML.
12 |
13 | ## Top-Level API
14 |
15 | | Field | Type | Description |
16 | | --- | --- | --- |
17 | | **specVersion** | *String* | A semver version indicating which version of this API is being used.|
18 | | **schema** | [*Schema*](#schema) | The GraphQL schema of this subgraph|
19 | | **dataSources**| [*[Data Source Spec]*](#data-source)| Each Data Source spec defines data which will be ingested, and transformation logic to derive the state of the subgraph's entities based on the source data.|
20 |
21 | ## Schema
22 |
23 | | Field | Type | Description |
24 | | --- | --- | --- |
25 | | **file**| [*Path*](#path) | The path of the GraphQL IDL file, either locally or on IPFS |
26 |
27 | ## Data Source
28 |
29 | | Field | Type | Description |
30 | | --- | --- | --- |
31 | | **kind** | *String | The type of data source. Possible values: *ethereum/contract*|
32 | | **name** | *String* | The name of the source data. Will be used to generate APIs in mapping, and also for self-documentation purposes |
33 | | **source** | [*EthereumContractSource*](#ethereumcontractsource) | The source data on a blockchain such as Ethereum |
34 | | **mapping** | [*Mapping*](#mapping) | The transformation logic applied to the data prior to being indexed |
35 |
36 | ### EthereumContractSource
37 |
38 | | Field | Type | Description |
39 | | --- | --- | --- |
40 | | **address** | *String* | The address of the source data in its respective blockchain |
41 | | **abi** | *String* | The name of the ABI for this Ethereum contract (see `abis` in `mapping` manifest) |
42 |
43 | ### Mapping
44 | The `mapping` field may be one of the following supported mapping manifests:
45 | - [Ethereum Events Mapping](#ethereum-events-mapping)
46 |
47 | #### Ethereum Events Mapping
48 |
49 | | Field | Type | Description |
50 | | --- | --- | --- |
51 | | **kind** | *String* | Must be "ethereum/events" for Ethereum Events Mapping |
52 | | **apiVersion** | *String* | Semver string of the version of the Mappings API which will be used by the mapping script |
53 | | **language** | *String* | The language of the runtime for the Mapping API. Possible values: *wasm/assemblyscript* |
54 | | **entities** | *[String]* | A list of entities which will be ingested as part of this mapping. Must correspond to names of entities in the GraphQL IDL |
55 | | **abis** | *ABI* | ABIs for the contract classes which should be generated in the Mapping ABI. Name is also used to reference the ABI elsewhere in the manifest |
56 | | **eventHandlers** | *EventHandler* | Handlers for specific events, which will be defined in the mapping script |
57 | | **file** | [*Path*](#path) | The path of the mapping script |
58 |
59 | #### EventHandler
60 |
61 | | Field | Type | Description |
62 | | --- | --- | --- |
63 | | **event** | *String* | An identifier for an event which will be handled in the mapping script. For Ethereum contracts, this must be the full event signature to disambiguate from events which may share the same name. |
64 | | **handler** | *String* | The name of an exported function in the mapping script which should handle the specified event. |
65 |
66 | ## Path
67 | A path has one field `path` which either refers to a path of a file on the local dev machine, or an [IPLD link](#footnotes).
68 |
69 | When using the Graph-CLI, local paths may be used during development, and then the tool will take care of deploying linked files to IPFS and replacing the local paths with IPLD links at deploy time.
70 |
71 | | Field | Type | Description |
72 | | --- | --- | --- |
73 | | **path** | *String or IPLD Link* | A path to a local file or an IPLD link |
74 |
75 | ## Footnotes
76 | - [1] https://github.com/ipld/specs
77 | - [2] https://github.com/ipld/specs/blob/master/Codecs/DAG-JSON.md
78 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Graph Protocol Research
2 | This repo contains specifications and research papers related to The Graph, a decentralized query protocol for the decentralized web.
3 |
4 | ## Stages
5 | The following stages apply to papers and specs in this repo.
6 |
7 | | Stage | Description | Badge |
8 | | :----- | :----------- | -----: |
9 | | **WIP** | Specifications which are in progress. Has gaps and is actively being changed and added to. | 
10 | | **Draft** | Specification is a complete draft. Subject to change heavily. | 
11 | | **Stable** | Specification is at a state where it is relatively stable. Only slight improvements should be made to the spec. | 
12 | | **Finished** | Specification has been fully implemented and should not change, except to address critical issues | 
13 | | **Deferred** | Specification made it to at least the "Draft" stage but was later rejected. | 
14 |
15 | ## Papers
16 | - : [The Graph Whitepaper V1 [Deprecated]]() - This was the whitepaper we used to build interest in our protocol, early in 2018, before we had a team, or funding. Its a useful look into some of our early thinking, but should no longer be considered a source of truth for the protocol design.
17 |
18 | ## Specs
19 | - : [Hybrid Network Specification](./specs/graph-protocol-hybrid-network) - This specification is a hybrid protocol design, intended to bridge the gap between our [hosted service](http://thegraph.com) and our fully decentralized network design. Important elements of the decentralized network are covered here, including several economic mechanisms, interfaces and a high level architecture. Several elements are notably still centralized, such as the dispute management process, payment channels and governance.
20 |
21 | ## Implementations
22 |
23 | 🔨 = In Progress
24 |
25 | ✅ = Implemented
26 |
27 | ❌ = Not implemented
28 |
29 |
30 | ### Indexing Nodes
31 | | | [Graph Node](https://github.com/graphprotocol/graph-node) |
32 | | :-------------------- | :----------: |
33 | | **Hybrid Network spec** | |
34 | | *Subgraphs* | ✅ |
35 | | *GraphQL Schemas* | ✅ |
36 | | *WASM Mappings* | ✅ |
37 | | *Index Ethereum Solidity events* | ✅ |
38 | | *Index IPFS data* | ✅ |
39 | | *Read Interface* | ❌ |
40 | | *RPC API* | ❌ |
41 | | *Payment Channels* | ❌ |
42 | | *Work Token Economics* | ❌ |
43 |
44 | ## Contributing
45 | If you have questions about the contents of this repo, feel free to ask questions in the #research channel of our [Discord](http://thegraph.com/discord).
46 |
47 | We don't yet have a formal improvement proposal process, but feel free to submit ideas for improvements to the protocol as issues in this repo.
48 |
49 | If you spot an error, gap or useful clarification in one of the specs or papers, feel free to file an issue (or if it is small, submit a PR directly), and you may be listed as a contributor on the spec, if your issue is accepted 🙂.
50 |
51 | We look forward to some great contributions from our community, thank you in advance! 🗿✨🚀
52 |
53 | ## License
54 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
55 |
56 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
57 |
58 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE GRAPH PROTOCOL INC BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
59 |
60 | Except as contained in this notice, the names "The Graph" or "Graph Protocol" shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from the Graph Protocol Inc. team.
61 |
62 | The Graph is a trademark of Graph Protocol Inc.
63 |
--------------------------------------------------------------------------------
/specs/graph-protocol-hybrid-network/data-modeling/README.md:
--------------------------------------------------------------------------------
1 | # Data Modeling
2 | The schema of your dataset--that is, the entity types, values and relationships that are available to query--are defined through the GraphQL Interface Definition Language (IDL)[1](#footnotes).
3 |
4 | ## Entities
5 |
6 | ## Entities
7 |
8 | Entities are defined as GraphQL types decorated with an `@entity`. All entities must have an `id: ID!` field defined.
9 |
10 | #### Example
11 | Define a `Token` entity:
12 |
13 | ```graphql
14 | @entity
15 | type Token {
16 | # The unique ID of this entity
17 | id: ID!
18 | name: String!
19 | symbol: String!
20 | decimals: Int!
21 | }
22 | ```
23 |
24 | An attribute on an entity type may be specified as unique, in which case the value for that attribute must be unique among all instances of that entity type.
25 |
26 | ### Example
27 | Define a `File` entity with a unique content hash:
28 | ```graphql
29 | @entity
30 | type File {
31 | id: ID!
32 | name: String!
33 | bytes: Bytes!
34 | length: Int!
35 | # Only one File entity may be created with a given
36 | # content hash.
37 | hash: String! @unique
38 | }
39 | ```
40 |
41 | ## Built-In Types
42 |
43 | ### GraphQL Built-In Scalars
44 | All the scalars defined in the GraphQL spec are supported: `Int`, `Float`, `String`, `Boolean`, and `ID`.
45 |
46 | ### Bytes
47 | There is a `Bytes` scalar for variable-length byte arrays.
48 |
49 | Additionally, fixed-length byte scalar types between 1 and 32 bytes are supported: `Byte`, `Bytes1` (an alias for `Byte`), `Bytes2`, `Bytes3` ... `Bytes31`, and `Bytes32`.
50 |
51 | ### Numbers
52 | The GraphQL spec defines `Int` and `Float` to have sizes of 32 bytes.
53 |
54 | This API additionally includes `BigInt` and `BigFloat` number types to represent arbitrarily large integer or floating point numbers, respectively.
55 |
56 | There are also fixed-size number types to represent numbers between 1 and 32 bytes long. The suffix is specified by the number of bits.
57 |
58 | Signed integers all share the `Int` prefix: `Int8`, `Int16`, `Int24`, `Int32` (an alias of `Int`) ... `Int240`, `Int248`, and `Int256`.
59 |
60 | There are corresponding unsigned integer types prefixed with `UInt`: `UInt8`, `UInt16`, `UInt24`, `UInt32` ... `UInt240`, `UInt248`, and `UInt256`.
61 |
62 | All number types other than `Int` and `Float`, which are serialized as JSON number types, are serialized as strings.
63 |
64 | Even though the serialization format is the same, having the sizes captured in the type system provides better self-documentation and enables tooling that generates convenient deserializers in statically typed languages.
65 |
66 | ## Value Objects
67 | All types not decorated with the `@entity` decorator are value objects. Value object types may be used as the type of entity attributes, and do not have unique `id` attributes themselves.
68 |
69 | ## Entity Relationships
70 | An entity may have a relationship to one or more other entities in your data model. Relations are unidirectional.
71 |
72 | Despite being unidirectional, attributes may be defined on entities which facilitate navigating relationships in the reverse direction. See [Reverse Lookups](#reverse-lookups).
73 |
74 | ### Basics
75 |
76 | Relationships are defined on entities just like any other scalar type, except that the type specified is that of another entity.
77 |
78 | #### Example
79 | Define a `Transaction` entity type with an optional one-to-one relationship with a `TransactionReceipt` entity type:
80 | ```graphql
81 | @entity
82 | type Transaction {
83 | id: ID!
84 | transactionReceipt: TransactionReceipt
85 | }
86 |
87 | @entity
88 | type TransactionReceipt {
89 | id: ID!
90 | transaction: Transaction
91 | }
92 | ```
93 |
94 | #### Example
95 | Define a `Token` entity type with a required one-to-many relationship with a `TokenBalance` entity type:
96 | ```graphql
97 | @entity
98 | type Token {
99 | id: ID!
100 | tokenBalances: [TokenBalance!]!
101 | }
102 |
103 | @entity
104 | type TokenBalance {
105 | id: ID!
106 | amount: Int!
107 | }
108 | ```
109 |
110 | ### Reverse Lookups
111 | Reverse lookups can be defined on an entity through the `@derivedFrom` field. This creates a "virtual" field on the entity that may be queried but cannot be set manually through the mappings API. Rather, it is derived from the relationship defined on the other entity.
112 |
113 | The type of a `@derivedFrom` field must be a collection since multiple entities may specify relationships to a single entity.
114 |
115 | #### Example
116 | Define a reverse lookup from a `User` entity type to an `Organization` entity type:
117 | ```graphql
118 | @entity
119 | type Organization {
120 | id: ID!
121 | name: String!
122 | members: [User]!
123 | }
124 |
125 | @entity
126 | type User {
127 | id: ID!
128 | name: String!
129 | organizations: [Organization!] @derivedFrom(field: "members")
130 | }
131 | ```
132 |
133 | ## Footnotes
134 | - [1] http://facebook.github.io/graphql/draft/#sec-Type-System
135 |
--------------------------------------------------------------------------------
/specs/graph-protocol-hybrid-network/mappings-api/README.md:
--------------------------------------------------------------------------------
1 | # Mappings API
2 |
3 | ## Overview
4 | Mappings define how data is extracted or ingested from one or more data sources, transformed, and then loaded in a format that follows a specific data model. At their core, mappings are simply WASM modules, and the mappings API is a set of host external functions that are injected into the WASM runtime and implement a specific interface. These function interfaces are in-protocol.
5 |
6 | Additionally, extra-protocol APIs may be defined in userspace, which implement an API in a higher-level language that compiles to WASM. The Graph Protocol team created one such API, which is included here as a reference example.
7 |
8 | ## WASM API
9 | The Mappings API can be split into two portions, the *ingest* or *extract* API and the *store* API (how data is loaded). We present an ingest API tailored to event-sourcing Ethereum smart contract data, but future versions of the protocol will enable ingest APIs specific to other decentralized data sources. The *store API* will not need to change to support new data sources.
10 |
11 | **Note:** There are also a number of utility functions that are currently injected into the WASM runtime for convenience. These will either be implemented natively in WASM or fully specified in a future version of this spec.
12 |
13 | ### Ingest
14 | #### Ethereum
15 | Data is ingested from Ethereum by event-sourcing Solidity events, as well as other triggers, defined in the subgraph manifest. The WASM module referenced in the subgraph manifest is expected to have handlers that correspond to the handlers defined in the [subgraph manifest](../subgraph-manifest).
16 |
17 | See this [reference implementation](https://github.com/graphprotocol/graph-node/blob/master/runtime/wasm/src/host.rs) for how these handlers should be called.
18 |
19 | Additionally, we inject functions for calling Ethereum smart contracts for additional data that is not included in the Ethereum event:
20 | - ethereum_call
21 |
22 | See this [reference](https://github.com/graphprotocol/graph-node/blob/master/runtime/wasm/src/host_exports.rs) for these additional functions.
23 |
24 | ### Store
25 | The store API includes the following methods:
26 | - set
27 | - get
28 | - remove
29 |
30 | See this [reference implementation](https://github.com/graphprotocol/graph-node/blob/master/runtime/wasm/src/host_exports.rs) for these external functions.
31 |
32 | ### Utilities
33 | We currently inject the following utility functions into the WASM runtime, which may be changed or removed in a future version of the protocol:
34 | - bytes_to_string
35 | - bytes_to_hex
36 | - big_int_to_hex
37 | - big_int_to_i32
38 | - json_to_i64
39 | - json_to_u64
40 | - json_to_f64
41 | - json_to_big_int
42 | - crypto_keccak_256
43 | - big_int_plus
44 | - big_int_minus
45 | - big_int_times
46 | - big_int_divided_by
47 | - big_int_mod
48 | - string_to_h160
49 |
50 | See this [reference implementation](https://github.com/graphprotocol/graph-node/blob/master/runtime/wasm/src/host_exports.rs) for these external functions.
51 |
52 | ## Higher-Level APIs
53 | Higher-level APIs provide context for the low-level APIs, described above, in a higher-level programming language that compiles to WASM.
54 |
55 | ### AssemblyScript
56 | [AssemblyScript](https://github.com/AssemblyScript/assemblyscript/wiki) is a subset of TypeScript that compiles to WASM. It only natively supports a handful of types, 32 and 64-bit floating point and integer numeric types, but we extend the runtime with additional higher-level types, such as `TypedMap` and `BigInt`, to facilitate a more developer-friendly API.
57 |
58 | See this [reference](https://github.com/graphprotocol/graph-ts/blob/master/index.ts) for all types, external functions, and utilities.
59 |
60 | #### Types
61 | ##### Basic Types
62 | - `TypedMap`
63 | - `TypedMapEntry`
64 | - `BytesArray`
65 | - `Bytes`
66 | - `BigInt`
67 | - `Value`
68 | - `ValueKind`
69 | - `ValuePayload`
70 |
71 | ##### Serialization Formats
72 | - `JSONValue`
73 | - `JSONValueKind`
74 | - `JSONValuePayload`
75 |
76 | ##### Ethereum Types
77 | - `EthereumValue`
78 | - `EthereumValueKind`
79 | - `EthereumBlock`
80 | - `EthereumTransaction`
81 | - `EthereumEvent`
82 | - `EthereumEventParams`
83 | - `SmartContractCall`
84 | - `SmartContract`
85 |
86 | ##### Store Types
87 | - `Entity`
88 |
89 | #### Ingest
90 | ##### Ethereum
91 | - `ethereum.call`
92 |
93 | ##### IPFS
94 | - `ipfs.cat`
95 |
96 | #### Store
97 | - `store.set`
98 | - `store.get`
99 | - `store.remove`
100 |
101 | #### Utilities
102 | - `crypto.keccak256`
103 | - `json.fromBytes`
104 | - `json.toI64`
105 | - `json.toU64`
106 | - `json.toF64`
107 | - `json.toBigInt`
108 | - `typeConversion.bytesToString`
109 | - `typeConversion.bytesToHex`
110 | - `typeConversion.bigIntToString`
111 | - `typeConversion.stringToH160`
112 | - `typeConversion.i32ToBigInt`
113 | - `typeConversion.bigIntToI32`
114 | - `bigInt.plus`
115 | - `bigInt.minus`
116 | - `bigInt.times`
117 | - `bigInt.dividedBy`
118 | - `bigInt.mod`
119 |
--------------------------------------------------------------------------------
/specs/graph-protocol-hybrid-network/rpc-api/README.md:
--------------------------------------------------------------------------------
1 | # JSON RPC API
2 |
3 | This API uses JSON RPC 2.0[1](#footnotes), a light-weight, transport agnostic RPC protocol.
4 |
5 | ## Methods
6 |
7 | - getPrices
8 | - ping
9 | - callReadOp
10 |
11 | ## Reference
12 |
13 | ### getPrices
14 | Retrieves the gas and bandwidth pricing of an Indexing Node in a specific token denomination. Prices returned are informational only, they do not represent a commitment by the Indexing Node.
15 |
16 | #### Parameters
17 | 1. `String` (optional) - The symbol of the token which prices are being requested in. Valid values are 'ETH' or 'DAI'. If not specified, prices will be returned for all tokens the node denominates prices in.
18 |
19 | #### Returns
20 | `Array