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

fix(gatsby): support union types for one-to-one ___NODE relations #19916

Merged
merged 2 commits into from
Dec 3, 2019

Conversation

vladar
Copy link
Contributor

@vladar vladar commented Dec 2, 2019

Description

This PR should make the processing of ___NODE convenience fields consistent for one-to-one and one-to-many relations (currently one-to-many works as expected while one-to-one doesn't).

Take this example with one-to-one relation:

createNode({
  internal: { type: `MyType` },
  related___NODE: `FooTypeNode1`,
})
createNode({
  internal: { type: `MyType` },
  related___NODE: `BarTypeNode1`,
})

The expected inference result is a union type:

type MyType {
  related: FooBar
}

union FooBar = Foo | Bar

The actual result is a first registered object type:

type MyType {
  related: Foo
}

The same example for one-to-many relation produces an expected result:

createNode({
  internal: { type: `MyType` },
  related___NODE: [`FooTypeNode1`],
})
createNode({
  internal: { type: `MyType` },
  related___NODE: [`BarTypeNode1`],
})

Results in:

type MyType {
  related: [FooBar]
}

union FooBar = Foo | Bar

Related Issues

Fixes #10090

@vladar vladar changed the title fix(gatsby): support union types for a single node relation using ___NODE convention fix(gatsby): support union types for one-to-one ___NODE relations Dec 3, 2019
@vladar vladar marked this pull request as ready for review December 3, 2019 08:57
@vladar vladar requested a review from a team as a code owner December 3, 2019 08:57
Copy link
Contributor

@pvdz pvdz left a comment

Choose a reason for hiding this comment

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

Looks fine to me.

How big are these clusters of nodes? Because if we Object.keys() them at every turn, or they are big with random key names, we should really consider to use Maps here. I suspect that'll make a big difference.

Approving since that's not in the scope of this PR. Food for thought.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot: merge on green Gatsbot will merge these PRs automatically when all tests passes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Single reference fields that accept multiple content types don't work in GraphQL
3 participants