listType - listOf

This commit is contained in:
Tobe O 2018-08-04 21:49:13 -04:00
parent e1ce66a039
commit 9a8d1638b5
9 changed files with 22 additions and 22 deletions

View file

@ -25,7 +25,7 @@ main() async {
fields: [ fields: [
field( field(
'todos', 'todos',
listType(convertDartType(Todo).nonNullable()), listOf(convertDartType(Todo).nonNullable()),
resolve: resolveViaServiceIndex(todoService), resolve: resolveViaServiceIndex(todoService),
), ),
field( field(

View file

@ -37,19 +37,19 @@ Future configureServer(Angel app) async {
fields: [ fields: [
field( field(
'droids', 'droids',
listType(droidType.nonNullable()), listOf(droidType.nonNullable()),
description: 'All droids in the known galaxy.', description: 'All droids in the known galaxy.',
resolve: resolveViaServiceIndex(droidService), resolve: resolveViaServiceIndex(droidService),
), ),
field( field(
'humans', 'humans',
listType(humanType.nonNullable()), listOf(humanType.nonNullable()),
description: 'All humans in the known galaxy.', description: 'All humans in the known galaxy.',
resolve: resolveViaServiceIndex(humansService), resolve: resolveViaServiceIndex(humansService),
), ),
field( field(
'starships', 'starships',
listType(starshipType.nonNullable()), listOf(starshipType.nonNullable()),
description: 'All starships in the known galaxy.', description: 'All starships in the known galaxy.',
resolve: resolveViaServiceIndex(starshipService), resolve: resolveViaServiceIndex(starshipService),
), ),

View file

@ -69,7 +69,7 @@ Support for list types is also included. Use the `listType` helper for convenien
```dart ```dart
/// A non-nullable list of non-nullable integers /// A non-nullable list of non-nullable integers
listType(graphQLInt.nonNullable()).nonNullable(); listOf(graphQLInt.nonNullable()).nonNullable();
``` ```
### Input values and parameters ### Input values and parameters
@ -92,7 +92,7 @@ The field `characters` accepts a parameter, `title`. To reproduce this in
```dart ```dart
final GraphQLObjectType queryType = objectType('AnimeQuery', fields: [ final GraphQLObjectType queryType = objectType('AnimeQuery', fields: [
field('characters', field('characters',
listType(characterType.nonNullable()), listOf(characterType.nonNullable()),
inputs: [ inputs: [
new GraphQLFieldInput('title', graphQLString.nonNullable()) new GraphQLFieldInput('title', graphQLString.nonNullable())
] ]

View file

@ -20,7 +20,7 @@ abstract class GraphQLType<Value, Serialized> {
} }
/// Shorthand to create a [GraphQLListType]. /// Shorthand to create a [GraphQLListType].
GraphQLListType<Value, Serialized> listType<Value, Serialized>( GraphQLListType<Value, Serialized> listOf<Value, Serialized>(
GraphQLType<Value, Serialized> innerType) => GraphQLType<Value, Serialized> innerType) =>
new GraphQLListType<Value, Serialized>(innerType); new GraphQLListType<Value, Serialized>(innerType);

View file

@ -11,5 +11,5 @@ final GraphQLObjectType trainerType =
final GraphQLObjectType pokemonRegionType = objectType('PokemonRegion', final GraphQLObjectType pokemonRegionType = objectType('PokemonRegion',
fields: [ fields: [
field('trainer', trainerType), field('trainer', trainerType),
field('pokemon_species', listType(pokemonType)) field('pokemon_species', listOf(pokemonType))
]); ]);

View file

@ -36,11 +36,11 @@ main() {
}); });
test('list', () { test('list', () {
expect(listType(graphQLString).serialize(['foo', 'bar']), ['foo', 'bar']); expect(listOf(graphQLString).serialize(['foo', 'bar']), ['foo', 'bar']);
var today = new DateTime.now(); var today = new DateTime.now();
var tomorrow = today.add(new Duration(days: 1)); var tomorrow = today.add(new Duration(days: 1));
expect(listType(graphQLDate).serialize([today, tomorrow]), expect(listOf(graphQLDate).serialize([today, tomorrow]),
[today.toIso8601String(), tomorrow.toIso8601String()]); [today.toIso8601String(), tomorrow.toIso8601String()]);
}); });

View file

@ -22,7 +22,7 @@ GraphQLSchema reflectSchema(GraphQLSchema schema, List<GraphQLType> allTypes) {
var schemaType = objectType('__Schema', fields: [ var schemaType = objectType('__Schema', fields: [
field( field(
'types', 'types',
listType(typeType), listOf(typeType),
resolve: (_, __) => allTypeSet ??= allTypes.toSet(), resolve: (_, __) => allTypeSet ??= allTypes.toSet(),
), ),
field( field(
@ -42,7 +42,7 @@ GraphQLSchema reflectSchema(GraphQLSchema schema, List<GraphQLType> allTypes) {
), ),
field( field(
'directives', 'directives',
listType(directiveType).nonNullable(), listOf(directiveType).nonNullable(),
resolve: (_, __) => [], // TODO: Actually fetch directives resolve: (_, __) => [], // TODO: Actually fetch directives
), ),
]); ]);
@ -113,7 +113,7 @@ GraphQLObjectType _reflectSchemaTypes() {
_typeType.fields.add( _typeType.fields.add(
field( field(
'interfaces', 'interfaces',
listType(_reflectSchemaTypes().nonNullable()), listOf(_reflectSchemaTypes().nonNullable()),
resolve: (type, _) { resolve: (type, _) {
if (type is GraphQLObjectType) { if (type is GraphQLObjectType) {
return type.interfaces; return type.interfaces;
@ -127,7 +127,7 @@ GraphQLObjectType _reflectSchemaTypes() {
_typeType.fields.add( _typeType.fields.add(
field( field(
'possibleTypes', 'possibleTypes',
listType(_reflectSchemaTypes().nonNullable()), listOf(_reflectSchemaTypes().nonNullable()),
resolve: (type, _) { resolve: (type, _) {
if (type is GraphQLObjectType && type.isInterface) { if (type is GraphQLObjectType && type.isInterface) {
return type.possibleTypes; return type.possibleTypes;
@ -227,7 +227,7 @@ GraphQLObjectType _createTypeType() {
), ),
field( field(
'fields', 'fields',
listType(fieldType), listOf(fieldType),
inputs: [ inputs: [
new GraphQLFieldInput( new GraphQLFieldInput(
'includeDeprecated', 'includeDeprecated',
@ -244,7 +244,7 @@ GraphQLObjectType _createTypeType() {
), ),
field( field(
'enumValues', 'enumValues',
listType(enumValueType.nonNullable()), listOf(enumValueType.nonNullable()),
inputs: [ inputs: [
new GraphQLFieldInput( new GraphQLFieldInput(
'includeDeprecated', 'includeDeprecated',
@ -265,7 +265,7 @@ GraphQLObjectType _createTypeType() {
), ),
field( field(
'inputFields', 'inputFields',
listType(inputValueType.nonNullable()), listOf(inputValueType.nonNullable()),
resolve: (obj, _) { resolve: (obj, _) {
if (obj is GraphQLInputObjectType) { if (obj is GraphQLInputObjectType) {
return obj.inputFields; return obj.inputFields;
@ -313,7 +313,7 @@ GraphQLObjectType _createFieldType() {
), ),
field( field(
'args', 'args',
listType(inputValueType.nonNullable()).nonNullable(), listOf(inputValueType.nonNullable()).nonNullable(),
resolve: (f, _) => (f as GraphQLObjectField).inputs, resolve: (f, _) => (f as GraphQLObjectField).inputs,
), ),
]); ]);
@ -384,13 +384,13 @@ GraphQLObjectType _reflectDirectiveType() {
), ),
field( field(
'locations', 'locations',
listType(_directiveLocationType.nonNullable()).nonNullable(), listOf(_directiveLocationType.nonNullable()).nonNullable(),
// TODO: Fetch directiveLocation // TODO: Fetch directiveLocation
resolve: (obj, _) => <String>[], resolve: (obj, _) => <String>[],
), ),
field( field(
'args', 'args',
listType(inputValueType.nonNullable()).nonNullable(), listOf(inputValueType.nonNullable()).nonNullable(),
resolve: (obj, _) => [], resolve: (obj, _) => [],
), ),
]); ]);

View file

@ -55,7 +55,7 @@ GraphQLType _objectTypeFromDartType(Type type, [List<Type> typeArguments]) {
if (clazz.typeArguments.isNotEmpty) { if (clazz.typeArguments.isNotEmpty) {
var inner = convertDartType(clazz.typeArguments[0].reflectedType); var inner = convertDartType(clazz.typeArguments[0].reflectedType);
//if (inner == null) return null; //if (inner == null) return null;
return listType(inner.nonNullable()); return listOf(inner.nonNullable());
} }
throw new ArgumentError( throw new ArgumentError(

View file

@ -21,7 +21,7 @@ void main() {
queryType: objectType('api', fields: [ queryType: objectType('api', fields: [
field( field(
'todos', 'todos',
listType(todoType), listOf(todoType),
resolve: (_, __) => [ resolve: (_, __) => [
new Todo( new Todo(
text: 'Clean your room!', text: 'Clean your room!',