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

Create collections top level entity in GraphQL #214

Merged

Conversation

pheuberger
Copy link
Member

@pheuberger pheuberger commented Jan 20, 2025

Without this PR the user of our GraphQL endpoints needs to go via hyperboards to access the collections inside. Another drawback is that via this query they can only access the hypercert id, so they'll have to fire a separate query to combine the data.

This PR adds collections as a top level entity and exposes full hypercert objects as child entities. This also applies to hyperboards as the standalone collections entity is being reused there too.

This PR also provides a fix for hyperboard sorting.

Incidentally the tests around signature verification were broken, which blocked this PR. I refactored the tests to not rely on the Alchemy API key to fix the issues.

Copy link
Contributor

@Jipperism Jipperism left a comment

Choose a reason for hiding this comment

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

Tested with hyperboards widget, and AFAICT everything still works.

src/graphql/schemas/typeDefs/baseTypes/basicTypeDef.ts Outdated Show resolved Hide resolved
src/utils/envVars.ts Show resolved Hide resolved
This sort function was only built to work with a few very specific types
from the Caching DB. However, it was used on data that wasn't meant for
the caching DB. Namely the Blueprints and perhaps others.

This implements basic sorting for all database types.
@pheuberger
Copy link
Member Author

pheuberger commented Jan 22, 2025

@bitbeckers Unit tests are failing now given the coverage requirements, which is blocking this PR. What's the best way forward?

ERROR: Coverage for lines (17.53%) does not meet global threshold (20%)
ERROR: Coverage for functions (54.65%) does not meet global threshold (60%)
ERROR: Coverage for statements (17.53%) does not meet global threshold (20%)

@bitbeckers
Copy link
Collaborator

@pheuberger where does the regression come from? If it's about the Services we can lower the threshold as we'll soon focus on #218

@bitbeckers Unit tests are failing now given the coverage requirements, which is blocking this PR. What's the best way forward?

ERROR: Coverage for lines (17.53%) does not meet global threshold (20%)
ERROR: Coverage for functions (54.65%) does not meet global threshold (60%)
ERROR: Coverage for statements (17.53%) does not meet global threshold (20%)

@pheuberger
Copy link
Member Author

pheuberger commented Jan 23, 2025

@pheuberger where does the regression come from? If it's about the Services we can lower the threshold as we'll soon focus on #218

@bitbeckers Unit tests are failing now given the coverage requirements, which is blocking this PR. What's the best way forward?

ERROR: Coverage for lines (17.53%) does not meet global threshold (20%)
ERROR: Coverage for functions (54.65%) does not meet global threshold (60%)
ERROR: Coverage for statements (17.53%) does not meet global threshold (20%)

Yes, it must be the services, as that's the majority of code added outside of graphql/ which is already excluded from coverage. Otherwise there are mostly 1:1 changes, so the coverage shouldn't have changed for any of those. So, as you're saying, we're going to tackle #218 and thus will have to re-evaluate thresholds completely, so I'll downgrade them for the time being.

I ignored services/ for now @bitbeckers. Once your refactor is completed, we should turn it back on. I also lowered the coverage thresholds in the commits that are responsible for going below the thresholds with a small explanation why, so everything is neat and tidy.

Our services are difficult to test at the moment and we don't really
have tests for them. However, when you make changes to the GraphQL
schema and potentially introduce new entities, you'll also alway have to
add code to the services and might go below the thresholds set.

PR hypercerts-org#218 is going to address this problem and make the services as well
as some of the GraphQL testable.

This is in anticipation of the next commit which is going to introduce
the collections entity as a top-level entity.
Without this patch the user of our GraphQL endpoints needs to go via
hyperboards to access the collections inside. Another drawback is that
via this query they can only access the hypercert id, so they'll have to
fire a separate query to combine the data.

This patch adds collections as a top level entity and exposes full
hypercert objects as child entities. This also applies to hyperboards as
the standalone collections entity is being reused there too.
The problem right now is that the constants that are loaded from the
environment have an additional name if specified. This additional name
is very confusing if you're presented with the error message

Environment variable Alchemy API key is not set.

This makes you wonder if perhaps you have mistyped the variable name.
It's almost always better to just print the variable name as it is
expected in your .env file. One notable exception is perhaps our Web3Up
proof and secret.

That's why this patch changes the approach of assertExists() to only
deal with environment variables (it's not used in any other way
currently) and have the caller specify the variable name and an optional
hint to help the person stumbling over a missing env var error with
additional context.

The name of assertExists() was renamed to getRequiredEnvVar() to better
reflect what the function is doing. The filename was also renamed to
further support this.
The current test file was testing library code that is already
comprehensively tested. It was also making slow RPC requests and slowed
the test suite down substantially. It requires the Alchemy API key to be
set which is not something that we want, so this patch is doing away
with all superfluous tests and focuses on testing only the code that
we've added around the library call.

Also lowered the coverage thresholds since the EVM client getter is now
mocked and its internals are thus not covered by these tests any longer.
Without this patch the Safe signature verification code will get RPC
URLs for the specified chain id. This in turn will load the Alchemy API
key, which is not relevant for our tests.

This patch mocks all of this away, so that the API key doesn't need to
be present in the environment while running tests.

Also lowered the coverage threshold of functiosn to 52 as mocking
getRpcUrl() doesn't touch the internals of this function. This should be
thoroughly tested in a dedicated test file anyway.
@bitbeckers bitbeckers merged commit 1f43906 into hypercerts-org:develop Jan 28, 2025
1 check passed
@pheuberger pheuberger deleted the create-collections-entity-graphql branch January 28, 2025 12:29
@bitbeckers bitbeckers linked an issue Feb 3, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

[graphql] Add metrics to hyperboards
4 participants