这是indexloc提供的服务,不要输入任何密码
Skip to content

Fragment with nested deferred fragment does not work with isFragmentReady  #9564

@ludusrusso

Description

@ludusrusso

Which packages are impacted by your issue?

@graphql-codegen/client-preset

Describe the bug

When using isFragmentReady function with a fragment that has a deferred nested fragment, the function returns only true, this is related to the fact that __meta__.deferredFields is not populated on fragments, but only on queries.

e.g.

//@ts-ignore
const Fragment = gql(/* GraphQL */ `
  fragment Foo on Foo {
    value
  }
`);


//@ts-ignore
const NestedFragmentWithFragment = gql(/* GraphQL */ `
  fragment fooNested on Foo {
    id
    ...foo @defer
  }
`);

Your Example Website or App

https://github.com/ludusrusso/example-gql-codegen-with-fragment-deferred

Steps to Reproduce the Bug or Issue

  • Create a fragment
  • Use the fragment in other fragment with @defer
  • use isFragmentReady function, it will always return true

Expected behavior

isFragmentReady should return false if the nested deferred fragment is not ready.

Screenshots or Videos

No response

Platform

  • OS: macOS
  • NodeJS: 18.5.0
  • graphql 16.6.0
  • @graphql-codegen/* ^4.0.1

Codegen Config File

// eslint-disable-next-line import/no-extraneous-dependencies
import { type CodegenConfig } from '@graphql-codegen/cli';


const config: CodegenConfig = {
  schema: './src/yoga.mjs',
  documents: ['src/**/*.tsx'],
  generates: {
    './src/gql/': {
      preset: 'client',
    },
  },
  hooks: { afterAllFileWrite: ['prettier --write'] },
};

export default config;

Additional context

Example repo: https://github.com/ludusrusso/example-gql-codegen-with-fragment-deferred

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions