graphql_fragment_generator

Last updated:

0 purchases

graphql_fragment_generator Image
graphql_fragment_generator Images
Add to Cart

Description:

graphql fragment generator

GraphQL Fragment Generator #
You can generate a fragment of GraphQL.
Example #
Given a library timeline.dart with a Timeline class and user.dart with a User class both annotated with @GraphQLFragment():
import 'package:graphql_fragment_annotation/graphql_fragment_annotation.dart';
import 'package:json_annotation/json_annotation.dart';

import 'user.dart';

part 'timeline.graphql.g.dart';

@GraphQLFragment(on: "timeline")
class Timeline {
@JsonKey(name: 'id')
final String id;
@JsonKey(name: 'content')
final String name;
@JsonKey(name: 'user')
final User user;

Timeline(this.id, this.name, this.user);
}
copied to clipboard
import 'package:graphql_fragment_annotation/graphql_fragment_annotation.dart';
import 'package:json_annotation/json_annotation.dart';

part 'user.graphql.g.dart';

@GraphQLFragment(on: 'user')
class User {
@JsonKey(name: 'id')
final String id;
@JsonKey(name: 'name')
final String name;

User(this.id, this.name);
}
copied to clipboard
Building creates the corresponding part timeline.graphql.g.dart and user.graphql.g.dart:
part of 'timeline.dart';

const String timelineFragmentName = "timelineField";
final String timelineFragment = '''
fragment $timelineFragmentName on timeline {
id
content
user { ...$userFragmentName }
}
$userFragment
''';
copied to clipboard
part of 'user.dart';

const String userFragmentName = "userField";
final String userFragment = '''
fragment $userFragmentName on user {
id
name
}
''';
copied to clipboard

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.