micimize / graphql-to-dart

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

Problem with aliases (on master) #22

Closed EugenePisotsky closed 4 years ago

EugenePisotsky commented 4 years ago

Hi,

There's a problem with aliases. Query like this:

    route: geoRoute(locations: $locations) {
        ...RouteFragment
    }

    targetRoute: geoRoute(locations: $locationsAll) {
        ...RouteFragment
    }

... is generated to this code:

SimulatorRoutesQuery({
          @required SimulatorRouteFragmentRoute route,
          @required SimulatorRouteFragmentTargetRoute targetRoute,

  }): super(
      geoRoute: route,
      geoRoute: targetRoute,
  )

(2 geoRoute passed to super)

micimize commented 4 years ago

oh heck, you're right. I guess we need to recognize a field accessed multiple times and add additional properties to the fields object for each beyond the 1st

EugenePisotsky commented 4 years ago

also, probably not the best way, but as a workaround I was thinking about using map for aliased fields in the root Query class, something like:

Map<String, dynamic> aliasedFields = Map();

and if schemaFieldName not equals to name, mixin can set / get it from the aliasedFields map

micimize commented 4 years ago

1.1.5-beta fixes this specific issue, but there are still some serious problems in #24