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

feat: resolve all pivot attributes #2464

Merged
merged 7 commits into from
Feb 1, 2024
Merged

feat: resolve all pivot attributes #2464

merged 7 commits into from
Feb 1, 2024

Conversation

jaulz
Copy link
Contributor

@jaulz jaulz commented Nov 8, 2023

  • Added or updated tests
  • Documented user facing changes
  • Updated CHANGELOG.md

Changes

This PR allows users to expose all pivot fields in connections in a new field pivot which resides next to node and cursor. This could be helpful in the following situation:

type Post {
  id: ID
  title: String
}

type User {
  id: ID
  name: String
  ratedPosts: [Post] @hasMany(type: CONNECTION, defaultCount: 25, edgeType: "UserPostEdge")
}

type UserPost {
  id: ID
  rating: Int
}

type UserPostEdge {
  cursor: String!
  node: Post!
  pivot: UserPost!
}

extend type Query {
  userById(id: ID! @eq): User @find
}

Now we can query the user and his rated posts like this:

query ListRatedPosts {
  userById(id: 3) {
    ratedPosts {
      edges {
        node {
          id
          title
        }
        pivot {
          id
          rating
        }
      }
    }
  }
}

Since the pivot field is now of type UserPost we can easily update the rating in these entities on the client (i.e. optimistic update) without fetching the whole list again.

Breaking changes

The change will break things in the unlikely situation that there is a pivot field within the pivot field.

@spawnia spawnia added the enhancement A feature or improvement label Nov 28, 2023
src/Pagination/ConnectionField.php Outdated Show resolved Hide resolved
@spawnia spawnia marked this pull request as draft November 29, 2023 14:58
@jaulz jaulz marked this pull request as ready for review February 1, 2024 10:08
@jaulz jaulz requested a review from spawnia February 1, 2024 10:09
@spawnia spawnia merged commit 24cec48 into nuwave:master Feb 1, 2024
24 checks passed
@spawnia
Copy link
Collaborator

spawnia commented Feb 1, 2024

Thank you, released with https://github.com/nuwave/lighthouse/releases/tag/v6.33.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A feature or improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants