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.

Cannot read/write nested fragments

See original GitHub issue
Versions

Versions

Describe the bug

In our project, we create a new GraphQL file for each query, mutation, and fragment. Out of that, a types file is generated, including the GraphQL document.

We’re making use of the Apollo write/read fragment feature, in order to store some state in the Apollo cache or simply overwrite some data. For this, we use the document of the fragment from the generated types file.

With the latest update, we get an error, that no fragment was found for a specific name. We looked a bit deeper into that and found out, for fragments that import another fragment, the fragment is not included in the respective document.

fragment Zip on Zip {
   zip
}
#import "./zip.fragment.gql"
fragment Address on Address {
   street
   zip {
     ...Zip
   } 
}
import { AddressFragmentDoc } from './address.fragment.gql-types.tsx';

client.writeFragment({
   fragment: AddressFragmentDoc,
   data: {
      // the data
   }
})

This causes the following error: Invariant Violation: No fragment named Zip.

Looking into the changes of our current upgrade PR, we can see that for all fragments that all fragment.definitions assignments to the document got removed, while they been added to the respective query and mutations.

Example:

export const AddressFragmentDoc = {
  kind: 'Document',
  defintions: [
    {
       // the current fragment document defintion
    }
-    ...ZipFragmentDoc.definitions
  ]
}

It seems, by removing the definitions of the imported fragment we lose the information about the fragment.

Questions

  • is this a bug?
  • is there any configuration around this issue?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:7
  • Comments:6

github_iconTop GitHub Comments

3reactions
whathercommented, Feb 18, 2022

I’m hitting this as well. Is there a fix in sight?

1reaction
n1ru4lcommented, Aug 19, 2021

@johannesbraeunig Can you please provide a reproduction or even better pr with a failing test for this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't retain nested fragments - Stack Overflow
You can use FragmentManager.saveFragmentInstanceState(Fragment) to retrieve a fragment state. The return value implements Parcelable, so you can put it in a ...
Read more >
Configuring the Apollo Client cache - Apollo GraphQL Docs
Define polymorphic type relationships for fragment matching; Define patterns for pagination; Manage client-side local state. To customize cache behavior, you ...
Read more >
How to stream XML fragments from an XmlReader - LINQ to ...
You can stream XML fragments from an XmlReader using a custom axis ... The ReadFrom method doesn't return until it has read the...
Read more >
aws-cdk/aws-stepfunctions module - AWS Documentation
You can pass fragments of this State Machine Data into Tasks of the state machine. ... If your Choice doesn't have an otherwise()...
Read more >
Critical section - Wikipedia
In concurrent programming, concurrent accesses to shared resources can lead to unexpected or ... This protected section cannot be entered by more than...
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