{"action":"created","comment":{"url":"https://api.github.com/repos/gatsbyjs/gatsby/pulls/comments/224757921","pull_request_review_id":164207125,"id":224757921,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIyNDc1NzkyMQ==","diff_hunk":"@@ -256,21 +257,23 @@ function inferFromFieldName(value, selector, types): GraphQLFieldConfig<*, *> {\n     let type\n     // If there's more than one type, we'll create a union type.\n     if (fields.length > 1) {\n-      type = new GraphQLUnionType({\n-        name: createTypeName(\n-          `Union_${key}_${fields\n+      type = unionTypes.find(type =>","path":"packages/gatsby/src/schema/infer-graphql-type.js","position":null,"original_position":15,"commit_id":"f54e0562e56ed2684fae93a6ab6ac901a0298e9d","original_commit_id":"0fede76e808d3df83f915a2dd976f637d899f014","user":{"login":"haroldangenent","id":1481468,"node_id":"MDQ6VXNlcjE0ODE0Njg=","avatar_url":"https://avatars0.githubusercontent.com/u/1481468?v=4","gravatar_id":"","url":"https://api.github.com/users/haroldangenent","html_url":"https://github.com/haroldangenent","followers_url":"https://api.github.com/users/haroldangenent/followers","following_url":"https://api.github.com/users/haroldangenent/following{/other_user}","gists_url":"https://api.github.com/users/haroldangenent/gists{/gist_id}","starred_url":"https://api.github.com/users/haroldangenent/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/haroldangenent/subscriptions","organizations_url":"https://api.github.com/users/haroldangenent/orgs","repos_url":"https://api.github.com/users/haroldangenent/repos","events_url":"https://api.github.com/users/haroldangenent/events{/privacy}","received_events_url":"https://api.github.com/users/haroldangenent/received_events","type":"User","site_admin":false},"body":"I've made `unionTypes` an object, so union type instances can be shared on a per-key basis. The value still needs to be an array though (and we still need to use `.find` on it), because of this use-case:\r\n\r\n- A node type contains a union type on the field with the key `content`;\r\n- Another node type also contains a union type on the `content` field, but it contains different node types for the children.\r\n\r\nIn this case, we do _not_ want to share the union type. We want to verify that it actually contains the same node types.\r\n\r\nIn case you hadn't already noticed, I've changed the name of the union type to exclude all fields names. This way the union type name doesn't change when you the data structure for the children change (in case of WordPress: adding or removing an ACF layout).","created_at":"2018-10-12T11:48:08Z","updated_at":"2018-10-12T11:48:09Z","html_url":"https://github.com/gatsbyjs/gatsby/pull/9052#discussion_r224757921","pull_request_url":"https://api.github.com/repos/gatsbyjs/gatsby/pulls/9052","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/gatsbyjs/gatsby/pulls/comments/224757921"},"html":{"href":"https://github.com/gatsbyjs/gatsby/pull/9052#discussion_r224757921"},"pull_request":{"href":"https://api.github.com/repos/gatsbyjs/gatsby/pulls/9052"}},"in_reply_to_id":224748142},"pull_request":{"url":"https://api.github.com/repos/gatsbyjs/gatsby/pulls/9052","id":222420024,"node_id":"MDExOlB1bGxSZXF1ZXN0MjIyNDIwMDI0","html_url":"https://github.com/gatsbyjs/gatsby/pull/9052","diff_url":"https://github.com/gatsbyjs/gatsby/pull/9052.diff","patch_url":"https://github.com/gatsbyjs/gatsby/pull/9052.patch","issue_url":"https://api.github.com/repos/gatsbyjs/gatsby/issues/9052","number":9052,"state":"open","locked":false,"title":"Share union type instances","user":{"login":"haroldangenent","id":1481468,"node_id":"MDQ6VXNlcjE0ODE0Njg=","avatar_url":"https://avatars0.githubusercontent.com/u/1481468?v=4","gravatar_id":"","url":"https://api.github.com/users/haroldangenent","html_url":"https://github.com/haroldangenent","followers_url":"https://api.github.com/users/haroldangenent/followers","following_url":"https://api.github.com/users/haroldangenent/following{/other_user}","gists_url":"https://api.github.com/users/haroldangenent/gists{/gist_id}","starred_url":"https://api.github.com/users/haroldangenent/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/haroldangenent/subscriptions","organizations_url":"https://api.github.com/users/haroldangenent/orgs","repos_url":"https://api.github.com/users/haroldangenent/repos","events_url":"https://api.github.com/users/haroldangenent/events{/privacy}","received_events_url":"https://api.github.com/users/haroldangenent/received_events","type":"User","site_admin":false},"body":"Hello, Gatsby team 👋\r\n\r\nI hope to get some feedback on this PR. Let's dive in. Currently, [union types are named as follows](https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/src/schema/infer-graphql-type.js#L260-L265):\r\n\r\n1. Using the names of all the fields they contain;\r\n2. Incremented automatically when the same key occurs (`createTypeName`).\r\n\r\nThis causes union types to not be very reliable for usage in GraphQL queries (and not pretty, such as `unionContentPostNodeWordPressAcfImageWordPressAcfText_2` for a WordPress flexible content field).\r\n\r\nThis issue is mentioned in https://github.com/gatsbyjs/gatsby/pull/4074#issuecomment-366299727 and is the root of the cause of this problem: https://github.com/gatsbyjs/gatsby/issues/8615. This PR takes a first shot at naming union types more consistently.\r\n\r\n- **Naïvety**: Might this approach be overlooking some use-case in which you would _not_ want to share union type instances when the same child-node types are used? I'm not too familiar with the use-cases for all source plugins.\r\n- **Shared across all keys**: In this PR, union type instances are shared across all fields that contain the same child-node types, disregarding the key of the field. We could also choose to only share these instances for the exact same field key, to name union types more consistently for some specific use-cases. Any ideas on this?\r\n- **`createTypeName` and updated schema**: Because `createTypeName` is used (that stores all seen names in memory), the field name still gets incremented. This ensures a unique union type, when the same key is used for different child-node types. However, because [schema is updated](https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/src/bootstrap/index.js#L377) during bootstrap (for the `SitePage` node), all fields using `createTypeName` end on `_2`. While this never changes, this makes it _seem_ less reliable for developers trying to use the field. Maybe this is out of scope, but would there be a way to fix this issue? If you have any pointers on where to start, that would be great.\r\n- **Test**: I could also use some pointers on how to write a test for this use-case. Looking at [the current tests](https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/src/schema/__tests__/infer-graphql-type-test.js), I'm not sure on how to check the type of a union type field or even query several node types (only `listNode` is queried).\r\n\r\nThanks!","created_at":"2018-10-12T10:23:18Z","updated_at":"2018-10-12T11:48:09Z","closed_at":null,"merged_at":null,"merge_commit_sha":"50dbecbb5361abc07371ce23a6e46b46f1b46ccf","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/gatsbyjs/gatsby/pulls/9052/commits","review_comments_url":"https://api.github.com/repos/gatsbyjs/gatsby/pulls/9052/comments","review_comment_url":"https://api.github.com/repos/gatsbyjs/gatsby/pulls/comments{/number}","comments_url":"https://api.github.com/repos/gatsbyjs/gatsby/issues/9052/comments","statuses_url":"https://api.github.com/repos/gatsbyjs/gatsby/statuses/f54e0562e56ed2684fae93a6ab6ac901a0298e9d","head":{"label":"haroldangenent:topics/share-union-type-instances","ref":"topics/share-union-type-instances","sha":"f54e0562e56ed2684fae93a6ab6ac901a0298e9d","user":{"login":"haroldangenent","id":1481468,"node_id":"MDQ6VXNlcjE0ODE0Njg=","avatar_url":"https://avatars0.githubusercontent.com/u/1481468?v=4","gravatar_id":"","url":"https://api.github.com/users/haroldangenent","html_url":"https://github.com/haroldangenent","followers_url":"https://api.github.com/users/haroldangenent/followers","following_url":"https://api.github.com/users/haroldangenent/following{/other_user}","gists_url":"https://api.github.com/users/haroldangenent/gists{/gist_id}","starred_url":"https://api.github.com/users/haroldangenent/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/haroldangenent/subscriptions","organizations_url":"https://api.github.com/users/haroldangenent/orgs","repos_url":"https://api.github.com/users/haroldangenent/repos","events_url":"https://api.github.com/users/haroldangenent/events{/privacy}","received_events_url":"https://api.github.com/users/haroldangenent/received_events","type":"User","site_admin":false},"repo":{"id":152632344,"node_id":"MDEwOlJlcG9zaXRvcnkxNTI2MzIzNDQ=","name":"gatsby","full_name":"haroldangenent/gatsby","private":false,"owner":{"login":"haroldangenent","id":1481468,"node_id":"MDQ6VXNlcjE0ODE0Njg=","avatar_url":"https://avatars0.githubusercontent.com/u/1481468?v=4","gravatar_id":"","url":"https://api.github.com/users/haroldangenent","html_url":"https://github.com/haroldangenent","followers_url":"https://api.github.com/users/haroldangenent/followers","following_url":"https://api.github.com/users/haroldangenent/following{/other_user}","gists_url":"https://api.github.com/users/haroldangenent/gists{/gist_id}","starred_url":"https://api.github.com/users/haroldangenent/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/haroldangenent/subscriptions","organizations_url":"https://api.github.com/users/haroldangenent/orgs","repos_url":"https://api.github.com/users/haroldangenent/repos","events_url":"https://api.github.com/users/haroldangenent/events{/privacy}","received_events_url":"https://api.github.com/users/haroldangenent/received_events","type":"User","site_admin":false},"html_url":"https://github.com/haroldangenent/gatsby","description":"Build blazing fast, modern apps and websites with React","fork":true,"url":"https://api.github.com/repos/haroldangenent/gatsby","forks_url":"https://api.github.com/repos/haroldangenent/gatsby/forks","keys_url":"https://api.github.com/repos/haroldangenent/gatsby/keys{/key_id}","collaborators_url":"https://api.github.com/repos/haroldangenent/gatsby/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/haroldangenent/gatsby/teams","hooks_url":"https://api.github.com/repos/haroldangenent/gatsby/hooks","issue_events_url":"https://api.github.com/repos/haroldangenent/gatsby/issues/events{/number}","events_url":"https://api.github.com/repos/haroldangenent/gatsby/events","assignees_url":"https://api.github.com/repos/haroldangenent/gatsby/assignees{/user}","branches_url":"https://api.github.com/repos/haroldangenent/gatsby/branches{/branch}","tags_url":"https://api.github.com/repos/haroldangenent/gatsby/tags","blobs_url":"https://api.github.com/repos/haroldangenent/gatsby/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/haroldangenent/gatsby/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/haroldangenent/gatsby/git/refs{/sha}","trees_url":"https://api.github.com/repos/haroldangenent/gatsby/git/trees{/sha}","statuses_url":"https://api.github.com/repos/haroldangenent/gatsby/statuses/{sha}","languages_url":"https://api.github.com/repos/haroldangenent/gatsby/languages","stargazers_url":"https://api.github.com/repos/haroldangenent/gatsby/stargazers","contributors_url":"https://api.github.com/repos/haroldangenent/gatsby/contributors","subscribers_url":"https://api.github.com/repos/haroldangenent/gatsby/subscribers","subscription_url":"https://api.github.com/repos/haroldangenent/gatsby/subscription","commits_url":"https://api.github.com/repos/haroldangenent/gatsby/commits{/sha}","git_commits_url":"https://api.github.com/repos/haroldangenent/gatsby/git/commits{/sha}","comments_url":"https://api.github.com/repos/haroldangenent/gatsby/comments{/number}","issue_comment_url":"https://api.github.com/repos/haroldangenent/gatsby/issues/comments{/number}","contents_url":"https://api.github.com/repos/haroldangenent/gatsby/contents/{+path}","compare_url":"https://api.github.com/repos/haroldangenent/gatsby/compare/{base}...{head}","merges_url":"https://api.github.com/repos/haroldangenent/gatsby/merges","archive_url":"https://api.github.com/repos/haroldangenent/gatsby/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/haroldangenent/gatsby/downloads","issues_url":"https://api.github.com/repos/haroldangenent/gatsby/issues{/number}","pulls_url":"https://api.github.com/repos/haroldangenent/gatsby/pulls{/number}","milestones_url":"https://api.github.com/repos/haroldangenent/gatsby/milestones{/number}","notifications_url":"https://api.github.com/repos/haroldangenent/gatsby/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/haroldangenent/gatsby/labels{/name}","releases_url":"https://api.github.com/repos/haroldangenent/gatsby/releases{/id}","deployments_url":"https://api.github.com/repos/haroldangenent/gatsby/deployments","created_at":"2018-10-11T17:48:00Z","updated_at":"2018-10-11T17:48:19Z","pushed_at":"2018-10-12T11:37:55Z","git_url":"git://github.com/haroldangenent/gatsby.git","ssh_url":"git@github.com:haroldangenent/gatsby.git","clone_url":"https://github.com/haroldangenent/gatsby.git","svn_url":"https://github.com/haroldangenent/gatsby","homepage":"https://www.gatsbyjs.org","size":432348,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"gatsbyjs:master","ref":"master","sha":"9523a2503c2932984a27f385961741720384f777","user":{"login":"gatsbyjs","id":12551863,"node_id":"MDEyOk9yZ2FuaXphdGlvbjEyNTUxODYz","avatar_url":"https://avatars1.githubusercontent.com/u/12551863?v=4","gravatar_id":"","url":"https://api.github.com/users/gatsbyjs","html_url":"https://github.com/gatsbyjs","followers_url":"https://api.github.com/users/gatsbyjs/followers","following_url":"https://api.github.com/users/gatsbyjs/following{/other_user}","gists_url":"https://api.github.com/users/gatsbyjs/gists{/gist_id}","starred_url":"https://api.github.com/users/gatsbyjs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gatsbyjs/subscriptions","organizations_url":"https://api.github.com/users/gatsbyjs/orgs","repos_url":"https://api.github.com/users/gatsbyjs/repos","events_url":"https://api.github.com/users/gatsbyjs/events{/privacy}","received_events_url":"https://api.github.com/users/gatsbyjs/received_events","type":"Organization","site_admin":false},"repo":{"id":36040894,"node_id":"MDEwOlJlcG9zaXRvcnkzNjA0MDg5NA==","name":"gatsby","full_name":"gatsbyjs/gatsby","private":false,"owner":{"login":"gatsbyjs","id":12551863,"node_id":"MDEyOk9yZ2FuaXphdGlvbjEyNTUxODYz","avatar_url":"https://avatars1.githubusercontent.com/u/12551863?v=4","gravatar_id":"","url":"https://api.github.com/users/gatsbyjs","html_url":"https://github.com/gatsbyjs","followers_url":"https://api.github.com/users/gatsbyjs/followers","following_url":"https://api.github.com/users/gatsbyjs/following{/other_user}","gists_url":"https://api.github.com/users/gatsbyjs/gists{/gist_id}","starred_url":"https://api.github.com/users/gatsbyjs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gatsbyjs/subscriptions","organizations_url":"https://api.github.com/users/gatsbyjs/orgs","repos_url":"https://api.github.com/users/gatsbyjs/repos","events_url":"https://api.github.com/users/gatsbyjs/events{/privacy}","received_events_url":"https://api.github.com/users/gatsbyjs/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/gatsbyjs/gatsby","description":"Build blazing fast, modern apps and websites with React","fork":false,"url":"https://api.github.com/repos/gatsbyjs/gatsby","forks_url":"https://api.github.com/repos/gatsbyjs/gatsby/forks","keys_url":"https://api.github.com/repos/gatsbyjs/gatsby/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gatsbyjs/gatsby/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gatsbyjs/gatsby/teams","hooks_url":"https://api.github.com/repos/gatsbyjs/gatsby/hooks","issue_events_url":"https://api.github.com/repos/gatsbyjs/gatsby/issues/events{/number}","events_url":"https://api.github.com/repos/gatsbyjs/gatsby/events","assignees_url":"https://api.github.com/repos/gatsbyjs/gatsby/assignees{/user}","branches_url":"https://api.github.com/repos/gatsbyjs/gatsby/branches{/branch}","tags_url":"https://api.github.com/repos/gatsbyjs/gatsby/tags","blobs_url":"https://api.github.com/repos/gatsbyjs/gatsby/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gatsbyjs/gatsby/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gatsbyjs/gatsby/git/refs{/sha}","trees_url":"https://api.github.com/repos/gatsbyjs/gatsby/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gatsbyjs/gatsby/statuses/{sha}","languages_url":"https://api.github.com/repos/gatsbyjs/gatsby/languages","stargazers_url":"https://api.github.com/repos/gatsbyjs/gatsby/stargazers","contributors_url":"https://api.github.com/repos/gatsbyjs/gatsby/contributors","subscribers_url":"https://api.github.com/repos/gatsbyjs/gatsby/subscribers","subscription_url":"https://api.github.com/repos/gatsbyjs/gatsby/subscription","commits_url":"https://api.github.com/repos/gatsbyjs/gatsby/commits{/sha}","git_commits_url":"https://api.github.com/repos/gatsbyjs/gatsby/git/commits{/sha}","comments_url":"https://api.github.com/repos/gatsbyjs/gatsby/comments{/number}","issue_comment_url":"https://api.github.com/repos/gatsbyjs/gatsby/issues/comments{/number}","contents_url":"https://api.github.com/repos/gatsbyjs/gatsby/contents/{+path}","compare_url":"https://api.github.com/repos/gatsbyjs/gatsby/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gatsbyjs/gatsby/merges","archive_url":"https://api.github.com/repos/gatsbyjs/gatsby/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gatsbyjs/gatsby/downloads","issues_url":"https://api.github.com/repos/gatsbyjs/gatsby/issues{/number}","pulls_url":"https://api.github.com/repos/gatsbyjs/gatsby/pulls{/number}","milestones_url":"https://api.github.com/repos/gatsbyjs/gatsby/milestones{/number}","notifications_url":"https://api.github.com/repos/gatsbyjs/gatsby/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gatsbyjs/gatsby/labels{/name}","releases_url":"https://api.github.com/repos/gatsbyjs/gatsby/releases{/id}","deployments_url":"https://api.github.com/repos/gatsbyjs/gatsby/deployments","created_at":"2015-05-21T22:43:05Z","updated_at":"2018-10-12T11:07:10Z","pushed_at":"2018-10-12T11:46:01Z","git_url":"git://github.com/gatsbyjs/gatsby.git","ssh_url":"git@github.com:gatsbyjs/gatsby.git","clone_url":"https://github.com/gatsbyjs/gatsby.git","svn_url":"https://github.com/gatsbyjs/gatsby","homepage":"https://www.gatsbyjs.org","size":432359,"stargazers_count":26631,"watchers_count":26631,"language":"JavaScript","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":3128,"mirror_url":null,"archived":false,"open_issues_count":731,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":3128,"open_issues":731,"watchers":26631,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/gatsbyjs/gatsby/pulls/9052"},"html":{"href":"https://github.com/gatsbyjs/gatsby/pull/9052"},"issue":{"href":"https://api.github.com/repos/gatsbyjs/gatsby/issues/9052"},"comments":{"href":"https://api.github.com/repos/gatsbyjs/gatsby/issues/9052/comments"},"review_comments":{"href":"https://api.github.com/repos/gatsbyjs/gatsby/pulls/9052/comments"},"review_comment":{"href":"https://api.github.com/repos/gatsbyjs/gatsby/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/gatsbyjs/gatsby/pulls/9052/commits"},"statuses":{"href":"https://api.github.com/repos/gatsbyjs/gatsby/statuses/f54e0562e56ed2684fae93a6ab6ac901a0298e9d"}},"author_association":"NONE"}}
{"actor":{"display_login":"haroldangenent"}}