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

Implement archiveEntity GQL mutation and BP hook #1518

Merged
merged 8 commits into from
Nov 29, 2022

Conversation

benwerner01
Copy link
Member

🌟 What is the purpose of this PR?

This PR introduces an archiveEntity GQL mutation and BP hook.

πŸ”— Related links

πŸ” What does this change?

See commits.

πŸ“œ Does this require a change to the docs?

No.

πŸ›‘ What tests cover this?

None.

❓ How to test this?

  1. Run the HASH App using yarn dev
  2. Log into the frontend and navigate to http://localhost:3000/entity-editor
  3. Use the "create entity" button to create an entity, and then use the "archive created entity button" to archive the created entity

πŸ“Ή Demo

Screen.Recording.2022-11-28.at.12.43.57.mov

@codecov
Copy link

codecov bot commented Nov 28, 2022

Codecov Report

Merging #1518 (4116541) into main (83667d3) will decrease coverage by 0.01%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##             main    #1518      +/-   ##
==========================================
- Coverage   55.81%   55.79%   -0.02%     
==========================================
  Files         218      218              
  Lines       14224    14229       +5     
  Branches      376      376              
==========================================
  Hits         7939     7939              
- Misses       6280     6285       +5     
  Partials        5        5              
Flag Coverage Ξ”
unit-tests 1.76% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Ξ”
packages/hash/api/src/graphql/resolvers/index.ts 0.00% <ΓΈ> (ΓΈ)
...i/src/graphql/resolvers/knowledge/entity/entity.ts 0.00% <0.00%> (ΓΈ)
...i/src/graphql/typeDefs/knowledge/entity.typedef.ts 0.00% <ΓΈ> (ΓΈ)

πŸ“£ We’re building smart automated test selection to slash your CI/CD build times. Learn more

@lgtm-com
Copy link

lgtm-com bot commented Nov 28, 2022

This pull request introduces 1 alert when merging a44b0a8 into 387317f - view on LGTM.com

new alerts:

  • 1 for Useless conditional

Heads-up: LGTM.com's PR analysis will be disabled on the 5th of December, and LGTM.com will be shut down ⏻ completely on the 16th of December 2022. Please enable GitHub code scanning, which uses the same CodeQL engine βš™οΈ that powers LGTM.com. For more information, please check out our post on the GitHub blog.

Copy link
Contributor

@Alfred-Mountfield Alfred-Mountfield left a comment

Choose a reason for hiding this comment

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

Looks good to me for the most part, few clarifying questions


await entityModel.archive(graphApi, { actorId: userModel.getEntityUuid() });

return true;
Copy link
Contributor

Choose a reason for hiding this comment

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

What does it mean to return a boolean here? I assume we're throwing an error on the failure case (as I don't see a return false) so would we perhaps want to return null or something if that's even possible?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes we are throwing an error. GraphQL does not have a void type so this seemed like the easiest thing to do. GraphQL also doesn't seem to support returning null as you suggest. It would be possible to introduce a scalar called Void if you feel strongly about not using Boolean.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh right it doesn't support null, remember talking about this a long time ago. Boolean seems fine for now


const { entityId } = data;

await archiveEntityFn({ variables: { entityId } });
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you not need to use the return value here?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, because I've made the return-type of the BP hook Promise<void>

Copy link
Contributor

Choose a reason for hiding this comment

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

We seem to throw errors when data is nullish in other hooks so I feel like we need to check it's true here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Why is data nullable in other hooks?

Copy link
Member Author

Choose a reason for hiding this comment

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

I feel like the error throwing when data is falsy is a consequence of an incorrect return-type, so not something that should influence the decision of which return-type to use here.

Copy link
Contributor

Choose a reason for hiding this comment

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

It doesn't seem to be our configuration, but actually hardcoded in the type from Apollo

image

Copy link
Member Author

Choose a reason for hiding this comment

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

I think data can be undefined in apollo, because they return errors rather than throwing them (see the error field in your screenshot). I now see that this is what we are doing for the BP hooks as well:
image

However, I still don't think returning data: undefined should be treated as an error state, instead if errors is a non-empty array it should indicate that an error has occurred in the archiveEntity hook.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've looked at the current graph service definition, and it seems we should be returning a boolean instead so have changed it to that in 6f3978a
image

@lgtm-com
Copy link

lgtm-com bot commented Nov 28, 2022

This pull request introduces 1 alert when merging 6f3978a into 69dc78c - view on LGTM.com

new alerts:

  • 1 for Useless conditional

Heads-up: LGTM.com's PR analysis will be disabled on the 5th of December, and LGTM.com will be shut down ⏻ completely on the 16th of December 2022. Please enable GitHub code scanning, which uses the same CodeQL engine βš™οΈ that powers LGTM.com. For more information, please check out our post on the GitHub blog.

@benwerner01 benwerner01 merged commit cac8e7c into main Nov 29, 2022
@benwerner01 benwerner01 deleted the bw/archive-entity-gql branch November 29, 2022 10:36
@vilkinsons vilkinsons added type/eng > frontend Owned by the @frontend team and removed area: frontend labels Jul 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/apps > hash* Affects HASH (a `hash-*` app) area/apps > hash-api Affects the HASH API (app) type/eng > frontend Owned by the @frontend team
Development

Successfully merging this pull request may close these issues.

None yet

3 participants