artemis_custom_gen

Last updated:

0 purchases

artemis_custom_gen Image
artemis_custom_gen Images
Add to Cart

Description:

artemis custom gen

artemis_custom_gen #
artemis_custom_gen is a custom types generator for artemis GraphQL package.

Getting started
Usage
Roadmap

Getting started #
To use the package, simply add the following to your pubspec.yaml:
dependencies:
artemis_custom_gen:

dev_dependencies:
build_runner:
copied to clipboard
Or to depend on the latest main:
dependencies:
artemis_custom_gen:
git: https://github.com/lapuske/artemis_custom_gen.git

dev_dependencies:
build_runner:
copied to clipboard
Usage #
Detailed example can be found in /example directory.

Annotate the custom type with @ArtemisCustomType() annotation:

@ArtemisCustomType()
class MyCustomType {
// ...
}
copied to clipboard
By default, artemis_custom_gen uses the Dart class name (MyCustomType in the example above) as a GraphQL scalar name. If the GraphQL scalar name differs from your Dart class name, you should specify the graphQlType parameter in ArtemisCustomType annotation:
@ArtemisCustomType(graphQlType: 'MyGraphQlScalar')
class MyCustomType {
// ...
}
copied to clipboard
Note, that for parsing from String your custom type must have a single String argument constructor. E.g.:
@ArtemisCustomType(graphQlType: 'MyGraphQlScalar')
class MyCustomType {
const MyCustomType(this.value); // `this.value` is a `String`.
final String value;
}
copied to clipboard
class Parent {
const Parent(this.value);
final String value;
}

@ArtemisCustomType(graphQlType: 'MyGraphQlScalar')
class MyCustomType extends Parent {
const MyCustomType(super.value); // `super.value` is a `String`.
}
copied to clipboard
@ArtemisCustomType(graphQlType: 'MyGraphQlScalar')
class MyCustomType {
const MyCustomType(this.value);

// Naming doesn't matter.
const MyCustomType.parse(String string) : value = double.parse(string);

final double value;
}
copied to clipboard
And for parsing to String currently artemis_custom_gen uses toString() on your custom type.

(Optionally) Configure the output path (default is lib/api/parsers.g.dart).

In your build.yaml:
targets:
$default:
builders:
artemis_custom_gen:
options:
output: api/backend/parsers.dart # Without `lib/`.
copied to clipboard

Run the build_runner:

dart run build_runner build
copied to clipboard

Add the generated type to the artemis options in build.yaml (see artemis documentation to learn more):

targets:
$default:
builders:
artemis:
options:
scalar_mapping:
- graphql_type: MyGraphQlScalar
custom_parser_import: "package:your_package/path_to_parsed_file.dart"
dart_type:
name: MyCustomType
imports:
- "package:your_package/path_to_your_model/my_custom_type.dart"
copied to clipboard
Roadmap #

❌ Configurable to String and from String parsers on ArtemisCustomType.

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.