apollo-client icon indicating copy to clipboard operation
apollo-client copied to clipboard

Runtime error when passing `DocumentNode` array to `createFragmentRegistry`

Open alessbell opened this issue 1 year ago • 2 comments

Issue Description

Clone the example in https://github.com/alessbell/nonreactive.

Replace the following lines:

    fragments: createFragmentRegistry(gql`
      ${UserFragment}
    `),

with

    fragments: createFragmentRegistry([UserFragment]),

This type checks, but the following runtime error occurs: Cannot read properties of undefined (reading 'filter') at the doc.definitions.filter line in getFragmentDefinitions.

Link to Reproduction

https://github.com/alessbell/nonreactive

Reproduction Steps

No response

alessbell avatar Jun 12 '23 19:06 alessbell

Facing this problem. I was expecting to be able to use an array of fragments based on the type documentation, but seems like this is not possible?

lsfgrd avatar Oct 20 '23 17:10 lsfgrd

Having similar issue here. I have generated schema using graphql-codegen, and I'm trying to use my fragments like this

import { UserFragmentDoc } from 'generated/graphql.ts'

const cache = new InMemoryCache({
  fragments: createFragmentRegistry([UserFragmentDoc]),
})

I'm having same issue Cannot read properties of undefined (reading 'filter'), even though my UserFragmentDoc has correct kind and correctly types definitions

sheff3rd avatar Apr 16 '24 19:04 sheff3rd