platform/packages/graphql/graphql_generator/README.md

53 lines
1.5 KiB
Markdown
Raw Normal View History

2019-04-16 15:15:24 +00:00
# graphql_generator
2019-04-18 15:23:12 +00:00
[![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)
2019-04-16 15:15:24 +00:00
Generates `package:graphql_schema` schemas for
annotated class.
2019-04-18 15:23:12 +00:00
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
2020-04-05 10:39:49 +00:00
@GraphQLDocumentation(description: 'Todo object type')
2019-04-18 15:23:12 +00:00
class Todo {
String text;
2020-04-05 10:39:49 +00:00
/// Whether this item is complete
2019-04-18 15:23:12 +00:00
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,
2020-04-05 10:39:49 +00:00
description: 'Todo object type',
2019-04-18 15:23:12 +00:00
interfaces: [],
fields: [
field('text', graphQLString),
2020-04-05 10:39:49 +00:00
field('isComplete', graphQLBoolean, description: 'Whether this item is complete')
2019-04-18 15:23:12 +00:00
]);
2020-04-05 10:39:49 +00:00
```