-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Check for gql documents before running codegen #4728
Check for gql documents before running codegen #4728
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Requesting clarification and minor changes, comments in the files
@dac09 Thanks for your review. If I understood you correctly the biggest concern was that we might be catching too many errors when calling |
Yes they do for sure. I think its worth the compromise, I'm sure you would've done it another way if possible!
Maybe switch this to use inline snapshots? May not address the brittle problem, but will be much easier to maintain! Something like:
Watcha think? |
Another thing to check based on our conversation yesterday:
|
#want this is v1 so so bad 🥺🙏 |
I'll do my best |
Thanks @Tobbe I know you are and you will. Excited to have this far along!! |
1586f6b
to
c572e87
Compare
✅ Deploy Preview for redwoodjs-docs ready! 🔨 Explore the source changes: 793dd10 🔍 Inspect the deploy log: https://app.netlify.com/sites/redwoodjs-docs/deploys/6238f40eb47b6400096c1109 😎 Browse the preview: https://deploy-preview-4728--redwoodjs-docs.netlify.app |
This would be inside |
@dac09 Ready for another review
|
await generateGraphQLSchema() | ||
|
||
const webPaths = await generateTypeDefGraphQLWeb() | ||
const gqlTypesWebOutput = fs.readFileSync(webPaths[0], 'utf-8') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor suggestion. what do you think of mocking fs.writeFileSync here instead of using the index here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like this idea. Saves on disk I/O for the test case which is always a good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome! Thank you @Tobbe for bearing with me.
Looks like it should be possible to catch the "unknown type" error too, which is awesome. And no problem doing this in another PR
Left a few small comments that I would appreciate if you addressed
} | ||
}) | ||
|
||
test("Doesn't swallow legit errors - missingType", async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think we could:
a) Move this into a separate describe block
b) Before each, delete all generated .d.ts files, to make sure the old ts files in the fixture aren't picked up
c) Make sure the generate .d.ts isn't commited in the missingType fixture
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a) done
b) I've (manually) deleted all .d.ts files. No "old" files exist
c) No files are generated as part of the tests, because the generation bails on the (expected) errors. If, for some reason, files starts being generated hopefully that's a red flag for the developer so he/she doesn't just blindly commit them...
…postprocessing-nested-api-functions * 'main' of github.com:redwoodjs/redwood: Stying updates on docs site fix(deps): update typescript-eslint monorepo to v5.16.0 (redwoodjs#4862) fix(deps): update dependency cross-undici-fetch to v0.1.27 (redwoodjs#4858) fix(deps): update dependency @graphql-yoga/common to v0.1.0-canary-bfd2627.0 (redwoodjs#4857) chore(deps): update dependency zx to v6.0.7 (redwoodjs#4861) (docs) add Flightcontrol.dev Deploy (redwoodjs#4826) Handle case when requestContext is undefined getting protocol (redwoodjs#4864) Check for gql documents before running codegen (redwoodjs#4728) change flightcontrol setup to use yarn v3 and change cookie config (redwoodjs#4843) Forward -> Foreward Forward -> Foreward Typo Reorgnize tutorial into chapters (redwoodjs#4855) Fix linting warnings on new gql function (redwoodjs#4859) Use GraphQL Yoga (redwoodjs#4712) Fix url for tutorial path (redwoodjs#4852) chore(deps): update actions/cache action to v3 (redwoodjs#4847) Update link to tutorial deployment try learn's algolia config (redwoodjs#4851)
Fixes #4393
Recap
This is the error we're printing
The "Unable to find..." error message comes from here: https://github.com/ardatan/graphql-tools/blob/2207fbcdacf708ee9836ee72d0c0f92dba0d0942/packages/load/src/load-typedefs.ts#L120
The "Error: Could not generate..." message is our own.
Fix
This PR uses the
loadDocuments()
function from@graphql-tools
to first try and load all gql documents. If no documents are found we don't run the codegen, and thus don't get the error messages shown above.In a recent meeting with The Guild there was some talk about performance issues. Especially when reading from disk as we're doing here. So I did some rudimentary timing checks on this. From what I can tell this extra check adds less than 0.1s to the total runtime for
yarn rw g types
.This is an alternative fix to #4491. That PR didn't do anything about the running of the codegen, it only changed the "Error: ..." message.
Before
After