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

Feature/near data source template #824

Draft
wants to merge 2 commits into
base: ci/sf/feature/schema-per-protocol
Choose a base branch
from

Conversation

maoueh
Copy link
Contributor

@maoueh maoueh commented Jan 29, 2022

No description provided.

This will make it easier to add new network and will improve error messages when someone will be using fields that do not exist on a specific network but does in other (`temlates` for example used in NEAR were given a bunch of errors like the support was possible while it should have displayed an error on the `templates` node itself).

Using `templates` on NEAR before this PR:

```
✔ Apply migrations
✖ Failed to load subgraph from ../graph-node-dev/subgraphs/near/data-source/testnet.yaml: Error in ../graph-node-dev/subgraphs/near/data-source/testnet.yaml:

  Path: templates > 0 > source
  No value provided

  Path: templates > 0 > mapping
  Unexpected key in map: receiptHandlers

  Path: templates > 0 > mapping > abis
  No value provided
```

And with this PR:

```
$ ./bin/graph build ../graph-node-dev/subgraphs/near/data-source/testnet.yaml
✖ Failed to load subgraph from ../graph-node-dev/subgraphs/near/data-source/testnet.yaml: Error in ../graph-node-dev/subgraphs/near/data-source/testnet.yaml:

  Path: /
  Unexpected key in map: templates
```
@maoueh maoueh changed the base branch from master to ci/sf/feature/schema-per-protocol January 29, 2022 03:07
@evaporei evaporei self-requested a review February 2, 2022 11:55
}

generateModuleImports() {
return []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you'll need to add 'near' here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not required because there is actually no near type involved in the generated code:

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

export class receipts extends DataSourceTemplate {
  static create(account: string): void {
    DataSourceTemplate.create("receipts", [account]);
  }

  static createWithContext(account: string, context: DataSourceContext): void {
    DataSourceTemplate.createWithContext("receipts", [account], context);
  }
}

I tested the full flow of NEAR data source template and it worked great.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see why I thought that, that's because you're not using the Account type from the near module. I would prefer that instead of using string directly. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ambivalent.

If we go with Account, it should be used thoroughly everywhere, right now it's a mixed usage in graph-ts (mostly 50/50).

The second thing that makes it me doubt is how people on NEAR are used to work directly with string. I've research this a little bit and it seems AccountId is used more (https://github.com/near/near-sdk-rs/blob/05c389c75a568af3f37a3346d6f7b4064852e1de/near-sdk/src/types/account_id.rs#L39) although I've seen various example dealing with String directly. The AssemblyScript however does not seems to have an AccountId alias and seems to deal with string directly: https://github.com/near/near-sdk-as/blob/master/sdk-core/assembly/contract.ts#L12.

I prefer string personally as it make the cognitive load lower. If we choose to still wrap it, I'm voting more for AccountId to align with the Rust SDK for NEAR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I see 🤔

Well we can discuss that later then, I'm gonna merge this, thanks for the PR!!

@evaporei evaporei force-pushed the ci/sf/feature/schema-per-protocol branch from 6235e0a to 00427b7 Compare February 8, 2022 12:36
@evaporei
Copy link
Contributor

@maoueh this is missing a conflict resolution because of the refactor you've done that got merged into master

@maoueh
Copy link
Contributor Author

maoueh commented Feb 14, 2022

We will wait until the actual feature in graph-node is ready to ship, which is not the case now. I will turn that to Draft until progress is made there.

@maoueh maoueh marked this pull request as draft February 14, 2022 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants