micimize / graphql-to-dart

generate dart classes and respective JsonSerializable transcoders
42 stars 8 forks source link

fragment merging #29

Closed micimize closed 4 years ago

micimize commented 4 years ago

I've handled regular field merging

{
      f: friends {
        name
      }
      f: friends {
        id
      }
}
#=>
{
      f: friends {
        name
        id
      }
}

But nested field fragment merging is a nightmare. I'm not going to do it anytime soon.

Basically, figuring out that ...info generates Relationships which contains the field friends which gets merged into friends in the top level query is just a horrible thing to deal with in the current design.

fragment home on Human {
  home: homePlanet
  planet: homePlanet
}

fragment dimensions on Human {
  height
  mass
}

fragment relationships on Human {
  friends {
    name
  }
  starships {
    name
    length
  }
}

fragment info on Human {
  ...dimensions
  ...home
}

query HeroForEpisode($ep: Episode!) {
  hero(episode: $ep) {
    # without typename we can't really tell which fragments to parse
    __typename
    name
    ... on Droid {
      primaryFunction
    }
    ... on Human {
      friends {
        name
        id
      }
      appearsIn
      ...info
      ...relationships
    }
  }
}
micimize commented 4 years ago

closing in favor of #27