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

feat(graphiql): Prettify also formats query variables #991

Merged
merged 3 commits into from
Nov 7, 2019
Merged

feat(graphiql): Prettify also formats query variables #991

merged 3 commits into from
Nov 7, 2019

Conversation

zouxuoz
Copy link
Contributor

@zouxuoz zouxuoz commented Nov 6, 2019

Closes #990

and rid of unnecessary editors updates when content not changed during prettification

@codecov
Copy link

codecov bot commented Nov 6, 2019

Codecov Report

Merging #991 into master will decrease coverage by 0.06%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #991      +/-   ##
==========================================
- Coverage   43.14%   43.08%   -0.07%     
==========================================
  Files          64       64              
  Lines        2934     2943       +9     
  Branches      635      637       +2     
==========================================
+ Hits         1266     1268       +2     
- Misses       1400     1406       +6     
- Partials      268      269       +1
Impacted Files Coverage Δ
packages/graphiql/src/components/GraphiQL.js 30.49% <0%> (-0.78%) ⬇️
packages/graphiql/src/utility/find.js 100% <0%> (+66.66%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f088eba...1f120a5. Read the comment docs.

@zouxuoz
Copy link
Contributor Author

zouxuoz commented Nov 6, 2019

@benjie should I add some tests to increase coverage?) or I could just remove the code part which rid of unnecessary editors updates

Copy link
Member

@benjie benjie left a comment

Choose a reason for hiding this comment

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

Thanks @zouxuoz! Adding tests would be preferably; we have the beginnings of Cypress tests but I'm not sure if they're hooked up to code coverage or not (@acao?). Adding a test like those here: https://github.com/graphql/graphiql/blob/master/packages/graphiql/cypress/integration/init.spec.js would be great, testing the following circumstances:

  1. Regular prettification: enter ugly query and variables, click button, and check they are prettier
  2. Noop prettification: enter prettified query and variables, click button, and check that everything's unchanged (and no errors)
  3. No crash on bad query: enter broken query and ugly variables, click button, query should remain unchanged but variables should be prettier
  4. No crash on bad variables: enter ugly query and broken variables, click button, query should prettify but variables should remain unchanged.

Thanks so much 🙌

Copy link
Member

@benjie benjie left a comment

Choose a reason for hiding this comment

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

Seems CI failed due to non-determinism in our existing tests - not your fault. This code looks great, simple, clean, does the job and well tested 👍

Please fix the query strings and then it's good to merge 👍


describe('GraphiQL Prettify', function() {
it('Regular prettification', function() {
cy.visit(`/?query=${uglyQuery}&variables=${uglyVaribles}`);
Copy link
Member

Choose a reason for hiding this comment

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

Please escape the URLs; it doesn't seem to matter for these tests but it'll help future tests get it right 👍

Suggested change
cy.visit(`/?query=${uglyQuery}&variables=${uglyVaribles}`);
cy.visit(`/?query=${encodeURIComponent(uglyQuery)}&variables=${encodeURIComponent(uglyVaribles)}`);

cy.expect(w.g.getVariableEditor().getValue()).to.equal(brokenVaribles);
})
})
})
Copy link
Member

Choose a reason for hiding this comment

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

Excellent job of translating my list into tests! 🙌

@zouxuoz
Copy link
Contributor Author

zouxuoz commented Nov 7, 2019

@benjie Updated 🥳

Copy link
Member

@benjie benjie left a comment

Choose a reason for hiding this comment

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

Works beautifully. I'm going to ignore the codecov issues because I think we haven't got around to having Cypress contribute to that yet, and I'm satisfied the tests are fine.

@benjie benjie changed the title Prettify query variables feat(graphiql): Prettify also formats query variables Nov 7, 2019
@benjie benjie merged commit b7d0bfd into graphql:master Nov 7, 2019
@benjie
Copy link
Member

benjie commented Nov 7, 2019

Merged! Thanks 🎉

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.

Unable to prettify query variables input
2 participants