From 9b9b8018d718c50d4f50b9f2094e8c744cbdce2b Mon Sep 17 00:00:00 2001 From: Tobe O Date: Fri, 3 Aug 2018 13:36:34 -0400 Subject: [PATCH] Allow deprecating fields --- graphql_schema/lib/src/field.dart | 6 ++++- graphql_server/lib/introspection.dart | 33 ++++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/graphql_schema/lib/src/field.dart b/graphql_schema/lib/src/field.dart index f369f299..54df9857 100644 --- a/graphql_schema/lib/src/field.dart +++ b/graphql_schema/lib/src/field.dart @@ -8,14 +8,18 @@ class GraphQLField { final String name; final GraphQLFieldResolver resolve; final GraphQLType type; + final String deprecationReason; GraphQLField(this.name, {Iterable arguments: const [], @required this.resolve, - this.type}) { + this.type, + this.deprecationReason}) { this.arguments.addAll(arguments ?? []); } + bool get isDeprecated => deprecationReason?.isNotEmpty == true; + FutureOr serialize(Value value) { return type.serialize(value); } diff --git a/graphql_server/lib/introspection.dart b/graphql_server/lib/introspection.dart index 6e9b19f0..5c75b665 100644 --- a/graphql_server/lib/introspection.dart +++ b/graphql_server/lib/introspection.dart @@ -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, _) => [], + ), ]); }