-
-
Notifications
You must be signed in to change notification settings - Fork 119
custom class name #214
Comments
First of all - update to the latest beta) |
Could you clarify the use case? |
I am very sorry for the late reply |
You can present the selection set with Fragment and you'll get a class with name |
okay, I think this helps me a little, |
Currently there is no way to customize class name. The “fragmentation” is the only way. As far as it ads only “Mixin” postfix overhead it works pretty good. |
You can also try a |
Hey @vasilich6107, I want to change the name of the class so I can set it as a type that my widget accepts but it's too long, not very readable, and too specific. I wanted to handle it myself by creating another general class that includes only the fields that I care about but dart apparently doesn't work the same as typescript :/ // ...
@JsonSerializable(explicitToJson: true)
class Home$Query$LatestProducts$Product with EquatableMixin {
Home$Query$LatestProducts$Product();
factory Home$Query$LatestProducts$Product.fromJson(
Map<String, dynamic> json) =>
_$Home$Query$LatestProducts$ProductFromJson(json);
String id;
String name;
double price;
String image;
Home$Query$LatestProducts$Product$Author author;
List<Home$Query$LatestProducts$Product$Category> categories;
@override
List<Object> get props => [id, name, price, image, author, categories];
Map<String, dynamic> toJson() =>
_$Home$Query$LatestProducts$ProductToJson(this);
}
// ... and there are many duplicates of this exact class in the generated code: // ...
@JsonSerializable(explicitToJson: true)
class Home$Query$PaginatedCategoryResponse$Category$PaginatedProductResponse$Product
with EquatableMixin {
Home$Query$PaginatedCategoryResponse$Category$PaginatedProductResponse$Product();
factory Home$Query$PaginatedCategoryResponse$Category$PaginatedProductResponse$Product.fromJson(
Map<String, dynamic> json) =>
_$Home$Query$PaginatedCategoryResponse$Category$PaginatedProductResponse$ProductFromJson(
json);
String id;
String name;
double price;
String image;
Home$Query$PaginatedCategoryResponse$Category$PaginatedProductResponse$Product$Author
author;
List<Home$Query$PaginatedCategoryResponse$Category$PaginatedProductResponse$Product$Category>
categories;
@override
List<Object> get props => [id, name, price, image, author, categories];
Map<String, dynamic> toJson() =>
_$Home$Query$PaginatedCategoryResponse$Category$PaginatedProductResponse$ProductToJson(
this);
}
// ... And all I want is to accept a simple list of products in my widget like so: // ...
class ProductsRow extends StatelessWidget {
const ProductsRow({Key key, @required this.title, @required this.items})
: assert(title != null && items != null),
super(key: key);
final String title;
final List<Product> items;
@override
Widget build(BuildContext context) {
return Column(
children: [
Text(title),
ListView.builder(
itemCount: items.length,
itemBuilder: (context, index) {
return Text(items[index].name);
},
),
],
);
}
} So I created this general-purpose abstract class with just the fields that I care about abstract class Product {
String id;
String name;
} but the issue is that this doesn't work as I get a type mismatch even though they're the same fields that are contained in the previous classes and i think its just how the language works but it would be great to change the generated class name or even extend some other class or something. |
@msal4 split your query into fragments. |
@msal4 you must have solved this already, but you could also create a Product wrapper which forwards get / set calls to the generated classes. But honestly that & the Fragment ideas seem unnatural. I like the idea of custom class types. That the artemis framework knows how to map into / out of. |
@formvoltron i agree with your opinion. can i get some example for wrapping generated classes? thanks |
@formvoltron I split my query into fragments as @vasilich6107 suggested they worked pretty well but I'm curious about your idea it would be nice if you shared a code snippet or a link to get an idea of how it would be implemented |
this is the way i did. seems work? |
I was thinking about using encapsulation. so:
Like that... but that gets pretty boring writing those & so maybe this class could even be generated. I'm going to skip all of this & just use json_serializable on my model classes & write some code to generate them based on responses from the server code. |
@formvoltron @OdysseyJ @BeshoyMelika |
Bug description
i have class with this name SignIn$Mutation$AuthPayload i need to custom this name
can I custom classes name
Specs
Artemis version: [e.g. 6.0.3-beta.1]
build.yaml:
Artemis output:
GraphQL schema:
GraphQL query:
The text was updated successfully, but these errors were encountered: