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

Codegen does not import Address type if file/ipfs template is declared first under templates #1453

Closed
dimitrovmaksim opened this issue Sep 12, 2023 · 1 comment · Fixed by #1504
Assignees
Labels
bug Something isn't working

Comments

@dimitrovmaksim
Copy link
Member

dimitrovmaksim commented Sep 12, 2023

Which packages are impacted by your issue?

@graphprotocol/graph-cli

Describe the issue

Declaring the templates in the following order

templates:
  - kind: ethereum/contract
    name: GraphTokenLockWallet
    network: mainnet
    source:
      abi: GraphTokenLockWallet
    mapping:
      kind: ethereum/events
      apiVersion: 0.0.7
      language: wasm/assemblyscript
      file: ./src/token-lock-wallet.ts
      entities:
        - TokenLockWallet
      abis:
        - name: GraphTokenLockWallet
          file: ./abis/GraphTokenLockWallet.json
      eventHandlers:
        - event: TokensReleased(indexed address,uint256)
          handler: handleTokensReleased
  - name: TokenMetadata
    kind: file/ipfs
    mapping:
      apiVersion: 0.0.7
      language: wasm/assemblyscript
      file: ./src/mapping.ts
      handler: handleMetadata
      entities:
        - TokenMetadata
      abis:
        - name: GraphTokenLockWallet
          file: ./abis/GraphTokenLockWallet.json

will generate the following imports in generated/templates.ts:

import {
  Address,
  DataSourceTemplate,
  DataSourceContext
} from "@graphprotocol/graph-ts";

but if the file/ipfs template is declared before the ethereum/contract the Address import is missing

templates:
  - name: TokenMetadata
    kind: file/ipfs
    mapping:
      apiVersion: 0.0.7
      language: wasm/assemblyscript
      file: ./src/mapping.ts
      handler: handleMetadata
      entities:
        - TokenMetadata
      abis:
        - name: GraphTokenLockWallet
          file: ./abis/GraphTokenLockWallet.json
  - kind: ethereum/contract
    name: GraphTokenLockWallet
    network: mainnet
    source:
      abi: GraphTokenLockWallet
    mapping:
      kind: ethereum/events
      apiVersion: 0.0.7
      language: wasm/assemblyscript
      file: ./src/token-lock-wallet.ts
      entities:
        - TokenLockWallet
      abis:
        - name: GraphTokenLockWallet
          file: ./abis/GraphTokenLockWallet.json
      eventHandlers:
        - event: TokensReleased(indexed address,uint256)
          handler: handleTokensReleased

generated/templates.ts

import { DataSourceTemplate, DataSourceContext } from "@graphprotocol/graph-ts";

Reproduction

https://github.com/LimeChain/demo-subgraph/tree/codegen-missing-imports

Steps to Reproduce the Bug or Issue

  1. Go to https://github.com/LimeChain/demo-subgraph
  2. Clone the repo
  3. Fetch and checkout into codegen-missing-imports
  4. Install deps
  5. Run codegen
  6. Check imports in generated/templates.ts. Address import is missing, but is required by GraphTokenLockWallet create/createWithContext
  7. Switch order of declared templates in subgraph.yaml
  8. Run codegen again
  9. Check imports in generated/templates.ts. Address import is present

Expected behavior

It should import all required types

Screenshots or Videos

No response

Platform

@graphprotocol/graph-cli/0.57.0 darwin-arm64 node-v18.17.0

Subgraph Manifest

No response

Subgraph GraphQL Schema

No response

Additional context

No response

@dimitrovmaksim dimitrovmaksim added the bug Something isn't working label Sep 12, 2023
@dimitrovmaksim dimitrovmaksim changed the title Codegen does not import Address type if file/ipfs template is declared before ethereum/contract in subgraph.yaml Codegen does not import Address type if file/ipfs template is declared first under templates Sep 12, 2023
@azf20 azf20 added this to Tooling Sep 15, 2023
@azf20
Copy link
Contributor

azf20 commented Sep 15, 2023

thanks @dimitrovmaksim! @saihaj could you take a look?

@saihaj saihaj self-assigned this Sep 15, 2023
@saihaj saihaj moved this to 🔖 Next in Tooling Sep 15, 2023
@theguild-bot theguild-bot mentioned this issue Oct 31, 2023
26 tasks
@github-project-automation github-project-automation bot moved this from 🔖 Next to ✅ Done in Tooling Nov 15, 2023
This was referenced Apr 30, 2024
This was referenced May 7, 2024
@theguild-bot theguild-bot mentioned this issue Oct 15, 2024
26 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants