-
-
Notifications
You must be signed in to change notification settings - Fork 533
Make urlCache as a part of load context (#707) #708
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
Conversation
/** Load a schema from local path or remote URL */ | ||
export default async function load( | ||
schema: URL | PartialSchema, | ||
options: LoadOptions | ||
): Promise<{ [url: string]: PartialSchema }> { | ||
const urlCache = options.urlCache || new Set<string>(); |
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.
How can we ensure that the cache object being passed in is of type Set
when the user is consuming the library with vanilla JS? They will have types provided, but it will not throw an error if they pass a different data structure.
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.
Thanks for asking. As I see this function is not a part of the library public api. And the function uses the cache object for recursive calls optimization. Also as you may see the function does not check types of the other fields of LoadOptions.
Codecov Report
@@ Coverage Diff @@
## main #708 +/- ##
==========================================
- Coverage 96.34% 94.15% -2.19%
==========================================
Files 13 13
Lines 547 565 +18
Branches 194 198 +4
==========================================
+ Hits 527 532 +5
- Misses 19 32 +13
Partials 1 1
Continue to review full report at Codecov.
|
Hey @drwpow I've made two tests runs on my local machine: one on the main branch and one on the pr/pass-cache-in-context. And the tests run time difference is about 100ms. So I'm not sure how may I optimize the pr changes to make the tests pass. If you have any ideas about this issue I would like to hear about it. Run tests on the main branch
Run tests on the pr/pass-cache-in-context branch
|
The lack of this fix really crippled my attempt to use the node API, since the cache lives forever - and does not actually add the cached schema to the second and later call, i.e.
In the above code in a second or later function invocation, urlCache will have the schema cached - but |
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.
Awesome fix! Thank you.
@all-contributors please add @mbelsky for code, bug |
I've put up a pull request to add @mbelsky! 🎉 |
Released in |
@drwpow thanks so much, really appreciate this fix :) |
Closes #707