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

introduce new Intersection type #3550

Closed
wants to merge 1 commit into from
Closed

Conversation

yaacovCR
Copy link
Contributor

Intersections of unions and interfaces can be considered to "implement" their unions and interface members.

A type with a field of type Intersection will satisfy an interface where the field defined in the interface is one of the member types of the intersection.

Alternative to #3527

@netlify
Copy link

netlify bot commented Apr 29, 2022

Deploy Preview for compassionate-pike-271cb3 ready!

Name Link
🔨 Latest commit c328036
🔍 Latest deploy log https://app.netlify.com/sites/compassionate-pike-271cb3/deploys/627123b28ccb110008fda069
😎 Deploy Preview https://deploy-preview-3550--compassionate-pike-271cb3.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@github-actions
Copy link

Hi @yaacovCR, I'm @github-actions bot happy to help you with this PR 👋

Supported commands

Please post this commands in separate comments and only one per comment:

  • @github-actions run-benchmark - Run benchmark comparing base and merge commits for this PR
  • @github-actions publish-pr-on-npm - Build package from this PR and publish it on NPM

@yaacovCR
Copy link
Contributor Author

@yaacovCR yaacovCR force-pushed the intersection branch 3 times, most recently from dcea440 to 16e050a Compare April 29, 2022 14:15
@yaacovCR
Copy link
Contributor Author

intersection "implementing" interface

# generic types
interface Node {
  id: ID!
}

interface Connection {
  pageInfo: PageInfo!
  edges: [Edge]
}

interface Edge {
  cursor: String
  node: Node
}

type PageInfo {
  hasPreviousPage: Boolean
  hasNextPage: Boolean
  startCursor: String
  endCursor: String
}

# schema-specific types
interface Pet {
  id: ID!
  name: String
}

type Cat implements Pet & Node {
  id: ID!
  name: String
}

type Dog implements Pet & Node {
  id: ID!
  name: String
}

union HousePet = Cat | Dog

intersection HousePetNode = HousePet & Pet & Node

# house-pet-specific types
type HousePetEdge implements Edge {
  cursor: String
  node: HousePetNode # <<< This is what is unlocked by this PR
}

type HousePetConnection implements Connection {
  pageInfo: PageInfo!
  edges: [HousePetEdge]
}

# query
type Query {
  housePets: HousePetConnection
}

intersection "implementing" interface AND narrowing unions

# generic types
interface Node {
  id: ID!
}

interface Connection {
  pageInfo: PageInfo!
  edges: [Edge]
}

interface Edge {
  cursor: String
  node: Node
}

type PageInfo {
  hasPreviousPage: Boolean
  hasNextPage: Boolean
  startCursor: String
  endCursor: String
}

# schema-specific types
interface Pet {
  id: ID!
  name: String
}

type Cat implements Pet & Node {
  id: ID!
  name: String
}

type Dog implements Pet & Node {
  id: ID!
  name: String
}

type Fish implements Pet & Node {
  id: ID!
  name: String
}

type Lion implements Pet & Node {
  id: ID!
  name: String
}

union HousePet = Cat | Dog | Fish
union PetWithFur = Cat | Dog | Lion

intersection HousePetWithFurNode = HousePet & PetWithFur & Pet & Node

# house-pet-specific types
type HousePetWithFurEdge implements Edge {
  cursor: String
  node: HousePetWithFurNode  # <<< This is what is unlocked by this PR
}

type HousePetWithFurNodeConnection implements Connection {
  pageInfo: PageInfo!
  edges: [HousePetWithFurEdge]
}

# query
type Query {
  housePetsWithFur: HousePetWithFurNodeConnection
}

@yaacovCR yaacovCR added the spec RFC Implementation of a proposed change to the GraphQL specification label Apr 29, 2022
yaacovCR added a commit to yaacovCR/graphql-spec that referenced this pull request Apr 30, 2022
yaacovCR added a commit to yaacovCR/graphql-spec that referenced this pull request Apr 30, 2022
@yaacovCR
Copy link
Contributor Author

spec PR: graphql/graphql-spec#941

@yaacovCR
Copy link
Contributor Author

discussion @ graphql/graphql-wg#944

yaacovCR added a commit to yaacovCR/graphql-spec that referenced this pull request May 3, 2022
yaacovCR added a commit to yaacovCR/graphql-spec that referenced this pull request May 3, 2022
yaacovCR added a commit to yaacovCR/graphql-spec that referenced this pull request May 3, 2022
@yaacovCR yaacovCR force-pushed the intersection branch 4 times, most recently from d6696df to 8723cad Compare May 3, 2022 12:06
Intersections of unions and interfaces can be considered to "implement" their unions and interface members.

A type with a field of type Intersection will satisfy an interface where the field defined in the interface is one of the member types of the intersection.

Alternative to graphql#3527
@yaacovCR
Copy link
Contributor Author

yaacovCR commented May 5, 2022

Summary of discussion from WG https://github.com/graphql/graphql-wg/blob/main/agendas/2022/2022-05-05.md :

union HousePet implements Node was overwhelmingly felt to be best because it is (1) expressive (2) concise (3) less complex (4) will lead to early validation error, which overall would be most valuable. Intersections were felt to be powerful tools that would then propagate a small number of breaking changes to a large number of dangerous and --more importantly-- possibly silent errors!

The action item will then be to move forward as possible with graphql/graphql-spec#939 . Immediate next steps is to refine the implementation at #3527 with further checking for all the necessary validation and test changes.

@yaacovCR yaacovCR closed this May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
spec RFC Implementation of a proposed change to the GraphQL specification
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant