graphql_schema 1.0.0-beta

  • README.md
  • Installing
  • Versions
  • 39

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();

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  graphql_schema: "^1.0.0-beta"

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:graphql_schema/graphql_schema.dart';
        
Version Uploaded Documentation Archive
1.0.0-beta Jul 19, 2017 Go to the documentation of graphql_schema 1.0.0-beta Download graphql_schema 1.0.0-beta archive

Analysis

We analyzed this package on Apr 23, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.49.0
  • pana: 0.10.6

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
18 / 100
Health:
Code health derived from static analysis. [more]
55 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
66 / 100
Overall score:
Weighted score of the above. [more]
39
Learn more about scoring.

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:graphql_schema/graphql_schema.dart.

Suggestions

  • Maintain CHANGELOG.md.

    Changelog entries help clients to follow the progress in your code.

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 25 errors 3 hints.

    Strong-mode analysis of lib/src/object_type.dart failed with the following error:

    line: 12 col: 3
    Invalid override. The type of 'GraphQLObjectType.validate' ('(String, Map<dynamic, dynamic>) → ValidationResult<Map<dynamic, dynamic>>') isn't a subtype of 'GraphQLType<Map<String, dynamic>, Map<String, dynamic>>.validate' ('(String, Map<String, dynamic>) → ValidationResult<Map<String, dynamic>>').

    Strong-mode analysis of lib/src/scalar.dart failed with the following error:

    line: 27 col: 1
    The class 'GraphQLScalarType' cannot implement both 'GraphQLType<Value, Serialized>' and 'GraphQLType<dynamic, dynamic>' because the type arguments are different.

    Similar analysis of the following files failed:

    • lib/src/schema.dart (error)
    • lib/graphql_schema.dart (hint)
    • lib/src/validation_result.dart (hint)
  • Package is pre-release.

    Pre-release versions should be used with caution, their API may change in breaking ways.

  • The description is too short.

    Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

  • Maintain an example.

    None of the files in your example/ directory matches a known example patterns. Common file name patterns include: main.dart, example.dart or you could also use graphql_schema.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.19.0
graphql_parser ^1.0.0 1.0.0+1
Transitive dependencies
charcode 1.1.1
path 1.5.1
source_span 1.4.0
string_scanner 1.0.2
Dev dependencies
test ^0.12.0