Skip to content

Graph Project Migration, migrate AS to TS #2389

Open

Description

@stwiname

Description

Subgraphs use AssemblyScript which is a subset of Typescript, to write their mapping handlers. SubQuery uses Typescript for its handlers. The CLI migrate command should be updated to convert the Subgraph handlers into SubQuery compatible handlers.

Requirements

  • Test coverage of at least 80% for new code changes
  • Generate code that uses Subquery best practices and optimisations
  • Require no more user interaction than is currently required
  • Generate the same folder structure as used in SubQuery starters
  • A best effort to have code that compiles without any changes. This should cover all trivial cases

Code changes

This is the bulk of the required changes:

  • Imports
    • Remove imports for graph dependencies
    • Update imports for generated code
  • Function signatures
    • Update handler arguments to use the types generated using subql codegen
    • Update handler functions to be async
  • Update accessing properties from event/transaction/block
  • Entities
    • Update Entity.load to await Entity.get. Note: subquery returns undefined instead of null if the entity is not defined
    • Update creating entities to use Entitiy.create where possible
    • Update entity.save() to await entity.save()
  • Contract calls
    • Use generated factories to create instances of contracts
    • Use methods from contract instances

Implementation

The entrypoint for these changes should be done here

The implementation should use the Typescript Compiler API to traverse the AST and make changes.

Activity

  1. stwiname commented on Jun 4, 2024

    @stwiname
    CollaboratorAuthor

    This library might be a better option than using the TS compiler API https://github.com/dsherret/ts-morph/tree/latest/packages/ts-morph

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ Proxy