Git Product home page Git Product logo

graph-tooling's Introduction

The Graph Tooling

Monorepo for various tools used by subgraph developers.

This repository houses the following tools:

NPM Name
npm (scoped) @graphprotocol/graph-cli
npm (scoped) @graphprotocol/graph-ts

Contributing

We welcome contributions to this repository. Please see the contribution guidelines. For running the project locally,

  1. Clone the repository
  2. Make sure you have Node.js >=20.x installed
  3. Make sure you have [pnpm] installed: https://pnpm.io/installation
  4. Run pnpm install to install dependencies
  5. Run pnpm build to build the packages

Release process

We use changeset to manage releases. Every PR should include a changeset file. The release process is as follows:

  1. Author creates the PR with changes and runs pnpm changeset to create a changeset file to summarize the changes.
  2. When the PR is merged to main, a Github Action will run and create a PR with the version bump and changelog.
  3. We will merge the bot generated PR to main.
  4. A Github Action will run and publish the new version to npm.

Helpful links:

Stable release example

When PRs are merged and to main we can choose to merge the bot generated changeset PR to main and it will publish a new version to npm.

Example of a graph-client release: graphprotocol/graph-client#295

Alpha release example

Every PR to main that includes a changeset file will create a new alpha version.

Example of graph-client snapshot release: graphprotocol/graph-client#178 (comment)

License

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

The Graph CLI 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-tooling's People

Contributors

azf20 avatar davekaj avatar dependabot-preview[bot] avatar dependabot[bot] avatar dimitrovmaksim avatar dotansimha avatar enisdenjo avatar evaporei avatar fordn avatar fubhy avatar georg-getz avatar github-actions[bot] avatar html5cat avatar incrypto32 avatar jannis avatar leoyvens avatar lutter avatar maoueh avatar petkodes avatar pienkowb avatar pranavdaa avatar promaty avatar renovate[bot] avatar saihaj avatar schmidsi avatar shiyasmohd avatar theguild-bot avatar tilacog avatar timmclean avatar vivelev 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

graph-tooling's Issues

Support custom path for mapping entry point

Currently while running the-graph-wasm compile data-source.yaml the script looks for a file called mapping.ts in the root directory, even if a different file path is specified in the data source definition.

Fails generating types for ABI with a public mapping getter

Error

When generating the TypeScript types for Decentraland's LAND Marketplace, the type generator fails to properly parse an empty input name in the ABI, which represents a public getter for a mapping:

Marketplace.sol

mapping (uint256 => Auction) public auctionByAssetId;

Marketplace.json

{
    "constant": true,
    "inputs": [
      {
        "name": "",
        "type": "uint256"
      }
    ],
    "name": "auctionByAssetId",
    "outputs": [
      {
        "name": "id",
        "type": "bytes32"
      },
      {
        "name": "seller",
        "type": "address"
      },
      {
        "name": "price",
        "type": "uint256"
      },
      {
        "name": "expiresAt",
        "type": "uint256"
      }
    ],
    "payable": false,
    "stateMutability": "view",
    "type": "function"
  },

Error Message

$ the-graph-wasm generate-types --output-dir types/ data-source.yaml
[1/3] Load data source: data-source.yaml
[2/3] Load contract ABIs
Load contract ABI file: abis/Marketplace.json
[3/3] Generate types for contract ABIs
Generate types for contract ABI: Marketplace.json
Failed to generate types for contract ABI: { SyntaxError: Parameter declaration expected. (65:20)
  63 |   }
  64 | 
