Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Graph Project Migration, migrate AS to TS #2389

Open
stwiname opened this issue May 6, 2024 · 1 comment
Open

Graph Project Migration, migrate AS to TS #2389

stwiname opened this issue May 6, 2024 · 1 comment
Labels

Comments

@stwiname
Copy link
Collaborator

stwiname commented May 6, 2024

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.

@stwiname stwiname added the cli label May 9, 2024
@stwiname
Copy link
Collaborator Author

stwiname commented Jun 4, 2024

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
Labels
Projects
None yet
Development

No branches or pull requests

1 participant