.. | ||
example | ||
lib | ||
test | ||
.gitignore | ||
analysis_options.yaml | ||
graphql_schema.iml | ||
LICENSE | ||
pubspec.yaml | ||
README.md |
graphql_schema
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 aGraphQLSchema
objectType
- Create aGraphQLObjectType
with fieldsfield
- Create aGraphQLField
with a type/argument/resolverlistType
- Create aGraphQLListType
with the providedinnerType
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();