Graphql-code-generator: Angular template: problems with fragments

Created on 15 Sep 2018  路  8Comments  路  Source: dotansimha/graphql-code-generator

Hi,

I found two problems with fragments for the Angular template. This is an extract of the generated code:

const InvoiceCheckResultFragment = gql`
  fragment InvoiceCheckResult on InvoiceCheckResult {
    rowsWithUnknownProductCodes
    unknownShippings {
      ...InvoiceShipping
    }
    shippingsThatWereChargedMultipleTimes
    shippings {
      ...InvoiceShipping
    }
  }

  ${InvoiceShippingFragment}
  ${InvoiceShippingFragment}
`;

...

const InvoiceShippingFragment = gql`
  fragment InvoiceShipping on InvoiceShipping {
    rowsWithUnknownProductCodes
    invoiceNumber
....

The first one is the same one that you have fixed in #591 for react (fragment definition order). TypeScript spits out the error
error TS2448: Block-scoped variable 'InvoiceShippingFragment' used before its declaration.

The second problem is that fragments that are referenced twice are included twice in the gql-string. In this case, this is InvoiceShippingFragment.

bug plugins waiting-for-release

Most helpful comment

Tested it -> fixed :-)
Thanks a lot!

All 8 comments

@kamilkisiela

wrong order of fragments (test + fix): https://github.com/dotansimha/graphql-code-generator/pull/615

I didn't use a getter function because it doesn't fix an issue with TypeScript screaming about the order of declarations. I create dependency graph to resolve them in the proper order.

About duplicated fragments, now it checks if it was declared and skips it.

Fixed in 0.12.3 :)

v0.12.3 is out

Tested it -> fixed :-)
Thanks a lot!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zenVentzi picture zenVentzi  路  3Comments

mszczepanczyk picture mszczepanczyk  路  3Comments

leebenson picture leebenson  路  3Comments

bastman picture bastman  路  3Comments

fvisticot picture fvisticot  路  3Comments