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

Adding type and version to graphQL pool models: #456

Merged
merged 2 commits into from
Sep 21, 2023

Conversation

lgahdl
Copy link
Contributor

@lgahdl lgahdl commented Sep 15, 2023

  • GqlPoolBase;
  • GqlPoolWeighted;
  • GqlPoolStable;
  • GqlPoolPhantomStable;
  • GqlPoolMetaStable;
  • ..and all the other Pools of GqlPoolUnion type

- GqlPoolBase;
- GqlPoolWeighted;
- GqlPoolStable;
- GqlPoolPhantomStable;
- GqlPoolMetaStable;
- ..and all the other Pools of GqlPoolUnion type
@lgahdl lgahdl requested a review from franzns September 15, 2023 22:39
@franzns
Copy link
Contributor

franzns commented Sep 18, 2023

What is the reason for this?

@lgahdl
Copy link
Contributor Author

lgahdl commented Sep 18, 2023

What is the reason for this?

The type of the pool is a required parameter for the b-sdk:

export type PoolState = {
    id: Address;
    address: Address;
    type: string;
    tokens: {
			address: Address;
			decimals: number;
			index: number;
}[];

@franzns
Copy link
Contributor

franzns commented Sep 18, 2023

you can query the type via __typename in the pools Object which returns you the name of the GQL model (e.g. GqlPoolWeighted). Is that sufficient?

@lgahdl
Copy link
Contributor Author

lgahdl commented Sep 18, 2023

you can query the type via __typename in the pools Object which returns you the name of the GQL model (e.g. GqlPoolWeighted). Is that sufficient?

It would work, but, for example, to check if a Gyro Pool is Gyro2, Gyro3 or GyroE, it would need to look what factory created the pool, because all of them has the __typename "GqlPoolGyro", in my opinion it's easier to use this "type" parameter, and I'm thinking about the same thing for the "version", that is also not in the models, maybe it would be good to add "version" as well in the gql models, because some pool versions has different token ordering than others, what do you think?

@franzns
Copy link
Contributor

franzns commented Sep 19, 2023

Ok, makes sense. But it doesnt work like this.

  1. You only need to add it to GqlPoolBase, as all other extend that model
  2. You also need to populate that field in pool-gql-loader.service.ts
  3. Might also make sense to add it to GqlPoolMinimal

You want to give that a shot?

@lgahdl
Copy link
Contributor Author

lgahdl commented Sep 19, 2023

Hi @franzns! I made the changes to add "version" to all types, and I already tested for poolGetPools and poolGetPool methods, it's working fine. It wasn't necessary to populate these fields on "pool-gql-loader.service.ts", they come automatically populated because they're already part of "GqlPoolMinimal" and "GqlPoolBase" at schema.ts, so these fields don't need to be included manually, just like "id", "name", "symbol", and other base fields.

About the "1. You only need to add it to GqlPoolBase, as all others extend that model", this type of inheritance is not available in the basic graphQL, the interface "implements" keyword requires the child type to have inherited fields written(like id, name, chain, and others), but there are some packages that make possible to create directives and implement this type of functionality for graphQL, I can search further if you like, the most trustable one seems to be "@graphql-tools/utils".

StackOverflow Question about graphQL inheritance: https://stackoverflow.com/questions/47523384/how-to-inherit-or-extend-typedefs-in-graphql
Implementing this Inheritance in graphQL: https://nelsondominguez.hashnode.dev/inheritance-in-graphql-when-and-how-to-use-it
Package that implements graphQL directives: https://the-guild.dev/graphql/tools/docs/schema-directives

@lgahdl lgahdl changed the title Adding type to graphQL pool models: Adding type and version to graphQL pool models: Sep 20, 2023
@franzns
Copy link
Contributor

franzns commented Sep 21, 2023

Thanks luiz!

@franzns franzns merged commit 0cf960d into v3-canary Sep 21, 2023
1 check passed
@franzns franzns deleted the adding-type-pool-gql branch September 21, 2023 08:34
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