github apollographql/apollo-client @apollo/client@4.4.0-alpha.1

pre-release37 minutes ago

Minor Changes

  • #13522 6f94cfb Thanks @jerelmiller! - Fragment APIs now read fragment arguments and operation variables from the object passed to from. When you pass an object from a query result, you no longer need to pass variables to read the fragment with the correct values.

    const fragment = gql`
      fragment UserCard($avatarSize: Int) on User {
        id
        avatar(size: $avatarSize)
      }
    `;
    
    const query = gql`
      query GetUsers($friendAvatarSize: Int) {
        currentUser {
          ...UserCard(avatarSize: 96)
          friends {
            ...UserCard(avatarSize: $friendAvatarSize)
          }
        }
      }
    `;
    
    const { data } = useQuery(query, { variables: { friendAvatarSize: 32 } });
    
    // Reads the avatar with `size: 96`
    useFragment({ fragment, from: data.currentUser });
    
    // Reads the avatars with `size: 32`
    useFragment({ fragment, from: data.currentUser.friends });

    This works with useFragment, useSuspenseFragment, watchFragment, readFragment, writeFragment, and updateFragment. The same applies to fragments that use operation variables without fragment arguments.

  • #13521 7bd29db Thanks @phryneas! - CombinedGraphQLErrors and CombinedProtocolErrors now extend AggregateError.
    This means that you will need to use at least lib: ["es2021"] or lib: ["es2021.promise"] in your TypeScript configuration.

Don't miss a new apollo-client release

NewReleases is sending notifications on new releases.