name ?? Str::camel($this->column); } /** * Get the column of the field. * * @return string */ public function getColumn(): string { return $this->column; } /** * The description of the field. * * @return string */ public function description(): string { return ''; } /** * The type returned by the field. * * @return Type */ public function getType(): Type { if (!$this->nullable) { return Type::nonNull($this->type()); } return $this->type(); } /** * The type returned by the field. * * @return Type */ abstract protected function type(): Type; /** * Resolve the field. * * @param mixed $root * @return mixed */ public function resolve($root): mixed { return Arr::get($root, $this->column); } /** * Get the directives of the field. * * @return array */ public function directives(): array { return []; } /** * Get the field as a string representation. * * @return string */ public function toString(): String { $string = Str::of($this->getName()); if ($this instanceof HasArgumentsField) { $string = $string->append($this->buildArguments($this->arguments())); } $string = $string->append(': ') ->append($this->getType()->toString()); if ($this->shouldRename()) { $string = $string->append(" @rename(attribute: {$this->column})"); } if (filled($this->directives())) { $string = $string->append(' '.$this->resolveDirectives($this->directives())); } return $string->__toString(); } /** * Determine if the field is different from the column. * * @return bool */ public function shouldRename(): bool { if (Arr::has($this->directives(), 'field')) { return false; } return $this->getName() !== $this->column; } }