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 method that verificates if an instance was created, in order t… #10409

Merged
merged 6 commits into from
Oct 12, 2022

Conversation

miranciandt
Copy link
Contributor

@miranciandt miranciandt commented Oct 3, 2022

Hello. I've opened this pull request due to an issue we faced on our project while using amplify, where the graphql class could not read the getCancellableToken variable

10⁄03⁄22_1

We found out that this was happening because an instance was not being created before calling the graphql method, once the verification if the instance exists was happening after the assignment of the cancellableToken variable.

Description of changes

To work around this, I put the if statement that verificates if an instance was created into a method, in order to make it reusable. In this case, it was necessary to use it before the assignment of the cancellableToken variable.

Description of how you validated changes

[VScode debugger]
Code block behavior

Screenshot from 2022-10-03 14-03-35

  • Before the implementation:
without_isInstanceCreated.mp4
  • After the implementation:
with_isInstanceCreated.mp4

Checklist

  • [✓] PR description included
  • [✓] yarn test passes
  • [✓] Tests are changed or added
  • [ x ] Relevant documentation is changed or added (and PR referenced)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

…o make it reusable. In this case, it was necessary to use it before the assignment of the cancellableToken variable
@miranciandt miranciandt requested a review from a team as a code owner October 3, 2022 15:25
@miranciandt miranciandt closed this Oct 3, 2022
@miranciandt miranciandt reopened this Oct 3, 2022
@miranciandt miranciandt marked this pull request as draft October 3, 2022 16:27
@codecov-commenter
Copy link

codecov-commenter commented Oct 3, 2022

Codecov Report

Merging #10409 (5e54ad1) into main (b6f6c81) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main   #10409   +/-   ##
=======================================
  Coverage   83.78%   83.79%           
=======================================
  Files         182      182           
  Lines       16396    16399    +3     
  Branches     3441     3441           
=======================================
+ Hits        13738    13742    +4     
+ Misses       2580     2579    -1     
  Partials       78       78           
Impacted Files Coverage Δ
packages/api-graphql/src/GraphQLAPI.ts 88.48% <100.00%> (+0.71%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@siegerts siegerts added first-time-contributor The contribution is the first for this user in the repo external-contributor labels Oct 3, 2022
@miranciandt miranciandt marked this pull request as ready for review October 3, 2022 18:32
Copy link
Member

@dpilch dpilch left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution! Overall LGTM, have a couple comments.


expect(spyon).toBeCalledWith(url, init);
});

test('call isInstanceCreated', () => {
Copy link
Member

Choose a reason for hiding this comment

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

Could you create a test to assert that createInstance is no called when an instance already exists?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@@ -359,6 +357,12 @@ export class GraphQLAPIClass {
return response;
}

async isInstanceCreated() {
Copy link
Member

Choose a reason for hiding this comment

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

This reads more like it should return a boolean. Maybe something like createInstanceIfNotCreated would be a better fit 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.

Done! I agree with the name, thanks for the suggestion 🙂

@miranciandt miranciandt requested review from a team as code owners October 5, 2022 19:55
@miranciandt miranciandt requested a review from dpilch October 6, 2022 15:37
@dpilch
Copy link
Member

dpilch commented Oct 6, 2022

It looks like you accidentally included some format changes to the CHANGELOGs. Could remove these changes? Then it should be good to merge.

@miranciandt
Copy link
Contributor Author

@dpilch fixed

@stocaaro stocaaro merged commit 36de901 into aws-amplify:main Oct 12, 2022
@stocaaro
Copy link
Member

Thank you for this contribution! We've merged your change to main and expect it to go out in the release tomorrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external-contributor first-time-contributor The contribution is the first for this user in the repo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants