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] Initial attempt at fixing validator for venia-ui #2095

Merged
merged 11 commits into from
Jan 30, 2020

Conversation

sirugh
Copy link
Contributor

@sirugh sirugh commented Jan 10, 2020

Description

yarn run validate-queries was incomplete. It only validated venia-concept which no longer has any any graphql. That's not to say it won't always, but we should at least have had the validator check venia-ui.

Note: I added the validator to pre-push but I also changed the errors to warnings so as to not kill the push. We can discuss in this PR.

Related Issue

Closes PWA-251

Acceptance

Verification Stakeholders

Ya'll.

Specification

Verification Steps

  1. Run yarn run validate-queries. Result should display.

Screenshots / Screen Captures (if appropriate)

Image from Gyazo

Checklist

  • I have updated the documentation accordingly, if necessary.
  • I have added tests to cover my changes, if necessary.

@PWAStudioBot
Copy link
Contributor

PWAStudioBot commented Jan 10, 2020

Messages
📖

Access a deployed version of this PR here. Make sure to wait for the "pwa-pull-request-deploy" job to complete.

📖 DangerCI Failures related to missing labels/description/linked issues/etc will persist until the next push or next nightly build run (assuming they are fixed).
📖

Associated JIRA tickets: PWA-251.

Generated by 🚫 dangerJS against 6997ae8

Signed-off-by: Stephen Rugh <rugh@adobe.com>
Signed-off-by: Stephen Rugh <rugh@adobe.com>
Signed-off-by: Stephen Rugh <rugh@adobe.com>
@sirugh sirugh added the version: Patch This changeset includes backwards compatible bug fixes. label Jan 24, 2020
package.json Outdated
@@ -90,7 +90,7 @@
},
"husky": {
"hooks": {
"pre-push": "yarn run prettier:check && yarn run lint"
"pre-push": "yarn run prettier:check && yarn run lint && yarn run validate-queries"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is debatable. Do we want to run this on push? I think so.

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean, we don't currently. I'm okay with adding it since I always push with --no-verify anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let's ask the team

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dpatil-magento can we add this script to the CI checks?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

https://jira.corp.magento.com/browse/PWA-341 was created -- team says NO to prepush :D

@m2-community-project m2-community-project bot moved this from Ready for Review to Review in Progress in Pull Request Progress Jan 24, 2020
@@ -67,7 +67,7 @@ async function validateQueries(context, argv) {

// Validate our queries against that schema.
context.spinner.start('Finding queries in files...');
const validator = getValidator({ clients, project });
const validator = getValidator({ clients, project, schemaPath });
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now the validator will run the schema stored in the path rather than doing a "magical" search for the file within the directory the script is running. Basically we can run this from venia-concept but still check files in the sibling package, venia-ui.

}));

const ruleDefinition = ['error', ...clientRules];
const ruleDefinition = ['warn', ...clientRules];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is debatable. I know some folks think warnings are code smells. If we want to leave this as error we should then fix all the issues in the current graphql files (see the screenshot in the PR).

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, in this repo, we do prefer errors over warnings. That said, if you'd like to create an issue to fix all the warnings (and then flip it back from warn to error), that would be fine.

Signed-off-by: Stephen Rugh <rugh@adobe.com>
@@ -8,7 +8,7 @@
},
"validate-magento-pwa-queries": {
"clients": ["apollo", "literal"],
"filesGlob": "src/**/*.{js,graphql,gql}"
"filesGlob": "../{venia-ui,venia-concept}/{lib,src}/**/**/*.{js,graphql,gql}"
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'm bad with patterns...do I need the extra /**?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think you do.

@sirugh sirugh marked this pull request as ready for review January 24, 2020 22:59
@sirugh
Copy link
Contributor Author

sirugh commented Jan 24, 2020

I will fix tests once we land on a consensus for the debatable bits.

@sirugh sirugh changed the title Initial attempt at fixing validator for venia-ui [chore] Initial attempt at fixing validator for venia-ui Jan 28, 2020
jimbo
jimbo previously approved these changes Jan 29, 2020
package.json Outdated
@@ -90,7 +90,7 @@
},
"husky": {
"hooks": {
"pre-push": "yarn run prettier:check && yarn run lint"
"pre-push": "yarn run prettier:check && yarn run lint && yarn run validate-queries"
Copy link
Contributor

Choose a reason for hiding this comment

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

I mean, we don't currently. I'm okay with adding it since I always push with --no-verify anyway.

@@ -8,7 +8,7 @@
},
"validate-magento-pwa-queries": {
"clients": ["apollo", "literal"],
"filesGlob": "src/**/*.{js,graphql,gql}"
"filesGlob": "../{venia-ui,venia-concept}/{lib,src}/**/**/*.{js,graphql,gql}"
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think you do.

@m2-community-project m2-community-project bot moved this from Review in Progress to Reviewer Approved in Pull Request Progress Jan 29, 2020
Signed-off-by: Stephen Rugh <rugh@adobe.com>
Signed-off-by: Stephen Rugh <rugh@adobe.com>
jimbo
jimbo previously approved these changes Jan 29, 2020
Copy link
Contributor

@jimbo jimbo left a comment

Choose a reason for hiding this comment

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

Fine by me. Curious to see QA's take.

}));

const ruleDefinition = ['error', ...clientRules];
const ruleDefinition = ['warn', ...clientRules];
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, in this repo, we do prefer errors over warnings. That said, if you'd like to create an issue to fix all the warnings (and then flip it back from warn to error), that would be fine.

Signed-off-by: Stephen Rugh <rugh@adobe.com>
...clients.map(clientName => ({
env: clientName,
schemaJsonFilepath: schemaPath,
requiredFields: ['id']
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The Required Fields rule validates that any specified required field is part of the query, but only if that field is available in schema. This is useful to ensure that query results are cached properly in the client.

https://github.com/apollographql/eslint-plugin-graphql#required-fields-validation-rule

Copy link
Contributor

@jimbo jimbo left a comment

Choose a reason for hiding this comment

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

@dpatil-magento Theoretically, all of these id additions to the queries should make them hit the cache better. When you test this branch, let me know if you notice any perceptible difference in query performance.

@dpatil-magento
Copy link
Contributor

@jimbo Don't see any performance degradation on this PR, so merging this one.

@dpatil-magento dpatil-magento merged commit f9c4b9a into develop Jan 30, 2020
@m2-community-project m2-community-project bot moved this from Reviewer Approved to Done in Pull Request Progress Jan 30, 2020
@dpatil-magento dpatil-magento deleted the rugh/fix-gql-validator branch January 30, 2020 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

4 participants