Skip to content
This repository was archived by the owner on Oct 2, 2024. It is now read-only.
This repository was archived by the owner on Oct 2, 2024. It is now read-only.

Add "freezed" feature to codegen #370

@WDtms

Description

@WDtms

Before reporting a bug, please test the beta branch!

Bug description

For now it's pretty hard to use generated classes from "union" type;

For example now, to identify object and use it's field i need to use this construction:

query xxx {
   sometype: {
      ...on X {
         onlyXField
      }
      ...on Y {
         onlyYField
      }
      ...on Z {
         onlyZField
      }
   }
}
if (parsedObject is X) {
   return x.onlyXField;
}
if (parsedObject is Y) {
   return y.onlyYField;
}
if (parsedObject is Z) {
   return z.onlyZField;
}

// unsupported type
return error;

and if i use mixin (fragments inside queries), then i'd have to:

if (parsedObject is X) {
   return (x as XMixin).onlyXField;
}
if (parsedObject is Y) {
   return (y as XMixin).onlyYField;
}
if (parsedObject is Z) {
   return (z as XMixin).onlyZField;
}

// unsupported type
return error;

with "freezed" it would be something like this:

x.map(
   X: (it) => it.onlyXField,
   Y: (it) => it.onlyYField,
   Z: (it) => it.onlyZField,
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions