Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tpucci opened this issue Feb 27, 2025 · 0 comments

Comments

@tpucci
Copy link

tpucci commented Feb 27, 2025

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);
  });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant