fieldFromGetter function

  1. @deprecated
GraphQLObjectField fieldFromGetter (Symbol name, MethodMirror mirror, Exclude exclude, ClassMirror clazz)

Implementation

@deprecated
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;
      }
    },
  );
}