Open BeshoyMelika opened 3 years ago
First of all - update to the latest beta) There are a lot of bug fixes)
Could you clarify the use case? Why do you need the custom class name?
I am very sorry for the late reply I want to change the names because sometimes it is too long Is there a way to custom the name of class
You can present the selection set with Fragment and you'll get a class with name [FragmentName]Mixin
it will be much shorter.
okay, I think this helps me a little, but now no way to custom class name, right?
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. Actually we didn’t wanted to make such lo$oo$ng names. But in complex query sets the chance of name duplication with different selection set is pretty high.
You can also try a simple
naming schema...
May be it will fit your needs even better.
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 :/ here is the generated class:
// ...
@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.
Every fragment will get its own mixin FragmentNameMixin
and you'll be able to use it in your class as type
@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
class Post extends GetPosts$Query$PostWithPagination$Post {}
this is the way i did. seems work?
I was thinking about using encapsulation. so:
class Post {
GetPosts$Query$PostWithPagination$Post _genPost;
String get post =>_getPost.post;
}
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 Dart 2.13 released support of type aliases. This possibly could help you in solving your issue
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:
```yaml targets: $default: sources: - $package$ - lib/$lib$ - lib/graphql/** - general.schema.graphql builders: artemis: options: fragments_glob: lib/graphql/fragments.graphql schema_mapping: - schema: general.schema.graphql queries_glob: lib/graphql/auth/*.graphql output: lib/generatedql/auth/graphql_api.dart - schema: general.schema.graphql ```Artemis output:
```bash [ +168 ms] executing: [/Users/ahmed_pc/Development/flutter/] git -c log.showSignature=false log -n 1 --pretty=format:%H [ +92 ms] Exit code 0 from: git -c log.showSignature=false log -n 1 --pretty=format:%H [ ] 8b3760638a189741cd9ca881aa2dd237c1df1be5 [ +3 ms] executing: [/Users/ahmed_pc/Development/flutter/] git tag --points-at HEAD [ +150 ms] Exit code 0 from: git tag --points-at HEAD [ ] 1.22.0-12.1.pre [ +21 ms] executing: [/Users/ahmed_pc/Development/flutter/] git rev-parse --abbrev-ref --symbolic @{u} [ +16 ms] Exit code 0 from: git rev-parse --abbrev-ref --symbolic @{u} [ ] origin/beta [ ] executing: [/Users/ahmed_pc/Development/flutter/] git ls-remote --get-url origin [ +17 ms] Exit code 0 from: git ls-remote --get-url origin [ ] https://github.com/flutter/flutter.git [ +101 ms] executing: [/Users/ahmed_pc/Development/flutter/] git rev-parse --abbrev-ref HEAD [ +53 ms] Exit code 0 from: git rev-parse --abbrev-ref HEAD [ ] beta [ +15 ms] executing: sw_vers -productName [ +72 ms] Exit code 0 from: sw_vers -productName [ ] Mac OS X [ ] executing: sw_vers -productVersion [ +22 ms] Exit code 0 from: sw_vers -productVersion [ ] 10.15.6 [ ] executing: sw_vers -buildVersion [ +25 ms] Exit code 0 from: sw_vers -buildVersion [ ] 19G2021 [ +125 ms] Artifact Instance of 'AndroidMavenArtifacts' is not required, skipping update. [ ] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update. [ ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update. [ +1 ms] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update. [ ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update. [ +5 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update. [ ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update. [ ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update. [ ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update. [ ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update. [ ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update. [ ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update. [ +8 ms] Artifact Instance of 'MaterialFonts' is not required, skipping update. [ ] Artifact Instance of 'GradleWrapper' is not required, skipping update. [ ] Artifact Instance of 'AndroidMavenArtifacts' is not required, skipping update. [ ] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update. [ ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update. [ ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update. [ ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update. [ ] Artifact Instance of 'FlutterSdk' is not required, skipping update. [ ] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update. [ ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update. [ ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update. [ ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update. [ +63 ms] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update. [ +6 ms] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update. [ ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update. [ ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update. [ ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update. [ ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update. [ ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update. [ ] Artifact Instance of 'IosUsbArtifacts' is not required, skipping update. [ ] Artifact Instance of 'FontSubsetArtifacts' is not required, skipping update. [ +98 ms] Using /Users/ahmed_pc/Development/flutter/.pub-cache for the pub cache. [ ] executing: /Users/ahmed_pc/Development/flutter/bin/cache/dart-sdk/bin/pub run build_runner build --verbose [INFO] Generating build script... [INFO] Generating build script completed, took 623ms [INFO] Creating build script snapshot...... [INFO] Creating build script snapshot... completed, took 21.2s [INFO] BuildDefinition:Initializing inputs [INFO] BuildDefinition:Building new asset graph... [INFO] BuildDefinition:Building new asset graph completed, took 844ms [INFO] BuildDefinition:Checking for unexpected pre-existing outputs.... [INFO] BuildDefinition:Checking for unexpected pre-existing outputs. completed, took 2ms [INFO] Build:Running build... [FINE] artemis:artemis on lib/$lib$:-> Input class [FINE] artemis:artemis on lib/$lib$:┌ [][ProductsOrderByOrderByClause] [FINE] artemis:artemis on lib/$lib$:| [][ProductsOrderByOrderByClause][ClassName(name:r'ProductsOrderByColumn') ClassPropertyName(name:r'field')] -> ProductsOrderByColumn [FINE] artemis:artemis on lib/$lib$:| [][ProductsOrderByOrderByClause][ClassName(name:r'SortOrder') ClassPropertyName(name:r'order')] -> SortOrder [FINE] artemis:artemis on lib/$lib$:└ [][ProductsOrderByOrderByClause] [FINE] artemis:artemis on lib/$lib$:<- Generated input class ProductsOrderByOrderByClause. [FINE] artemis:artemis on lib/$lib$:-> Enum [FINE] artemis:artemis on lib/$lib$:<- Generated enum ProductsOrderByColumn. [FINE] artemis:artemis on lib/$lib$:-> Enum [FINE] artemis:artemis on lib/$lib$:<- Generated enum SortOrder. [FINE] artemis:artemis on lib/$lib$:-> Input class [FINE] artemis:artemis on lib/$lib$:┌ [][ProductFilter] [FINE] artemis:artemis on lib/$lib$:| [][ProductFilter][ClassName(name:r'ID') ClassPropertyName(name:r'id')] -> String [FINE] artemis:artemis on lib/$lib$:| [][ProductFilter][ClassName(name:r'String') ClassPropertyName(name:r'name')] -> String [FINE] artemis:artemis on lib/$lib$:| [][ProductFilter][ClassName(name:r'String') ClassPropertyName(name:r'sku')] -> String [FINE] artemis:artemis on lib/$lib$:| [][ProductFilter][ClassName(name:r'ID') ClassPropertyName(name:r'category')] -> ListGraphQL schema:
```graphql type Mutation { login(input: LoginInput!): AuthPayload! register(input: RegisterInput!): User! } input LoginInput { email: String! password: String! device_token: String! } type AuthPayload { token_type: String expires_in: Int access_token: String refresh_token: String } ```GraphQL query:
```graphql mutation SignIn($email: String!, $password: String!,$deviceToken:String!){ login(input: {email: $email, password: $password, device_token:$deviceToken }){ access_token refresh_token expires_in token_type } } ```