fieldFromGetter function

  1. @Deprecated('No replacement yet')
GraphQLObjectField fieldFromGetter(
  1. Symbol name,
  2. MethodMirror mirror,
  3. Exclude? exclude,
  4. ClassMirror clazz,
)

Implementation

@Deprecated('No replacement yet')
GraphQLObjectField fieldFromGetter(
    Symbol name, MethodMirror mirror, Exclude? exclude, ClassMirror clazz) {
  var type = _getProvidedType(mirror.metadata);
  var wasProvided = type != null;

  if (!wasProvided) {
    var returnType = mirror.returnType;

    if (!clazz.isAssignableTo(returnType)) {
      type = convertDartType(returnType.reflectedType,
          mirror.returnType.typeArguments.map((t) => t.reflectedType).toList());
    }
  }

  var nameString = _getSerializedName(name, mirror, clazz)!;
  var defaultValue = _getDefaultValue(mirror);

  if (!wasProvided && (nameString == 'id' && _autoNames(clazz))) {
    type = graphQLId;
  }

  return field(
    nameString,
    type!,
    deprecationReason: _getDeprecationReason(mirror.metadata),
    resolve: (obj, _) {
      if (obj is Map && exclude?.canSerialize != true) {
        return obj[nameString];
      } else if (obj != null && exclude?.canSerialize != true) {
        return reflect(obj).getField(name);
      } else {
        return defaultValue;
      }
    },
  );
}