expression method

Expression expression({
  1. bool isInput = false,
})

Implementation

Expression expression({bool isInput = false}) {
  final _type = gqlType;
  return _type.property(isInput ? 'inputField' : 'field').call(
    [
      literalString(name),
    ],
    {
      if (!isInput)
        'resolve': Method(
          (m) => m
            ..requiredParameters.addAll([
              Parameter((p) => p..name = 'obj'),
              Parameter((p) => p..name = 'ctx'),
            ])
            ..body = Code(isMethod ? getter : 'obj.$getter')
            ..lambda = !isMethod,
        ).genericClosure,
      if (!isInput && inputs.isNotEmpty)
        'inputs': literalList(inputs.map(refer)),
      if (isInput && defaultValueCode != null)
        'defaultValue': refer(defaultValueCode!),
      if (description != null && description!.isNotEmpty)
        'description': refer("'${description!}'"),
      if (deprecationReason != null)
        'deprecationReason': literalString(deprecationReason!),
      if (attachments != null) 'attachments': refer(attachments!)
    },
  );
}