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

chore: Fix mock ASE seeding script #3050

Merged
merged 5 commits into from
Nov 5, 2024

Conversation

oana-lolea
Copy link
Contributor

@oana-lolea oana-lolea commented Oct 29, 2024

Changes proposed in this pull request

  • Added checks if assets, peers and wallet addresses already exist.
  • If they do, they are returned. Otherwise, they are created as usual.

Context

When spinning up the local environment and the database volumes were not removed, the mock ASE seeding script tries to create assets, peers and wallet addresses to populate the database, but fails, because the values already exists and the mock user accounts are not created.

By checking if the data already exists by querying by their unique entries, this issue can be fixed. If an entry already exist, the seeding script will use those instead of creating them.

Added #3052 issue for updating the commands in the user docs.

Fixes #2945

Checklist

  • Related issues linked using fixes #number
  • Tests added/updated
  • Make sure that all checks pass
  • Bruno collection updated (if necessary)
  • Documentation issue created with user-docs label (if necessary)
  • OpenAPI specs updated (if necessary)

@github-actions github-actions bot added type: tests Testing related pkg: backend Changes in the backend package. pkg: frontend Changes in the frontend package. type: source Changes business logic pkg: auth Changes in the GNAP auth package. pkg: mock-ase pkg: mock-account-service-lib labels Oct 29, 2024
Copy link

netlify bot commented Oct 29, 2024

Deploy Preview for brilliant-pasca-3e80ec canceled.

Name Link
🔨 Latest commit 0582c3a
🔍 Latest deploy log https://app.netlify.com/sites/brilliant-pasca-3e80ec/deploys/6729eb5a74cffd00085c6aa1

Copy link
Contributor

@mkurapov mkurapov left a comment

Choose a reason for hiding this comment

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

Works for me after spinning the env down! Just some minor comments

packages/auth/src/graphql/schema.graphql Outdated Show resolved Hide resolved
packages/mock-account-service-lib/src/requesters.ts Outdated Show resolved Hide resolved
@@ -2,6 +2,14 @@ type Query {
"Fetch an asset by its ID."
asset("Unique identifier of the asset." id: String!): Asset

"Get an asset based on its currency code and scale if it exists."
assetByCodeAndScale(
Copy link
Contributor

Choose a reason for hiding this comment

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

we should add bruno requests for these queries

Copy link
Contributor

Choose a reason for hiding this comment

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

Just thinking out loud, but another option would be to not actually add these resolvers but just use assets and peers queries to fetch all assets & peers. But I think these might be useful to include.

@oana-lolea @BlairCurrey opinions on this?

Copy link
Contributor

Choose a reason for hiding this comment

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

An asset code and scale combination is unique, right? Might make sense for the graphql schema to reflect that in some way.

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 thought these queries might be reused in the future, because they are searching by the unique column(s) of the tables. But if not, I can just filter everything in the script and it might be a bit faster than just querying the db that much.

Copy link
Contributor

Choose a reason for hiding this comment

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

An asset code and scale combination is unique, right?

Yes, has a unique constraint in DB.

@njlie what do you mean by "Might make sense for the graphql schema to reflect that in some way."?

Copy link
Contributor

@njlie njlie Nov 4, 2024

Choose a reason for hiding this comment

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

What I mean to say is, from the point of view of someone integrating with the Admin GraphQL API and looking at it for the first time, seeing a resolver like assetByCodeAndScale would be an effective way to communicate to that audience that those two fields together is a unique combination

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I see what you mean. As in, the schema itself reflects to the integrator about how assets work. I thought you meant we needed to add a comment or something to the schema. Understand now.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree in general, let's keep these resolvers. @oana-lolea I think the outstanding item is just to remove some lines in the resolver test file

@mkurapov
Copy link
Contributor

mkurapov commented Oct 30, 2024

@oana-lolea make sure to go through the PR checklist as well

@github-actions github-actions bot removed the pkg: auth Changes in the GNAP auth package. label Oct 30, 2024
@@ -2,6 +2,14 @@ type Query {
"Fetch an asset by its ID."
asset("Unique identifier of the asset." id: String!): Asset

"Get an asset based on its currency code and scale if it exists."
assetByCodeAndScale(
Copy link
Contributor

Choose a reason for hiding this comment

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

Just thinking out loud, but another option would be to not actually add these resolvers but just use assets and peers queries to fetch all assets & peers. But I think these might be useful to include.

@oana-lolea @BlairCurrey opinions on this?

mkurapov
mkurapov previously approved these changes Nov 5, 2024
@oana-lolea oana-lolea merged commit b912bff into main Nov 5, 2024
30 of 42 checks passed
@oana-lolea oana-lolea deleted the 2945-update-mock-ase-seeding-script branch November 5, 2024 10:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: backend Changes in the backend package. pkg: frontend Changes in the frontend package. pkg: mock-account-service-lib pkg: mock-ase type: source Changes business logic type: tests Testing related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make mock ASE seeding script smarter
3 participants