{"action":"created","issue":{"url":"https://api.github.com/repos/gatsbyjs/gatsby/issues/6112","repository_url":"https://api.github.com/repos/gatsbyjs/gatsby","labels_url":"https://api.github.com/repos/gatsbyjs/gatsby/issues/6112/labels{/name}","comments_url":"https://api.github.com/repos/gatsbyjs/gatsby/issues/6112/comments","events_url":"https://api.github.com/repos/gatsbyjs/gatsby/issues/6112/events","html_url":"https://github.com/gatsbyjs/gatsby/issues/6112","id":335069453,"node_id":"MDU6SXNzdWUzMzUwNjk0NTM=","number":6112,"title":"Document linking images to other nodes, `onCreateNode` in `gatsby-nodes.js`","user":{"login":"sw-yx","id":6764957,"node_id":"MDQ6VXNlcjY3NjQ5NTc=","avatar_url":"https://avatars1.githubusercontent.com/u/6764957?v=4","gravatar_id":"","url":"https://api.github.com/users/sw-yx","html_url":"https://github.com/sw-yx","followers_url":"https://api.github.com/users/sw-yx/followers","following_url":"https://api.github.com/users/sw-yx/following{/other_user}","gists_url":"https://api.github.com/users/sw-yx/gists{/gist_id}","starred_url":"https://api.github.com/users/sw-yx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sw-yx/subscriptions","organizations_url":"https://api.github.com/users/sw-yx/orgs","repos_url":"https://api.github.com/users/sw-yx/repos","events_url":"https://api.github.com/users/sw-yx/events{/privacy}","received_events_url":"https://api.github.com/users/sw-yx/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-06-23T05:06:05Z","updated_at":"2018-06-24T07:10:27Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"## Summary\r\n\r\nbecause gatsby processes images separately from the other sources that might depend on those images, it is a very common need to want to link them `onCreateNode`. however the documentation on this is basically in https://github.com/gatsbyjs/gatsby/issues/3608 (and other related issues like https://github.com/gatsbyjs/gatsby/issues/5196, all looking the same). in particular this seems to be the key part:\r\n\r\n```js\r\n\r\n      // Find ID of File node\r\n      const fileNode = getNodes().find(n => n.absolutePath === pathToFile);\r\n\r\n      if (fileNode != null) {\r\n        // Find ImageSharp node corresponding to the File node\r\n        const imageSharpNodeId = fileNode.children.find(n => n.endsWith('>> ImageSharp'));\r\n        const imageSharpNode = getNodes().find(n => n.id === imageSharpNodeId);\r\n\r\n        // Add ImageSharp node as child\r\n        createParentChildLink({ parent: node, child: imageSharpNode });\r\n      }\r\n```\r\n\r\nhowever the `endsWith('>> ImageSharp')` doesn't even seem to be relevant anymore (at least when i tried it) so this also doesn't work.\r\n\r\nwe should document common patterns like this, if not treat them as bugs since it is fairly nasty dx.\r\n\r\n## Relevant information\r\n\r\nthis is what i'm doing now:\r\n\r\n```js\r\n// add images https://github.com/gatsbyjs/gatsby/issues/2995\r\n    const fileNode = getNodes().find(n => \r\n      n.absolutePath &&  // many nodes dont have it\r\n      n.absolutePath.includes('generatedScreenshots') && // just the screenshots\r\n      n.name === stub // assumes screenshots have same name as stub\r\n    )\r\n\r\n    if (fileNode != null) {\r\n      // Find ImageSharp node corresponding to the File node\r\n      const imageSharpNodeId = fileNode.children[0];\r\n      if (imageSharpNodeId) {\r\n        const imageSharpNode = getNodes().find(n => n.id === imageSharpNodeId);\r\n        if (imageSharpNode) createNodeField({ node, name: `starterScreenshot`, value: imageSharpNode })\r\n      } else console.log('no imageSharpNodeId found for ' + stub, fileNode)\r\n    }\r\n```\r\n\r\nbut i only get the bare minimum data, not imageSharp data:\r\n\r\n![Uploading image.png…]()\r\n\r\n\r\n### Environment (if relevant)\r\n\r\n```\r\n\r\n  System:\r\n    OS: macOS Sierra 10.12.6\r\n    CPU: x64 Intel(R) Core(TM) i7-4650U CPU @ 1.70GHz\r\n    Shell: 5.2 - /bin/zsh\r\n  Binaries:\r\n    Node: 8.5.0 - ~/.nvm/versions/node/v8.5.0/bin/node\r\n    Yarn: 1.6.0 - ~/.nvm/versions/node/v8.5.0/bin/yarn\r\n    npm: 6.0.0 - ~/.nvm/versions/node/v8.5.0/bin/npm\r\n  Browsers:\r\n    Chrome: 67.0.3396.87\r\n    Firefox: 58.0.1\r\n    Safari: 11.0.1\r\n  npmPackages:\r\n    gatsby: next => 2.0.0-beta.9 \r\n    gatsby-image: next => 2.0.0-beta.2 \r\n    gatsby-plugin-canonical-urls: next => 2.0.0-beta.2 \r\n    gatsby-plugin-catch-links: next => 2.0.2-beta.2 \r\n    gatsby-plugin-create-client-paths: ^1.0.8 => 1.0.8 \r\n    gatsby-plugin-feed: next => 2.0.0-beta.2 \r\n    gatsby-plugin-fullstory: ^1.0.4-5 => 1.0.4-9 \r\n    gatsby-plugin-glamor: next => 2.0.0-beta.2 \r\n    gatsby-plugin-google-analytics: next => 2.0.0-beta.2 \r\n    gatsby-plugin-google-tagmanager: next => 2.0.0-beta.2 \r\n    gatsby-plugin-lodash: next => 3.0.1-beta.2 \r\n    gatsby-plugin-mailchimp: ^2.2.3 => 2.2.3 \r\n    gatsby-plugin-manifest: next => 2.0.2-beta.2 \r\n    gatsby-plugin-netlify: next => 2.0.0-beta.2 \r\n    gatsby-plugin-netlify-cache: ^0.1.0 => 0.1.0 \r\n    gatsby-plugin-nprogress: next => 2.0.0-beta.2 \r\n    gatsby-plugin-offline: next => 2.0.0-beta.2 \r\n    gatsby-plugin-react-helmet: next => 3.0.0-beta.2 \r\n    gatsby-plugin-sharp: next => 2.0.0-beta.2 \r\n    gatsby-plugin-sitemap: next => 2.0.0-beta.2 \r\n    gatsby-plugin-twitter: next => 2.0.0-beta.2 \r\n    gatsby-plugin-typography: next => 2.2.0-beta.2 \r\n    gatsby-remark-autolink-headers: next => 2.0.0-beta.3 \r\n    gatsby-remark-copy-linked-files: next => 2.0.0-beta.2 \r\n    gatsby-remark-images: next => 2.0.1-beta.3 \r\n    gatsby-remark-prismjs: next => 3.0.0-beta.2 \r\n    gatsby-remark-responsive-iframe: next => 2.0.0-beta.2 \r\n    gatsby-remark-smartypants: next => 2.0.0-beta.2 \r\n    gatsby-source-filesystem: next => 2.0.1-beta.3 \r\n    gatsby-source-npm-package-search: ^1.0.8 => 1.0.8 \r\n    gatsby-transformer-csv: next => 2.0.0-beta.2 \r\n    gatsby-transformer-documentationjs: next => 2.0.0-beta.2 \r\n    gatsby-transformer-remark: next => 2.1.1-beta.2 \r\n    gatsby-transformer-screenshot: next => 2.0.0-beta.2 \r\n    gatsby-transformer-sharp: next => 2.1.1-beta.2 \r\n    gatsby-transformer-yaml: next => 2.1.1-beta.2 \r\n  npmGlobalPackages:\r\n    gatsby-cli: 1.1.58\r\n\r\n```"},"comment":{"url":"https://api.github.com/repos/gatsbyjs/gatsby/issues/comments/399734860","html_url":"https://github.com/gatsbyjs/gatsby/issues/6112#issuecomment-399734860","issue_url":"https://api.github.com/repos/gatsbyjs/gatsby/issues/6112","id":399734860,"node_id":"MDEyOklzc3VlQ29tbWVudDM5OTczNDg2MA==","user":{"login":"sw-yx","id":6764957,"node_id":"MDQ6VXNlcjY3NjQ5NTc=","avatar_url":"https://avatars1.githubusercontent.com/u/6764957?v=4","gravatar_id":"","url":"https://api.github.com/users/sw-yx","html_url":"https://github.com/sw-yx","followers_url":"https://api.github.com/users/sw-yx/followers","following_url":"https://api.github.com/users/sw-yx/following{/other_user}","gists_url":"https://api.github.com/users/sw-yx/gists{/gist_id}","starred_url":"https://api.github.com/users/sw-yx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sw-yx/subscriptions","organizations_url":"https://api.github.com/users/sw-yx/orgs","repos_url":"https://api.github.com/users/sw-yx/repos","events_url":"https://api.github.com/users/sw-yx/events{/privacy}","received_events_url":"https://api.github.com/users/sw-yx/received_events","type":"User","site_admin":false},"created_at":"2018-06-24T07:10:27Z","updated_at":"2018-06-24T07:10:27Z","author_association":"CONTRIBUTOR","body":"my conclusion is it can't be done. if you are from the future and hoping to do what i did, dont try. just do a `File` query instead and manually link them later."}}
{"actor":{"display_login":"sw-yx"}}