leto_generator 0.0.1-dev.4 copy "leto_generator: ^0.0.1-dev.4" to clipboard
leto_generator: ^0.0.1-dev.4 copied to clipboard

Generates GraphQL schemas from Dart classes, for use with package:leto_schema.

example/lib/main.dart

import 'package:leto_generator_example/decimal.dart';
import 'package:leto_generator_example/graphql_api.schema.dart';
import 'package:leto_generator_example/inputs.dart';
import 'package:leto_schema/leto_schema.dart';

part 'main.g.dart';

@GraphQLInput()
class TodoItemInput {
  const TodoItemInput({
    required this.text,
    this.nested,
  });

  final String text;
  final TodoItemInputNested? nested;

  factory TodoItemInput.fromJson(Map<String, Object?> json) => TodoItemInput(
        text: json['text']! as String,
        nested: json['nested'] == null
            ? null
            : TodoItemInputNested.fromJson(
                json['nested']! as Map<String, Object?>,
              ),
      );
}

@GraphQLInput()
class TodoItemInputNested {
  const TodoItemInputNested({required this.cost});

  final Decimal? cost;

  // ignore: prefer_constructors_over_static_methods
  static TodoItemInputNested fromJson(Map<String, Object?> json) =>
      TodoItemInputNested(
        cost: json['cost'] == null
            ? null
            : Decimal.parse(json['cost'].toString()),
      );
}

@GraphQLObject()
class TodoItem {
  /// A description of the todo item
  String? text;

  @GraphQLDocumentation(description: 'Whether this item is complete.')
  bool? isComplete;

  @Deprecated("Don't use this")
  DateTime createdAt;

  Decimal? cost;

  TodoItem({
    this.text,
    this.isComplete,
    // ignore: deprecated_consistency
    required this.createdAt,
  });
}

@Query()
String getName() {
  return '';
}

Future<void> main() async {
  print(graphqlApiSchema.schemaStr);

  InputGen<int> d = graphqlApiSchema.serdeCtx.fromJson({
    'name': 'nn',
    'generic': 1,
  });
  print(d.toJson());
}

// TODO: 1A delete this
const ss = '''
type Query {
  testInputGen(v: InputGenIntReq!): Int!
  getNestedInterfaceImpl3: NestedInterfaceImpl3!
  getName: String!
}

input InputGenIntReq {
  name: String!
  generic: Int!
}

type NestedInterfaceImpl3 {
  name3: String!
}

type Mutation {
  getInt: ResultIntReqString!
  getIntReq: ResultIntReqStringReq!
  getIntNull: ResultIntString!
  getIntInterface: ResultIntErrCodeInterfaceStringReqReq!
  getIntInterfaceEnum: ResultIntReqErrCodeInterfaceErrCodeTypeReqReq!
  getIntInterfaceEnumList: ResultIntListReqErrCodeInterfaceErrCodeTypeReqListReqReq!
  getIntInterfaceNEnumNull: ResultIntReqErrCodeInterfaceNErrCodeTypeReq!
}

"""
Int! when the operation was successful or String when an error was encountered.
"""
type ResultIntReqString {
  ok: Int
  err: String
  isOk: Boolean!
}

"""
Int! when the operation was successful or String! when an error was encountered.
"""
type ResultIntReqStringReq {
  ok: Int
  err: String
  isOk: Boolean!
}

"""
Int when the operation was successful or String when an error was encountered.
"""
type ResultIntString {
  ok: Int
  err: String
  isOk: Boolean!
}

"""
Int when the operation was successful or ErrCodeInterfaceStringReq! when an error was encountered.
"""
type ResultIntErrCodeInterfaceStringReqReq {
  ok: Int
  err: ErrCodeInterfaceStringReq
  isOk: Boolean!
}

type ErrCodeInterfaceStringReq {
  message: String
  code: String!
}

"""
Int! when the operation was successful or ErrCodeInterfaceErrCodeTypeReq! when an error was encountered.
"""
type ResultIntReqErrCodeInterfaceErrCodeTypeReqReq {
  ok: Int
  err: ErrCodeInterfaceErrCodeTypeReq
  isOk: Boolean!
}

type ErrCodeInterfaceErrCodeTypeReq {
  message: String
  code: ErrCodeType!
}

enum ErrCodeType {
  code1
  code2
}

"""
[Int]! when the operation was successful or ErrCodeInterfaceErrCodeTypeReqListReq! when an error was encountered.
"""
type ResultIntListReqErrCodeInterfaceErrCodeTypeReqListReqReq {
  ok: [Int]
  err: ErrCodeInterfaceErrCodeTypeReqListReq
  isOk: Boolean!
}

type ErrCodeInterfaceErrCodeTypeReqListReq {
  message: String
  code: [ErrCodeType!]!
}

"""
Int! when the operation was successful or ErrCodeInterfaceNErrCodeType! when an error was encountered.
"""
type ResultIntReqErrCodeInterfaceNErrCodeTypeReq {
  ok: Int
  err: ErrCodeInterfaceNErrCodeType
  isOk: Boolean!
}

type ErrCodeInterfaceNErrCodeType {
  message: String
  code: ErrCodeType!
}

type Subscription
''';
0
likes
140
pub points
40%
popularity

Publisher

unverified uploader

Generates GraphQL schemas from Dart classes, for use with package:leto_schema.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

analyzer, build, build_config, code_builder, collection, dart_style, freezed_annotation, glob, json_annotation, leto_schema, path, recase, source_gen, valida

More

Packages that depend on leto_generator