Source of file FieldCreator.php
Size: 3,555 Bytes - Last Modified: 2021-12-23T10:31:47+00:00
/var/www/docs.ssmods.com/process/src/src/FieldCreator.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 | <?php namespace SilverStripe\GraphQL; use SilverStripe\Core\Injector\Injectable; use GraphQL\Type\Definition\Type; /** * Base type for query types within graphql. I.e. mutations or queries * * @link https://github.com/webonyx/graphql-php#schema * * @see MutationCreator * @see QueryCreator */ class FieldCreator { use Injectable; /** * @var Manager */ protected $manager; /** * @param Manager|null Used to retrieve types (including the one returned from this creator), * and nest field types regardless of instantiation of their creators. */ public function __construct(Manager $manager = null) { $this->manager = $manager; } /** * Returns any fixed attributes for this type. E.g. 'name' or 'description' * * @link https://github.com/webonyx/graphql-php#schema * @return array */ public function attributes() { return []; } /** * Gets the type for elements within this query, or callback to lazy-load this type * * @link https://github.com/webonyx/graphql-php#type-system * @return Type|callable */ public function type() { return null; } /** * List of arguments this query accepts. * * @link https://github.com/webonyx/graphql-php#schema * @return array */ public function args() { return []; } /** * Merge all attributes for this query (type, attributes, resolvers, etc). * * @return array */ public function getAttributes() { $args = $this->args(); $attributes = array_merge([ 'args' => $args, ], $this->attributes()); $type = $this->type(); if (isset($type)) { $attributes['type'] = $type; } $resolver = $this->getResolver(); if (isset($resolver)) { $attributes['resolve'] = $resolver; } return $attributes; } /** * Convert the Fluent instance to an array. * * @return array */ public function toArray() { return $this->getAttributes(); } /** * Dynamically retrieve the value of an attribute. * * @param string $key * * @return mixed */ public function __get($key) { $attributes = $this->getAttributes(); return isset($attributes[$key]) ? $attributes[$key] : null; } /** * Dynamically check if an attribute is set. * * @param string $key * @return bool */ public function __isset($key) { $attributes = $this->getAttributes(); return isset($attributes[$key]); } /** * Returns a closure callback to the resolve method. This method * will convert an invocation of this operation into a result or set of results. * * Either implement {@see OperationResolver}, or add a callback resolver within * getAttributes() with the 'resolve' key. * * @link https://github.com/webonyx/graphql-php#query-resolution * @see OperationResolver::resolve() for method signature. * @return \Closure|null */ protected function getResolver() { if (! method_exists($this, 'resolve')) { return null; } $resolver = array($this, 'resolve'); return function () use ($resolver) { $args = func_get_args(); $result = call_user_func_array($resolver, $args); return $result; }; } } |