-
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
gatsby-source-graphql plugin re-runs createPage when using fragments #20083
Comments
Looks like double call of gatsby/examples/using-gatsby-source-graphql/gatsby-node.js Lines 57 to 62 in 768df7d
As you see a new node is created while the query is running (for a remote file). And Unfortunately, this is the expected behavior for The current workaround is to create remote file nodes separately in the |
Hiya! This issue has gone quiet. Spooky quiet. 👻 We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here. Thanks for being a part of the Gatsby community! 💪💜 |
Hey again! It’s been 30 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it. Thanks again for being part of the Gatsby community! 💪💜 |
You should be able to use existing createLink option and use an Apollo Link that supports caching, ie https://github.com/prisma-labs/http-link-dataloader |
@vladar can you give more hints on how to integrate this into a source plugin? |
Here's a sample gatsby-node.jsconst { createHttpLink } = require("apollo-link-http");
const fetch = require("node-fetch");
const gql = require("graphql-tag");
const { createRemoteFileNode } = require(`gatsby-source-filesystem`);
const uri = process.env.GRAPHQL_ENDPOINT;
const headers = {};
exports.sourceNodes = async (
{ actions, getCache, store, reporter }
) => {
const { createNode } = actions;
const link = createHttpLink({
uri,
fetch,
headers
});
const query = gql`
query FetchImages($after: String) {
mediaItems(first: 100, after: $after) {
pageInfo {
hasNextPage
endCursor
}
nodes {
sourceUrl
}
}
}
`;
let hasNextPage;
let after;
do {
const { data } = await makePromise(
execute(link, { query, variables: { after } })
);
await Promise.all(
data.mediaItems.nodes.map(({ sourceUrl }) => {
if (!sourceUrl || sourceUrl === "false") return Promise.resolve();
return createRemoteFileNode({
url: sourceUrl,
parentNodeId: null,
store,
getCache,
createNode,
createNodeId: () => sourceUrl,
httpHeaders: headers,
reporter
});
})
);
hasNextPage = data.mediaItems.pageInfo.hasNextPage;
after = data.mediaItems.pageInfo.endCursor;
} while (hasNextPage);
};
exports.createResolvers = ({ createResolvers }) => {
createResolvers({
MediaItem: {
localFile: {
type: "File",
resolve: (source, args, context) => context.nodeModel.getNodeById({ id: source.sourceUrl, type: "File" })
}
}
})
} |
@sanderploegsma thanks a lot for the fast response, I tried your approach but am running into problems either if I create a resolver in the original wpgraphql type, I get
and otherwise if I use your code as is, it complains that I have created a sample project: https://github.com/rburgst/gatsby-rebuilding-problem/tree/experiments/sourceNodes, it would be super kind if you could help me fix it. |
if I clone your example project everything seems to work correctly. Judging by the error you posted it looks like you have multiple versions of the |
You are correct, i had 2 graphql versions in my dependencies. Sorry for not reading the error well enough. Thanks so much! It works now. I will update my test repo so people can find a working solution if they encounter the same issue. |
Description
If a page query contains a fragment, the graphql source plugin seemingly re-runs the whole create page query multiple times.
Steps to reproduce
This can be recreated from the graphql source example here:
https://github.com/gatsbyjs/gatsby/tree/master/examples/using-gatsby-source-graphql
console.log()
the blog title.gatsby develop
and see that it outputs the titles twicegatsby develop
and see that it outputs the titles once.Expected result
createPage should be called once per page.
Actual result
createPage is called twice per page.
Environment
System:
OS: macOS 10.15.2
CPU: (12) x64 Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 10.16.3 - /usr/local/bin/node
Yarn: 1.16.0 - /usr/local/bin/yarn
npm: 6.9.0 - /usr/local/bin/npm
Languages:
Python: 2.7.16 - /usr/bin/python
Browsers:
Chrome: 78.0.3904.108
Firefox: 71.0
Safari: 13.0.4
npmPackages:
gatsby: ^2.0.0 => 2.18.11
gatsby-image: ^2.0.34 => 2.2.36
gatsby-plugin-netlify: ^2.0.0 => 2.1.30
gatsby-plugin-sharp: ^2.0.30 => 2.3.7
gatsby-source-filesystem: ^2.0.27 => 2.1.42
gatsby-source-graphql: ^2.0.0 => 2.1.28
gatsby-transformer-sharp: ^2.1.17 => 2.3.9
npmGlobalPackages:
gatsby-cli: 2.8.8
The text was updated successfully, but these errors were encountered: