listType - listOf
This commit is contained in:
parent
e1ce66a039
commit
9a8d1638b5
9 changed files with 22 additions and 22 deletions
|
@ -25,7 +25,7 @@ main() async {
|
|||
fields: [
|
||||
field(
|
||||
'todos',
|
||||
listType(convertDartType(Todo).nonNullable()),
|
||||
listOf(convertDartType(Todo).nonNullable()),
|
||||
resolve: resolveViaServiceIndex(todoService),
|
||||
),
|
||||
field(
|
||||
|
|
|
@ -37,19 +37,19 @@ Future configureServer(Angel app) async {
|
|||
fields: [
|
||||
field(
|
||||
'droids',
|
||||
listType(droidType.nonNullable()),
|
||||
listOf(droidType.nonNullable()),
|
||||
description: 'All droids in the known galaxy.',
|
||||
resolve: resolveViaServiceIndex(droidService),
|
||||
),
|
||||
field(
|
||||
'humans',
|
||||
listType(humanType.nonNullable()),
|
||||
listOf(humanType.nonNullable()),
|
||||
description: 'All humans in the known galaxy.',
|
||||
resolve: resolveViaServiceIndex(humansService),
|
||||
),
|
||||
field(
|
||||
'starships',
|
||||
listType(starshipType.nonNullable()),
|
||||
listOf(starshipType.nonNullable()),
|
||||
description: 'All starships in the known galaxy.',
|
||||
resolve: resolveViaServiceIndex(starshipService),
|
||||
),
|
||||
|
|
|
@ -69,7 +69,7 @@ Support for list types is also included. Use the `listType` helper for convenien
|
|||
|
||||
```dart
|
||||
/// A non-nullable list of non-nullable integers
|
||||
listType(graphQLInt.nonNullable()).nonNullable();
|
||||
listOf(graphQLInt.nonNullable()).nonNullable();
|
||||
```
|
||||
|
||||
### Input values and parameters
|
||||
|
@ -92,7 +92,7 @@ The field `characters` accepts a parameter, `title`. To reproduce this in
|
|||
```dart
|
||||
final GraphQLObjectType queryType = objectType('AnimeQuery', fields: [
|
||||
field('characters',
|
||||
listType(characterType.nonNullable()),
|
||||
listOf(characterType.nonNullable()),
|
||||
inputs: [
|
||||
new GraphQLFieldInput('title', graphQLString.nonNullable())
|
||||
]
|
||||
|
|
|
@ -20,7 +20,7 @@ abstract class GraphQLType<Value, Serialized> {
|
|||
}
|
||||
|
||||
/// Shorthand to create a [GraphQLListType].
|
||||
GraphQLListType<Value, Serialized> listType<Value, Serialized>(
|
||||
GraphQLListType<Value, Serialized> listOf<Value, Serialized>(
|
||||
GraphQLType<Value, Serialized> innerType) =>
|
||||
new GraphQLListType<Value, Serialized>(innerType);
|
||||
|
||||
|
|
|
@ -11,5 +11,5 @@ final GraphQLObjectType trainerType =
|
|||
final GraphQLObjectType pokemonRegionType = objectType('PokemonRegion',
|
||||
fields: [
|
||||
field('trainer', trainerType),
|
||||
field('pokemon_species', listType(pokemonType))
|
||||
field('pokemon_species', listOf(pokemonType))
|
||||
]);
|
||||
|
|
|
@ -36,11 +36,11 @@ main() {
|
|||
});
|
||||
|
||||
test('list', () {
|
||||
expect(listType(graphQLString).serialize(['foo', 'bar']), ['foo', 'bar']);
|
||||
expect(listOf(graphQLString).serialize(['foo', 'bar']), ['foo', 'bar']);
|
||||
|
||||
var today = new DateTime.now();
|
||||
var tomorrow = today.add(new Duration(days: 1));
|
||||
expect(listType(graphQLDate).serialize([today, tomorrow]),
|
||||
expect(listOf(graphQLDate).serialize([today, tomorrow]),
|
||||
[today.toIso8601String(), tomorrow.toIso8601String()]);
|
||||
});
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ GraphQLSchema reflectSchema(GraphQLSchema schema, List<GraphQLType> allTypes) {
|
|||
var schemaType = objectType('__Schema', fields: [
|
||||
field(
|
||||
'types',
|
||||
listType(typeType),
|
||||
listOf(typeType),
|
||||
resolve: (_, __) => allTypeSet ??= allTypes.toSet(),
|
||||
),
|
||||
field(
|
||||
|
@ -42,7 +42,7 @@ GraphQLSchema reflectSchema(GraphQLSchema schema, List<GraphQLType> allTypes) {
|
|||
),
|
||||
field(
|
||||
'directives',
|
||||
listType(directiveType).nonNullable(),
|
||||
listOf(directiveType).nonNullable(),
|
||||
resolve: (_, __) => [], // TODO: Actually fetch directives
|
||||
),
|
||||
]);
|
||||
|
@ -113,7 +113,7 @@ GraphQLObjectType _reflectSchemaTypes() {
|
|||
_typeType.fields.add(
|
||||
field(
|
||||
'interfaces',
|
||||
listType(_reflectSchemaTypes().nonNullable()),
|
||||
listOf(_reflectSchemaTypes().nonNullable()),
|
||||
resolve: (type, _) {
|
||||
if (type is GraphQLObjectType) {
|
||||
return type.interfaces;
|
||||
|
@ -127,7 +127,7 @@ GraphQLObjectType _reflectSchemaTypes() {
|
|||
_typeType.fields.add(
|
||||
field(
|
||||
'possibleTypes',
|
||||
listType(_reflectSchemaTypes().nonNullable()),
|
||||
listOf(_reflectSchemaTypes().nonNullable()),
|
||||
resolve: (type, _) {
|
||||
if (type is GraphQLObjectType && type.isInterface) {
|
||||
return type.possibleTypes;
|
||||
|
@ -227,7 +227,7 @@ GraphQLObjectType _createTypeType() {
|
|||
),
|
||||
field(
|
||||
'fields',
|
||||
listType(fieldType),
|
||||
listOf(fieldType),
|
||||
inputs: [
|
||||
new GraphQLFieldInput(
|
||||
'includeDeprecated',
|
||||
|
@ -244,7 +244,7 @@ GraphQLObjectType _createTypeType() {
|
|||
),
|
||||
field(
|
||||
'enumValues',
|
||||
listType(enumValueType.nonNullable()),
|
||||
listOf(enumValueType.nonNullable()),
|
||||
inputs: [
|
||||
new GraphQLFieldInput(
|
||||
'includeDeprecated',
|
||||
|
@ -265,7 +265,7 @@ GraphQLObjectType _createTypeType() {
|
|||
),
|
||||
field(
|
||||
'inputFields',
|
||||
listType(inputValueType.nonNullable()),
|
||||
listOf(inputValueType.nonNullable()),
|
||||
resolve: (obj, _) {
|
||||
if (obj is GraphQLInputObjectType) {
|
||||
return obj.inputFields;
|
||||
|
@ -313,7 +313,7 @@ GraphQLObjectType _createFieldType() {
|
|||
),
|
||||
field(
|
||||
'args',
|
||||
listType(inputValueType.nonNullable()).nonNullable(),
|
||||
listOf(inputValueType.nonNullable()).nonNullable(),
|
||||
resolve: (f, _) => (f as GraphQLObjectField).inputs,
|
||||
),
|
||||
]);
|
||||
|
@ -384,13 +384,13 @@ GraphQLObjectType _reflectDirectiveType() {
|
|||
),
|
||||
field(
|
||||
'locations',
|
||||
listType(_directiveLocationType.nonNullable()).nonNullable(),
|
||||
listOf(_directiveLocationType.nonNullable()).nonNullable(),
|
||||
// TODO: Fetch directiveLocation
|
||||
resolve: (obj, _) => <String>[],
|
||||
),
|
||||
field(
|
||||
'args',
|
||||
listType(inputValueType.nonNullable()).nonNullable(),
|
||||
listOf(inputValueType.nonNullable()).nonNullable(),
|
||||
resolve: (obj, _) => [],
|
||||
),
|
||||
]);
|
||||
|
|
|
@ -55,7 +55,7 @@ GraphQLType _objectTypeFromDartType(Type type, [List<Type> typeArguments]) {
|
|||
if (clazz.typeArguments.isNotEmpty) {
|
||||
var inner = convertDartType(clazz.typeArguments[0].reflectedType);
|
||||
//if (inner == null) return null;
|
||||
return listType(inner.nonNullable());
|
||||
return listOf(inner.nonNullable());
|
||||
}
|
||||
|
||||
throw new ArgumentError(
|
||||
|
|
|
@ -21,7 +21,7 @@ void main() {
|
|||
queryType: objectType('api', fields: [
|
||||
field(
|
||||
'todos',
|
||||
listType(todoType),
|
||||
listOf(todoType),
|
||||
resolve: (_, __) => [
|
||||
new Todo(
|
||||
text: 'Clean your room!',
|
||||
|
|
Loading…
Reference in a new issue