argInfoFromElement function

GraphQLArg argInfoFromElement(
  1. Element element
)

Implementation

GraphQLArg argInfoFromElement(Element element) {
  final argAnnot =
      const TypeChecker.fromRuntime(GraphQLArg).firstAnnotationOfExact(element);
  final defaultFunc = argAnnot?.getField('defaultFunc')?.toFunctionValue();
  final defaultCode = argAnnot?.getField('defaultCode')?.toStringValue();
  if (defaultFunc != null && defaultCode != null) {
    throw Exception(
      "Can't specify both defaultFunc: $defaultFunc and"
      ' defaultCode: $defaultCode in decorator GraphQLArg'
      ' for ${element.name}.',
    );
  }
  final String? _defaultFunc =
      defaultFunc != null ? executeCodeForExecutable(defaultFunc) : null;

  final argInfo = GraphQLArg(
    inline: argAnnot?.getField('inline')?.toBoolValue(),
    defaultCode: defaultCode ?? _defaultFunc,
    defaultFunc: null,
  );
  return argInfo;
}