Skip to content

Static fragments on Client Components #27

@amannn

Description

@amannn

Hey! Really exciting to see Apollo experimenting with RSC support in Next.js! 👏

I'm using a Relay-esque approach with Apollo Client, where components define fragments so that data requirements can be colocated with the code that consumes them and to reliably orchestrate data dependencies upwards a component hierarchy.

import { gql } from "@apollo/client";

export default function User({user}) {
  return <p>{user.name}</p>
}

User.fragments = {
  user: gql`
    fragment User_user on User {
      name
    }
  `
}

I noticed this works as long as the components that define fragments are Server Components, but since imports from Server Components to Client Components create a lazy reference, the static fragments are no longer resolvable.

Based on one of the examples in this repo, I've added this commit for demonstration: amannn@fa8c9d3

This is not really a limitation of Apollo, but of the RSC model I guess. I was wondering if this is something that you're interested in supporting and if there's something that can be done about this? The only thing that comes to my mind is a compiler that resolves the static parts at build time, but I guess ideally there would be 1st-class support from the RSC bundler for this.

Many thanks! 🙌

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions