2018-08-02 13:31:54 +00:00
part of graphql_schema . src . schema ;
2018-08-04 19:18:53 +00:00
class GraphQLFieldInput < Value , Serialized > {
2018-08-02 13:31:54 +00:00
final String name ;
final GraphQLType < Value , Serialized > type ;
final Value defaultValue ;
2018-08-03 17:45:40 +00:00
final String description ;
2018-08-02 13:50:31 +00:00
2018-08-04 19:18:53 +00:00
/// If [defaultValue] is `null`, and `null` is a valid value for this parameter, set this to `true`.
2018-08-02 13:50:31 +00:00
final bool defaultsToNull ;
2018-08-04 19:18:53 +00:00
static bool _isInputTypeOrScalar ( GraphQLType type ) {
if ( type is GraphQLInputObjectType ) {
return true ;
} else if ( type is GraphQLUnionType ) {
return type . possibleTypes . every ( _isInputTypeOrScalar ) ;
} else if ( type is GraphQLObjectType ) {
return false ;
} else if ( type is GraphQLNonNullableType ) {
return _isInputTypeOrScalar ( type . ofType ) ;
} else if ( type is GraphQLListType ) {
return _isInputTypeOrScalar ( type . ofType ) ;
} else {
return true ;
}
}
GraphQLFieldInput ( this . name , this . type ,
{ this . defaultValue , this . defaultsToNull: false , this . description } ) {
assert ( _isInputTypeOrScalar ( type ) ,
' All inputs to a GraphQL field must either be scalar types, or explicitly marked as INPUT_OBJECT. Call `GraphQLObjectType.asInputObject()` on any object types you are passing as inputs to a field. ' ) ;
}
@ override
bool operator = = ( other ) = >
other is GraphQLFieldInput & &
other . name = = name & &
other . type = = type & &
other . defaultValue = = other . defaultValue & &
other . defaultsToNull = = defaultsToNull & &
other . description = = description ;
2018-08-02 13:31:54 +00:00
}