> 65 |   auctionByAssetId(: U256): Marketplace__auctionByAssetIdResult {let __result = super.call(
     |                    ^
  66 |                    'auctionByAssetId',
  67 |                    [Token.fromU256()]
  68 |                  )
    at e (/Users/aklempner/Repos/Graph/decentraland-mapping/the-graph-wasm/examples/example-event-handler/node_modules/the-graph-wasm/node_modules/prettier/parser-typescript.js:1:329)
    at Object.parse (/Users/aklempner/Repos/Graph/decentraland-mapping/the-graph-wasm/examples/example-event-handler/node_modules/the-graph-wasm/node_modules/prettier/parser-typescript.js:1:1844304)
    at Object.parse$2 [as parse] (/Users/aklempner/Repos/Graph/decentraland-mapping/the-graph-wasm/examples/example-event-handler/node_modules/the-graph-wasm/node_modules/prettier/index.js:7000:19)
    at coreFormat (/Users/aklempner/Repos/Graph/decentraland-mapping/the-graph-wasm/examples/example-event-handler/node_modules/the-graph-wasm/node_modules/prettier/index.js:10196:23)
    at format (/Users/aklempner/Repos/Graph/decentraland-mapping/the-graph-wasm/examples/example-event-handler/node_modules/the-graph-wasm/node_modules/prettier/index.js:10367:16)
    at formatWithCursor (/Users/aklempner/Repos/Graph/decentraland-mapping/the-graph-wasm/examples/example-event-handler/node_modules/the-graph-wasm/node_modules/prettier/index.js:10379:12)
    at /Users/aklempner/Repos/Graph/decentraland-mapping/the-graph-wasm/examples/example-event-handler/node_modules/the-graph-wasm/node_modules/prettier/index.js:31222:15
    at Object.format (/Users/aklempner/Repos/Graph/decentraland-mapping/the-graph-wasm/examples/example-event-handler/node_modules/the-graph-wasm/node_modules/prettier/index.js:31241:12)
    at TypeGenerator._generateTypesForABI (/Users/aklempner/Repos/Graph/decentraland-mapping/the-graph-wasm/examples/example-event-handler/node_modules/the-graph-wasm/cli-lib/type-generator.js:95:36)
    at abis.map (/Users/aklempner/Repos/Graph/decentraland-mapping/the-graph-wasm/examples/example-event-handler/node_modules/the-graph-wasm/cli-lib/type-generator.js:83:43)

Reproducing

git clone [email protected]:graphprotocol/the-graph-wasm.git
cd the-graph-wasm
git checkout decentraland-mapping
yarn
cd examples/decentraland
yarn
yarn build

Pinpoint AssemblyScript dependency version

It seems we currently depend on the latest master of AssemblyScript, which is scary since the way we pass data around is coupled with the Asc ABI which could change at any moment. We should pinpoint our Asc version, even if it's to a commit hash.

Add WASM-side conversion between ByteArray and U64Array

For instance, there are cases where we'll need to take a U256 and convert it to an address via either Token.fromU256(value).toAddress() or directly from value.toAddress().

This is required for the MemeFactory data source.

Add overloaded SmartContract.bind() function that can take a string

There are situations where developers will want to hard-code contract addresses in mappings, in order to bind them with e.g.

let contract = SomeContract.bind(Address.fromString("0x..."), event.blockHash)
...

However, there no way to convert from a string to an address in our mappings.

Implement init command: create skeleton project

  • Initialize project directory with generic files: subgraph.yaml, package.json, schema.graphql, tsconfig.json.
  • Create the ./mappings and ./abis directories with a single file in each?
  • Files contain usage instructions in comment block on top?

Add contributing.md to graph-cli

Leo - please coordinate with Nena on the common set of contributing guidelines that are not rust-specific (she's writing them for the Typescript repo).

Namespace or de-duplicate conflicting ABI types

Livepeer reported that their contracts BondingManager and RoundsManager share some types, causing a name conflict when the ABIs of both contracts are added to a same mapping. The best solution would be to namespace the types by contract, but in this case since the types are equal de-duplicating would suffice.

Watch Mode

Right now, after each change to a mapping, the developer has to complete the following steps:

  • Generate types to write your mappings
  • Compile your subgraph and mappings
  • Deploy your subgraph manifest to IPFS
  • Deploy your subgraph to Graph Node
    It would be much better if this could all be done in a single step during development and if that command could be executed on save.

"Heap out of memory" error running `yarn build` in Decentraland example

Reproducing

git clone [email protected]:graphprotocol/the-graph-wasm.git
cd the-graph-wasm
git checkout marketplace-mapping-error
yarn
cd examples/decentraland
yarn
yarn build

Error Message

yarn build
yarn run v1.3.2
warning package.json: No license field
warning ../../package.json: No license field
$ the-graph-wasm compile data-source.yaml
[1/10] Load data source: data-source.yaml
[2/10] Create build directory
[3/10] Copy data source to build directory
Copy data source file: schema.graphql
Copy data source file: abis/Marketplace.json
Copy data source file: mapping.ts
[4/10] Generate types from contract ABIs
..... [1/3] Load data source
..... [2/3] Load contract ABIs
..... [3/3] Generate types for contract ABIs
..... Generate types for contract ABI: Marketplace.json
..... Write types to: Marketplace.types.ts
[5/10] Copy runtime to build directory
Copy runtime file: index.ts
[6/10] Add generated types to runtime
Add types from file to runtime: Marketplace.types.ts
[7/10] Add mapping to runtime
[8/10] Create output directory: /Users/aklempner/Repos/Graph/decentraland-mapping/the-graph-wasm/examples/decentraland/dist
[9/10] Compile data source
Compile data set mapping: Marketplace / mapping.ts

<--- Last few GCs --->

[24775:0x102801e00]    11261 ms: Mark-sweep 1296.9 (1355.3) -> 1296.6 (1360.8) MB, 971.1 / 0.0 ms  allocation failure GC in old space requested
[24775:0x102801e00]    12162 ms: Mark-sweep 1296.6 (1360.8) -> 1296.6 (1323.3) MB, 900.9 / 0.0 ms  last resort GC in old space requested
[24775:0x102801e00]    13008 ms: Mark-sweep 1296.6 (1323.3) -> 1296.6 (1323.3) MB, 845.6 / 0.0 ms  last resort GC in old space requested


<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 0x12daf8f257c1 <JSObject>
    1: /* anonymous */ [/Users/aklempner/Repos/Graph/decentraland-mapping/the-graph-wasm/examples/decentraland/node_modules/the-graph-wasm/node_modules/assemblyscript/dist/assemblyscript.js:~1] [pc=0x30b42e662d7b](this=0x12da8d102749 <t map = 0x12da9da87e21>,e=0x12da1807c099 <t map = 0x12da9da888c9>)
    2: /* anonymous */ [/Users/aklempner/Repos/Graph/decentraland-mapping/the-graph-wasm/example...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [/Users/aklempner/.nvm/versions/node/v8.11.1/bin/node]
 2: node::FatalException(v8::Isolate*, v8::Local<v8::Value>, v8::Local<v8::Message>) [/Users/aklempner/.nvm/versions/node/v8.11.1/bin/node]
 3: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/Users/aklempner/.nvm/versions/node/v8.11.1/bin/node]
 4: v8::internal::Factory::NewUninitializedFixedArray(int) [/Users/aklempner/.nvm/versions/node/v8.11.1/bin/node]
 5: v8::internal::(anonymous namespace)::ElementsAccessorBase<v8::internal::(anonymous namespace)::FastPackedObjectElementsAccessor, v8::internal::(anonymous namespace)::ElementsKindTraits<(v8::internal::ElementsKind)2> >::GrowCapacity(v8::internal::Handle<v8::internal::JSObject>, unsigned int) [/Users/aklempner/.nvm/versions/node/v8.11.1/bin/node]
 6: v8::internal::Runtime_GrowArrayElements(int, v8::internal::Object**, v8::internal::Isolate*) [/Users/aklempner/.nvm/versions/node/v8.11.1/bin/node]
 7: 0x30b42e4842fd
 8: 0x30b42e662d7b
 9: 0x30b42e66b0a4
10: 0x30b42e48535f
11: 0x30b42e645af8
  Done in 13.26s.

Implement TypedMap on top of WASM memory

Current idea: Use an Array<TypedMapEntry> where TypedMapEntry { key: T, value: V } to represent the key/value pairs. This way we can piggieback on the existing Array implementation in AssemblyScript.

Provide event-specific event classes for use in WASM handlers

WASM-only solution

There’s an easy solution that’s purely on the WASM side: We could generate

class AuctionCreatedEvent extends EthereumEvent {
  id(): Bytes { return this.params[0].value }
  assetId(): H256 { return this.params[1].value }
  seller(): string { return this.params[2].value }
}

When people then write handlers like

handleAuctionCreatedEvent(event: AuctionCreatedEvent) { ... }

they could use event.id(), event.seller(). (edited)
That requires no magic at all in Rust.

Rust solution

We could try using generics like

Event1<T>
Event2<T,U>
Event3<T,U,V>
...

and write Asc type conversions for the. The names of the parameters don't matter, just their order and their types.

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.