Allow deprecating fields

This commit is contained in:
Tobe O 2018-08-03 13:36:34 -04:00
parent 01ad2d26bf
commit 9b9b8018d7
2 changed files with 37 additions and 2 deletions

View file

@ -8,14 +8,18 @@ class GraphQLField<Value, Serialized> {
final String name;
final GraphQLFieldResolver<Value, Serialized> resolve;
final GraphQLType<Value, Serialized> type;
final String deprecationReason;
GraphQLField(this.name,
{Iterable<GraphQLFieldArgument> arguments: const <GraphQLFieldArgument>[],
@required this.resolve,
this.type}) {
this.type,
this.deprecationReason}) {
this.arguments.addAll(arguments ?? <GraphQLFieldArgument>[]);
}
bool get isDeprecated => deprecationReason?.isNotEmpty == true;
FutureOr<Serialized> serialize(Value value) {
return type.serialize(value);
}

View file

@ -161,16 +161,47 @@ GraphQLObjectType _createFieldType() {
type: graphQLString,
resolve: (f, _) => (f as GraphQLField).name,
),
field(
'isDeprecated',
type: graphQLString,
resolve: (f, _) => (f as GraphQLField).isDeprecated,
),
field(
'deprecationReason',
type: graphQLString,
resolve: (f, _) => (f as GraphQLField).deprecationReason,
),
field(
'args',
type: listType(graphQLString.nonNullable()).nonNullable(), // TODO: Input value type
resolve: (f, _) => (f as GraphQLField).arguments,
),
]);
}
GraphQLObjectType _reflectDirectiveType() {
// TODO: What actually is this???
return objectType('__Directive', fields: [
field(
'name',
type: graphQLString,
type: graphQLString.nonNullable(),
resolve: (obj, _) => (obj as DirectiveContext).NAME.span.text,
),
field(
'description',
type: graphQLString,
resolve: (obj, _) => null,
),
field(
'locations',
type: listType(graphQLString.nonNullable()).nonNullable(), // TODO: Enum directiveLocation
resolve: (obj, _) => [],
),
field(
'args',
type: listType(graphQLString.nonNullable()).nonNullable(),
resolve: (obj, _) => [],
),
]);
}