graphql_schema 1.0.4 copy "graphql_schema: ^1.0.4" to clipboard
graphql_schema: ^1.0.4 copied to clipboard

An implementation of GraphQL's type system in Dart. Basis of graphql_server.

example/example.dart

import 'package:graphql_schema/graphql_schema.dart';

final GraphQLSchema todoSchema = new GraphQLSchema(
  queryType: objectType('Todo', fields: [
    field(
      'text',
      graphQLString.nonNullable(),
      resolve: resolveToNull,
    ),
    field(
      'created_at',
      graphQLDate,
      resolve: resolveToNull,
    ),
  ]),
);

main() {
  // Validation
  var validation = todoSchema.queryType.validate(
    '@root',
    {
      'foo': 'bar',
      'text': null,
      'created_at': 24,
    },
  );

  if (validation.successful) {
    print('This is valid data!!!');
  } else {
    print('Invalid data.');
    validation.errors.forEach((s) => print('  * $s'));
  }

  // Serialization
  print(todoSchema.queryType.serialize({
    'text': 'Clean your room!',
    'created_at': new DateTime.now().subtract(new Duration(days: 10))
  }));
}
0
likes
40
pub points
4%
popularity

Publisher

unverified uploader

An implementation of GraphQL's type system in Dart. Basis of graphql_server.

Repository (GitHub)
View/report issues

License

MIT (LICENSE)

Dependencies

collection, meta, source_span

More

Packages that depend on graphql_schema