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(gatsby): track connections by default in runQuery and getAllNodes #29392

Merged
merged 54 commits into from
Feb 9, 2021

Conversation

vladar
Copy link
Contributor

@vladar vladar commented Feb 8, 2021

Description

Add connection tracking by default for runQuery and getAllNodes. Before this PR whenever you use runQuery or getAllNodes we track data relations per node not connection (unless you explicitly record connection relation).

As a result when a new node is added - we don't re-run all queries that can be potentially affected which leads to stale pages in builds.

Both methods have a second argument with pageDependencies. But people tend to omit it and rely on defaults.

New default is opt-in but people can still opt-out manually like this:

context.nodeModel.getAllNodes({ type: `Bar` }, { track: false })

or (for runQuery):

context.nodeModel.runQuery({ type: `Bar`, query: {}}, { track: false })

Documentation

https://www.gatsbyjs.com/docs/page-node-dependencies/

Related Issues

Fixes #27940

New version of graphql-compose adds type composers added via `createTemp` to schemaComposer. So before the upgrade `schemaComposer.has(typeName)` always returned false for temp types, now it returns true (as the temp composer is already added).
In the new version of graphql-compose the list of actual final types is stored in SchemaComposer itself, not TypeMapper. Also the same composer may have multiple keys
graphql-compose now adds temporary types to schemaComposer which is unfortunate. The suggested workaround is not to pass schemaComposer to createTemp (so use new schemaComposer under the hood).

That's what we do here but still use the original composer to resolve fields and types.
Those thunks cause stack overflow in graphql-compose. Indicates a bug in graphql-compose that warrants additional investigation.
graphql-compose introduced another behavior change for input type generation and unions. Previously it was ignoring fields of union types, now it throws.

Introduced here: graphql-compose/graphql-compose@b6363be
Another behavior change is that inputTypeComposer.getFields() now returns a map of fields where types are composers while our current code expects types to be types of graphql-js
…type composer

`typeComposer.getInterfaces()` now returns a list of interface composers not `GraphQLInterface` instances.

Also schemaComposer has multiple entries of the same type with different keys now.
`getType` method creates AST node under the hood that produces a duplicate type in the schema 🤷
@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Feb 8, 2021
@vladar vladar added topic: GraphQL Related to Gatsby's GraphQL layer and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Feb 8, 2021
Base automatically changed from v3/bump-graphql to master February 9, 2021 10:08
# Conflicts:
#	packages/gatsby/src/schema/__tests__/rebuild-sitepage-type.js
@vladar vladar marked this pull request as ready for review February 9, 2021 13:22
Copy link
Contributor

@pieh pieh left a comment

Choose a reason for hiding this comment

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

Yes, please!

@vladar vladar merged commit 5cbc085 into master Feb 9, 2021
@vladar vladar deleted the v3/run-query-auto-tracking branch February 9, 2021 16:47
pragmaticpat pushed a commit to pragmaticpat/gatsby that referenced this pull request Apr 28, 2022
gatsbyjs#29392)

* feat(gatsby): track runQuery connections by default

* track getAllNodes connections by default too

* update tests

* getAllNodes: track Node connection

* Allow to opt-out of dependency tracking
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: GraphQL Related to Gatsby's GraphQL layer
2 participants