Skip to content

Generation of Duplicated Fragments in nested fragments Β #3063

@zerocity

Description

@zerocity

Hi , i get several errors of "There can be only one fragment named ..." on the Client Side(Apollo).

On this example below it would be "There can be only one fragment named uptimeMeasurements"

Problem

The Group will import "PublicUptimeMeasurementsFragmentDoc" and the Component which could be a child of the group.

The generated Fragments look like this

// Pseudo Interfaces  for clarification 
export type PublicComponentTreeFragment = {
  components: Array<ComponentGroup | Component>
}

export type ComponentGroup = {
  id: Scalars['ID']
  label: Scalars['String']
  components: Array<Component>
  uptimeMeasurements: UptimeAggregation
}

export type Component = {
  id: Scalars['ID']
  label: Scalars['String']
  uptimeMeasurements: UptimeAggregation
}

// generated fragments
export const PublicComponentTreeFragmentDoc = gql`
  fragment publicComponentTree on PublicRootComponentGroup {
    id
    label
    components {
      ...publicComponent
      ...publicComponentGroup
    }
  }
  ${PublicComponentFragmentDoc}
  ${PublicComponentGroupFragmentDoc}
`

export const PublicComponentFragmentDoc = gql`
  fragment publicComponent on PublicComponent {
    id
    label
    uptimeMeasurements(view: $componentTimespan) {
      ...publicUptimeMeasurements
    }
  }
  ${PublicUptimeMeasurementsFragmentDoc}
  ${PublicResponseTimeMetricFragmentDoc}
`
export const PublicComponentGroupFragmentDoc = gql`
  fragment publicComponentGroup on PublicComponentGroup {
    id
    label
    uptimeMeasurements(view: $componentTimespan) {
      ...publicUptimeMeasurements
    }
    components {
      ...publicComponent
    }
  }
  ${PublicUptimeMeasurementsFragmentDoc}
  ${PublicComponentFragmentDoc}
`

i am using version of 1.9.1

overwrite: true
schema: "./schema.graphql"
documents: 'src/**/*.gql'
generates:
  src/types.ts:
    plugins:
      - add: // tslint:disable
      - add: /* eslint-disable */
      - typescript
    config: 
      namingConvention:
        enumValues: change-case#upperCase
  src/:
    preset: near-operation-file
    presetConfig:
      extension: .gen.tsx
      baseTypesPath: types.ts
    plugins:
      - add: // tslint:disable
      - add: /* eslint-disable */
      - typescript-operations
      - typescript-react-apollo
    config:
      withHooks: true
      preResolveTypes: true
      skipTypename: true
      gqlImport: graphql-tag.macro

is there a option to import fragments on queryDocument level ?

thanks for help

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