-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Log type conflics when inferring graphql types #3905
Conversation
Deploy preview for gatsbygram ready! Built with commit 97a9953 |
Will check those failing tests tomorrow |
Woah nice!! A couple of thoughts which you've probably thought of already but I'll throw out to document them:
|
Had that in my initial version, just removed it thinking it would be too spammy with array values (in long arrays scenario). If I would reduce arrays to single items of given type then it would be more readable but probably also somewhat confusing
I'd rather avoid adding special cases in core to show local markdown file even if it would be straight forward to do (getting parent File node and showing path to it). I would think that in general this would try finding nearest ancestor node (or self) that have I will experiment with some conventions tomorrow and hopefully plugin authors will voice their opinion on this topic. It doesn't need to be implemented in this PR - this can be done in follow up IMO. Another topic - what's Your opinion about adding links in console output - I could add paragraph about type conflicts here https://www.gatsbyjs.org/docs/querying-with-graphql/#where-does-gatsbys-graphql-schema-come-from and add link to it in warning message but then we'd need to be sure this link will always be correct. We do this in couple of places (f.e. debugging html builds or queries not run in non page-or-layout components), but I don't know if that's the right way to add more context to warnings/errors. |
I added the other links so I'm a big fan :-) Ideally we link to a single page and chose the title wisely so the link is stable. If it's a single page, we can easily add / tweak content over time. |
fddc563
to
302682d
Compare
Deploy preview for using-glamor failed. Built with commit f390267 https://app.netlify.com/sites/using-glamor/deploys/5a7d091e0b79b765d683cd48 |
4a77478
to
d36997c
Compare
Just note - I added data origin logging but it's bugged currently (it reports wrong sources). I will check if this is something I can fix with my current approach or will have to change it to something else. |
620721a
to
eab0355
Compare
I ended up rewriting It now will analyze values and report conflicts before doing any actual merging. It does have some performance hit (using freeCodeCamp guides website - it was consistently about +20% in 5 tests I run):
but it is offseted by fact that it now stores example value and extraction in not run 4 times for same nodes (for fields, for input fields, for sort field enums and for group enums). I will recheck that with example provided in #4055 later. Examples will fail to build because I added |
ee447d2
to
8045728
Compare
8045728
to
6580cfa
Compare
Deploy preview for using-drupal ready! Built with commit 97a9953 |
Rebased this PR so it's mergable again I've run gatsby build on master and this PR 5 times for gatsbyjs.org and it does decrease time spent on building schema (average times):
|
6580cfa
to
ec6e929
Compare
…or fields, for input fields, for sort field enums and for group enums) Signed-off-by: Michal Piechowiak <[email protected]>
… it to findRootNodeAncestor Signed-off-by: Michal Piechowiak <[email protected]>
Signed-off-by: Michal Piechowiak <[email protected]>
…t type conflicts when creating graphql schema Signed-off-by: Michal Piechowiak <[email protected]>
…h and detect type conflicts early (to not merge values if there is conflict) Signed-off-by: Michal Piechowiak <[email protected]>
ec6e929
to
17ae80a
Compare
Anyone care to review? |
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.
Looks good!
I didn't see any tests for the conflicts? Or perhaps I just missed them.
Also does the output look similar still to your original PR comment? I think that could be clearer still.
packages/gatsby/src/redux/actions.js
Outdated
@@ -505,6 +505,10 @@ const typeOwners = {} | |||
* @param {string} node.internal.contentDigest the digest for the content | |||
* of this node. Helps Gatsby avoid doing extra work on data that hasn't | |||
* changed. | |||
* @param {string} node.internal.nodeDescription An optional field. Human |
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.
Maybe just name the field description
? node
is already implied.
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.
Sure, will change that soon
return { type, nodes } | ||
} | ||
|
||
const getExampleValue = arg => { |
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.
Any reason this isn't named getExampleValues
?
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 can change that, but we get single value (object) from array of nodes, so I though single value would be more accurate.
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.
Yeah, I think of the object as a bag of values 🤷♂️
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.
Looks like this is all that's left for this to get in?
Yes, tests for this functionality is missing right now, will add them |
Output in PR description is what currently looks like - i feel this a little bit more readible in actual terminal: Just did testing with more spaced out information: might be worth adding some more colouring to seprate things, but I worry this would cause problems with readability in custom styled terminals people seems to like to use |
Signed-off-by: Michal Piechowiak <[email protected]>
Cool yeah — and generally people will only have one conflicting type so it should be less overwhelming for folks. We should double-check the official starters don't have any conflicting types before this gets merged too :-) |
Signed-off-by: Michal Piechowiak <[email protected]>
Signed-off-by: Michal Piechowiak <[email protected]>
Signed-off-by: Michal Piechowiak <[email protected]>
I will run this through official starters, but what about gatsbyjs.org: 😄 I was just thinking now how to handle possible conflicts in |
Signed-off-by: Michal Piechowiak <[email protected]>
Updating starters right now and as I suspected - this might be problematic with
I think silencing |
Signed-off-by: Michal Piechowiak <[email protected]>
…rently examples are not stored because type is not set - this is just future proofing Signed-off-by: Michal Piechowiak <[email protected]>
Signed-off-by: Michal Piechowiak <[email protected]>
Sweeet! Let's publish this! |
We should also merge this ( |
man thank heavens for this comment @pieh that was driving me crazy til I found this! |
* add nodeDescription field to node internal object Signed-off-by: Michal Piechowiak <[email protected]> * store extracted example value to not run it 4 times for same nodes (for fields, for input fields, for sort field enums and for group enums) Signed-off-by: Michal Piechowiak <[email protected]> * introduce TypeConflictReporter utility class that will store and print type conflicts when creating graphql schema Signed-off-by: Michal Piechowiak <[email protected]> * enhance findRootNode function to accept predicate function and rename it to findRootNodeAncestor Signed-off-by: Michal Piechowiak <[email protected]> * rewrite extractFieldExamples to be able to keep track of selector path and detect type conflicts early (to not merge values if there is conflict) Signed-off-by: Michal Piechowiak <[email protected]> * use type conflict reporter when extracting example value Signed-off-by: Michal Piechowiak <[email protected]> * add nested arrays in array of objects to tests Signed-off-by: Michal Piechowiak <[email protected]> * rename nodeDescription to description Signed-off-by: Michal Piechowiak <[email protected]> * add tests for conflict reporting Signed-off-by: Michal Piechowiak <[email protected]> * space out conflict info to be more readable Signed-off-by: Michal Piechowiak <[email protected]> * add description for possible conflicts in page context Signed-off-by: Michal Piechowiak <[email protected]> * fix schema type conflict in gatsbyjs.org Signed-off-by: Michal Piechowiak <[email protected]> * Silence SitePlugin type conflicts Signed-off-by: Michal Piechowiak <[email protected]> * just in case clear type examples store in data-tree-utils tests - currently examples are not stored because type is not set - this is just future proofing Signed-off-by: Michal Piechowiak <[email protected]> * rename getExampleValue to getExampleValues Signed-off-by: Michal Piechowiak <[email protected]>
This adds logging discarded/omitted fields that have conflicting types.
Example of output:
Above was generated using this demo - https://github.com/pieh/gatsby-conflicting-types-demo with prepared conflicts in frontmatter:
page 1 (hello-world - https://github.com/pieh/gatsby-conflicting-types-demo/blob/master/src/pages/hello-world/index.md ):
page 2 (hi-folks - https://github.com/pieh/gatsby-conflicting-types-demo/blob/master/src/pages/hi-folks/index.md ):
page 3 (my second post - https://github.com/pieh/gatsby-conflicting-types-demo/blob/master/src/pages/my-second-post/index.md ):
Closes #3856
Btw: funny side gain for finding conflicts in
gatsby-starter-blog
in passed context ( if anyone would ever want to query that :) ). Would need to usenull
instead of false here - https://github.com/gatsbyjs/gatsby-starter-blog/blob/master/gatsby-node.js#L39-L40