Skip to content

[Feature Request] Add methods to DataBuilders to copy nested fragment data class properties to the current data class #479

Open
@tpucci

Description

@tpucci

Hey!

I think it would be awesome to have methods to copy nested fragment data to the current builder.

My use case is to create a lot of mocks that could import one another for easier maintenance.
But without the possibility to use a fragment data inside a query data builder, it makes this a lot more complicated.

Here is an example (notice the fromHumanFrag method):

fragment HumanFrag on Human {
    id
    birthday
    height(unit: METER)
}

query HumanQuery($id: ID!) {

    human(id: $id) {
        ...HumanFrag
    }
}
  test('can serialize and deserialize responses with nested fragment', () {
    final human = GHumanFragData((b) => b
      ..id = '123'
      ..height = 180.0
      ..birthday = DateTime(2021, 1, 1));

    final res = GHumanQueryData((b) => b
      ..human.fromHumanFrag(human));

    final json = res.toJson();

    final resFromJson = GHumanQueryData.fromJson(json);

    expect(res, resFromJson);
  });

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions