platform/graphql_schema
2018-08-03 18:01:36 -04:00
..
example Type introspection base 2018-08-02 15:22:16 -04:00
lib Added enum type 2018-08-03 18:01:36 -04:00
test Added basic validation tests to graphql_schema 2018-08-03 17:25:16 -04:00
.gitignore Restructure 2018-08-02 08:48:53 -04:00
analysis_options.yaml Fix type errors in tests 2018-08-02 09:05:52 -04:00
graphql_schema.iml Pull in graphql_schema 2018-08-02 09:31:54 -04:00
LICENSE Restructure 2018-08-02 08:48:53 -04:00
pubspec.yaml Spec-compliant error messages 2018-08-03 17:07:08 -04:00
README.md Pull in graphql_schema 2018-08-02 09:31:54 -04:00

graphql_schema

Pub

An implementation of GraphQL's type system in Dart. Supports any platform where Dart runs.

Usage

It's easy to define a schema with the helper functions:

final GraphQLSchema todoSchema = new GraphQLSchema(
    query: objectType('Todo', [
  field('text', type: graphQLString.nonNullable()),
  field('created_at', type: graphQLDate)
]));

All GraphQL types are generic, in order to leverage Dart's strong typing support.

Serialization

GraphQL types can serialize and deserialize input data. The exact implementation of this depends on the type.

var iso8601String = graphQLDate.serialize(new DateTime.now());
var date = graphQLDate.deserialize(iso8601String);
print(date.millisecondsSinceEpoch);

Validation

GraphQL types can validate input data.

var validation = myType.validate('@root', {...});

if (validation.successful) {
  doSomething(validation.value);
} else {
  print(validation.errors);
}

Helpers

  • graphQLSchema - Create a GraphQLSchema
  • objectType - Create a GraphQLObjectType with fields
  • field - Create a GraphQLField with a type/argument/resolver
  • listType - Create a GraphQLListType with the provided innerType

Types

All of the GraphQL scalar types are built in, as well as a Date type:

  • graphQLString
  • graphQLId
  • graphQLBoolean
  • graphQLInt
  • graphQLFloat
  • graphQLDate

Non-Nullable Types

You can easily make a type non-nullable by calling its nonNullable method.

List Types

Support for list types is also included. Use the listType helper for convenience.

/// A non-nullable list of non-nullable integers
listType(graphQLInt.nonNullable()).nonNullable();