gql-dart / ferry

Stream-based strongly typed GraphQL client for Dart
https://ferrygraphql.com/
MIT License
602 stars 116 forks source link

[FerryGenerator] The code generated for schemas with intricate fragment spread may reference non-existent types #555

Open koutaro-masaki opened 10 months ago

koutaro-masaki commented 10 months ago

If there is a schema like the following, setting reuse_fragments causes the generated GBookFragment2_author to implement not only GAuthorFragment but also the non-existent type GBookFragment_author.

# book.graphql
type Book {
  title: String
  author: Person
}

type Person {
  name: String
  age: Int
  height: Int
  weight: Int
}

fragment AuthorFragment on Person {
  name
  age
}

fragment BookFragment on Book {
  title
  author {
    ...AuthorFragment
  }
}
# book2.graphql
fragment BookFragment2 on Book {
  ...BookFragment
  author {
    height
    weight
  }
}

If BookFragment and BookFragment2 are defined in the same file, this issue did not occur.

koutaro-masaki commented 10 months ago

However, defining fragments in the same file may cause UnusedFragment errors, making this not a very effective workaround.

https://github.com/gql-dart/ferry/issues/337