question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@client directive breaks fragments

See original GitHub issue

Intended outcome: Trying to use a fragment in a query with @client directive

export const GET_APPS = gql`
  fragment AppFragment on App {
    id
    name
  }
  query GetApps {
    apps @client {
      ...AppFragment
      # id
      # name
    }
  }
`

Returns the apps with their id and name fields(it works if i uncomment the two fields)

Actual outcome: The apps are returned with no fields at all

How to reproduce the issue: I’m just using a TypePolicies Query that returns an array of object with the id and name fields

Versions "@apollo/client": "^3.0.0-beta.43"

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
hwillsoncommented, May 7, 2021

@Banou26 thanks for updating your reproduction. This isn’t a bug though. You aren’t providing enough information in your read function to resolve the fragment properly. Your fragment is on the type Foo, but you aren’t referencing Foo when you return data from the foo read function. Update your code with the following, and it will work:

cache.policies.addTypePolicies({
  Query: {
    fields: {
      foo: {
        read: () => ({ bar: 'bar', __typename: "Foo" })
      }
    }
  }
});
1reaction
Banou26commented, May 6, 2021

Still an issue under ^3.3.16 which is current latest

Repro here with the code example i gave: https://github.com/Banou26/apollo-client-bug-6175

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fragments - Apollo GraphQL Docs
A GraphQL fragment is a piece of logic that can be shared between multiple queries and mutations. Every fragment includes a subset of...
Read more >
Can I define fragments on either the client or the server? - Reddit
It seems like I define fragments on either the client (using functions like gql or graphql ) or on the server (using functions...
Read more >
Fragment composition with Apollo client: convention and ...
I'd like to know better how to compose GraphQL fragments with Apollo client. I know how to do it, but I'd like to...
Read more >
Using fragments | Vue Apollo
The most straightforward use of fragments is to reuse parts of queries (or mutations or subscriptions) in various parts of your application. For...
Read more >
A deep-dive into Relay, the friendly & opinionated GraphQL ...
Go with a less opinionated, more flexible GraphQL client like Apollo. Anatomy of Relay. Colocation. Fragments; Data masking. Relay compiler.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found