platform/packages/graphql/graphql_generator/README.md
Tobe O 4e69153e3e Add 'packages/graphql/' from commit '33e2f86ba73d559197b6270df036256104726aca'
git-subtree-dir: packages/graphql
git-subtree-mainline: ac29392d7f
git-subtree-split: 33e2f86ba7
2020-02-15 18:22:07 -05:00

50 lines
No EOL
1.4 KiB
Markdown

# graphql_generator
[![Pub](https://img.shields.io/pub/v/graphql_generator.svg)](https://pub.dartlang.org/packages/graphql_generator)
[![build status](https://travis-ci.org/angel-dart/graphql.svg)](https://travis-ci.org/angel-dart/graphql)
Generates `package:graphql_schema` schemas for
annotated class.
Replaces `convertDartType` from `package:graphql_server`.
## Usage
Usage is very simple. You just need a `@graphQLClass` or `@GraphQLClass()` annotation
on any class you want to generate an object type for.
Individual fields can have a `@GraphQLDocumentation()` annotation, to provide information
like descriptions, deprecation reasons, etc.
```dart
@graphQLClass
class Todo {
String text;
@GraphQLDocumentation(description: 'Whether this item is complete.')
bool isComplete;
}
void main() {
print(todoGraphQLType.fields.map((f) => f.name));
}
```
The following is generated (as of April 18th, 2019):
```dart
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'main.dart';
// **************************************************************************
// _GraphQLGenerator
// **************************************************************************
/// Auto-generated from [Todo].
final GraphQLObjectType todoGraphQLType = objectType('Todo',
isInterface: false,
interfaces: [],
fields: [
field('text', graphQLString),
field('isComplete', graphQLBoolean)
]);
```