repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
nuwave/lighthouse | src/Schema/Factories/FieldFactory.php | FieldFactory.getInputValueDefinitions | protected function getInputValueDefinitions(Collection $argumentValues): array
{
return $argumentValues
->mapWithKeys(function (ArgumentValue $argumentValue): array {
return [
$argumentValue->getName() => $this->argumentFactory->handle($argumentValue),
];
})
->all();
} | php | protected function getInputValueDefinitions(Collection $argumentValues): array
{
return $argumentValues
->mapWithKeys(function (ArgumentValue $argumentValue): array {
return [
$argumentValue->getName() => $this->argumentFactory->handle($argumentValue),
];
})
->all();
} | [
"protected",
"function",
"getInputValueDefinitions",
"(",
"Collection",
"$",
"argumentValues",
")",
":",
"array",
"{",
"return",
"$",
"argumentValues",
"->",
"mapWithKeys",
"(",
"function",
"(",
"ArgumentValue",
"$",
"argumentValue",
")",
":",
"array",
"{",
"return",
"[",
"$",
"argumentValue",
"->",
"getName",
"(",
")",
"=>",
"$",
"this",
"->",
"argumentFactory",
"->",
"handle",
"(",
"$",
"argumentValue",
")",
",",
"]",
";",
"}",
")",
"->",
"all",
"(",
")",
";",
"}"
]
| Transform the ArgumentValues into the final InputValueDefinitions.
@param \Illuminate\Support\Collection<ArgumentValue> $argumentValues
@return \GraphQL\Language\AST\InputValueDefinitionNode[] | [
"Transform",
"the",
"ArgumentValues",
"into",
"the",
"final",
"InputValueDefinitions",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/Factories/FieldFactory.php#L503-L512 | train |
nuwave/lighthouse | src/Execution/ExtensionErrorHandler.php | ExtensionErrorHandler.handle | public static function handle(Error $error, Closure $next): array
{
$underlyingException = $error->getPrevious();
if ($underlyingException instanceof RendersErrorsExtensions) {
// Reconstruct the error, passing in the extensions of the underlying exception
$error = new Error(
$error->message,
$error->nodes,
$error->getSource(),
$error->getPositions(),
$error->getPath(),
$underlyingException,
$underlyingException->extensionsContent()
);
}
return $next($error);
} | php | public static function handle(Error $error, Closure $next): array
{
$underlyingException = $error->getPrevious();
if ($underlyingException instanceof RendersErrorsExtensions) {
// Reconstruct the error, passing in the extensions of the underlying exception
$error = new Error(
$error->message,
$error->nodes,
$error->getSource(),
$error->getPositions(),
$error->getPath(),
$underlyingException,
$underlyingException->extensionsContent()
);
}
return $next($error);
} | [
"public",
"static",
"function",
"handle",
"(",
"Error",
"$",
"error",
",",
"Closure",
"$",
"next",
")",
":",
"array",
"{",
"$",
"underlyingException",
"=",
"$",
"error",
"->",
"getPrevious",
"(",
")",
";",
"if",
"(",
"$",
"underlyingException",
"instanceof",
"RendersErrorsExtensions",
")",
"{",
"// Reconstruct the error, passing in the extensions of the underlying exception",
"$",
"error",
"=",
"new",
"Error",
"(",
"$",
"error",
"->",
"message",
",",
"$",
"error",
"->",
"nodes",
",",
"$",
"error",
"->",
"getSource",
"(",
")",
",",
"$",
"error",
"->",
"getPositions",
"(",
")",
",",
"$",
"error",
"->",
"getPath",
"(",
")",
",",
"$",
"underlyingException",
",",
"$",
"underlyingException",
"->",
"extensionsContent",
"(",
")",
")",
";",
"}",
"return",
"$",
"next",
"(",
"$",
"error",
")",
";",
"}"
]
| Handle Exceptions that implement Nuwave\Lighthouse\Exceptions\RendersErrorsExtensions
and add extra content from them to the 'extensions' key of the Error that is rendered
to the User.
@param \GraphQL\Error\Error $error
@param \Closure $next
@return array | [
"Handle",
"Exceptions",
"that",
"implement",
"Nuwave",
"\\",
"Lighthouse",
"\\",
"Exceptions",
"\\",
"RendersErrorsExtensions",
"and",
"add",
"extra",
"content",
"from",
"them",
"to",
"the",
"extensions",
"key",
"of",
"the",
"Error",
"that",
"is",
"rendered",
"to",
"the",
"User",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Execution/ExtensionErrorHandler.php#L20-L38 | train |
nuwave/lighthouse | src/Subscriptions/Serializer.php | Serializer.serialize | public function serialize(GraphQLContext $context): string
{
$request = $context->request();
return serialize([
'request' => [
'query' => $request->query->all(),
'request' => $request->request->all(),
'attributes' => $request->attributes->all(),
'cookies' => [],
'files' => [],
'server' => Arr::except($request->server->all(), ['HTTP_AUTHORIZATION']),
'content' => $request->getContent(),
],
'user' => serialize($context->user()),
]);
} | php | public function serialize(GraphQLContext $context): string
{
$request = $context->request();
return serialize([
'request' => [
'query' => $request->query->all(),
'request' => $request->request->all(),
'attributes' => $request->attributes->all(),
'cookies' => [],
'files' => [],
'server' => Arr::except($request->server->all(), ['HTTP_AUTHORIZATION']),
'content' => $request->getContent(),
],
'user' => serialize($context->user()),
]);
} | [
"public",
"function",
"serialize",
"(",
"GraphQLContext",
"$",
"context",
")",
":",
"string",
"{",
"$",
"request",
"=",
"$",
"context",
"->",
"request",
"(",
")",
";",
"return",
"serialize",
"(",
"[",
"'request'",
"=>",
"[",
"'query'",
"=>",
"$",
"request",
"->",
"query",
"->",
"all",
"(",
")",
",",
"'request'",
"=>",
"$",
"request",
"->",
"request",
"->",
"all",
"(",
")",
",",
"'attributes'",
"=>",
"$",
"request",
"->",
"attributes",
"->",
"all",
"(",
")",
",",
"'cookies'",
"=>",
"[",
"]",
",",
"'files'",
"=>",
"[",
"]",
",",
"'server'",
"=>",
"Arr",
"::",
"except",
"(",
"$",
"request",
"->",
"server",
"->",
"all",
"(",
")",
",",
"[",
"'HTTP_AUTHORIZATION'",
"]",
")",
",",
"'content'",
"=>",
"$",
"request",
"->",
"getContent",
"(",
")",
",",
"]",
",",
"'user'",
"=>",
"serialize",
"(",
"$",
"context",
"->",
"user",
"(",
")",
")",
",",
"]",
")",
";",
"}"
]
| Serialize the context.
@param \Nuwave\Lighthouse\Support\Contracts\GraphQLContext $context
@return string | [
"Serialize",
"the",
"context",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Subscriptions/Serializer.php#L33-L49 | train |
nuwave/lighthouse | src/Subscriptions/Serializer.php | Serializer.unserialize | public function unserialize(string $context): GraphQLContext
{
[
'request' => $rawRequest,
'user' => $rawUser
] = unserialize($context);
$request = new Request(
$rawRequest['query'],
$rawRequest['request'],
$rawRequest['attributes'],
$rawRequest['cookies'],
$rawRequest['files'],
$rawRequest['server'],
$rawRequest['content']
);
$request->setUserResolver(
function () use ($rawUser) {
return unserialize($rawUser);
}
);
return $this->createsContext->generate($request);
} | php | public function unserialize(string $context): GraphQLContext
{
[
'request' => $rawRequest,
'user' => $rawUser
] = unserialize($context);
$request = new Request(
$rawRequest['query'],
$rawRequest['request'],
$rawRequest['attributes'],
$rawRequest['cookies'],
$rawRequest['files'],
$rawRequest['server'],
$rawRequest['content']
);
$request->setUserResolver(
function () use ($rawUser) {
return unserialize($rawUser);
}
);
return $this->createsContext->generate($request);
} | [
"public",
"function",
"unserialize",
"(",
"string",
"$",
"context",
")",
":",
"GraphQLContext",
"{",
"[",
"'request'",
"=>",
"$",
"rawRequest",
",",
"'user'",
"=>",
"$",
"rawUser",
"]",
"=",
"unserialize",
"(",
"$",
"context",
")",
";",
"$",
"request",
"=",
"new",
"Request",
"(",
"$",
"rawRequest",
"[",
"'query'",
"]",
",",
"$",
"rawRequest",
"[",
"'request'",
"]",
",",
"$",
"rawRequest",
"[",
"'attributes'",
"]",
",",
"$",
"rawRequest",
"[",
"'cookies'",
"]",
",",
"$",
"rawRequest",
"[",
"'files'",
"]",
",",
"$",
"rawRequest",
"[",
"'server'",
"]",
",",
"$",
"rawRequest",
"[",
"'content'",
"]",
")",
";",
"$",
"request",
"->",
"setUserResolver",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"rawUser",
")",
"{",
"return",
"unserialize",
"(",
"$",
"rawUser",
")",
";",
"}",
")",
";",
"return",
"$",
"this",
"->",
"createsContext",
"->",
"generate",
"(",
"$",
"request",
")",
";",
"}"
]
| Unserialize the context.
@param string $context
@return \Nuwave\Lighthouse\Support\Contracts\GraphQLContext | [
"Unserialize",
"the",
"context",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Subscriptions/Serializer.php#L57-L81 | train |
nuwave/lighthouse | src/Execution/LighthouseRequest.php | LighthouseRequest.variables | public function variables(): array
{
$variables = $this->fieldValue('variables');
// In case we are resolving a GET request, variables
// are sent as a JSON encoded string
if (is_string($variables)) {
return json_decode($variables, true) ?? [];
}
// If this is a POST request, Laravel already decoded the input for us
return $variables ?? [];
} | php | public function variables(): array
{
$variables = $this->fieldValue('variables');
// In case we are resolving a GET request, variables
// are sent as a JSON encoded string
if (is_string($variables)) {
return json_decode($variables, true) ?? [];
}
// If this is a POST request, Laravel already decoded the input for us
return $variables ?? [];
} | [
"public",
"function",
"variables",
"(",
")",
":",
"array",
"{",
"$",
"variables",
"=",
"$",
"this",
"->",
"fieldValue",
"(",
"'variables'",
")",
";",
"// In case we are resolving a GET request, variables",
"// are sent as a JSON encoded string",
"if",
"(",
"is_string",
"(",
"$",
"variables",
")",
")",
"{",
"return",
"json_decode",
"(",
"$",
"variables",
",",
"true",
")",
"??",
"[",
"]",
";",
"}",
"// If this is a POST request, Laravel already decoded the input for us",
"return",
"$",
"variables",
"??",
"[",
"]",
";",
"}"
]
| Get the given variables for the query.
@return mixed[] | [
"Get",
"the",
"given",
"variables",
"for",
"the",
"query",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Execution/LighthouseRequest.php#L38-L50 | train |
nuwave/lighthouse | src/Execution/LighthouseRequest.php | LighthouseRequest.fieldValue | protected function fieldValue(string $key)
{
return $this->request->input($key)
?? $this->request->input("{$this->batchIndex}.{$key}");
} | php | protected function fieldValue(string $key)
{
return $this->request->input($key)
?? $this->request->input("{$this->batchIndex}.{$key}");
} | [
"protected",
"function",
"fieldValue",
"(",
"string",
"$",
"key",
")",
"{",
"return",
"$",
"this",
"->",
"request",
"->",
"input",
"(",
"$",
"key",
")",
"??",
"$",
"this",
"->",
"request",
"->",
"input",
"(",
"\"{$this->batchIndex}.{$key}\"",
")",
";",
"}"
]
| Get the contents of a field by key.
This is expected to take batched requests into consideration.
@param string $key
@return array|string|null | [
"Get",
"the",
"contents",
"of",
"a",
"field",
"by",
"key",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Execution/LighthouseRequest.php#L70-L74 | train |
nuwave/lighthouse | src/Execution/QueryFilter.php | QueryFilter.getInstance | public static function getInstance(FieldValue $value): self
{
$handler = 'query.filter'
.'.'.strtolower($value->getParentName())
.'.'.strtolower($value->getFieldName());
// Get an existing instance or register a new one
return app()->bound($handler)
? app($handler)
: app()->instance($handler, app(static::class));
} | php | public static function getInstance(FieldValue $value): self
{
$handler = 'query.filter'
.'.'.strtolower($value->getParentName())
.'.'.strtolower($value->getFieldName());
// Get an existing instance or register a new one
return app()->bound($handler)
? app($handler)
: app()->instance($handler, app(static::class));
} | [
"public",
"static",
"function",
"getInstance",
"(",
"FieldValue",
"$",
"value",
")",
":",
"self",
"{",
"$",
"handler",
"=",
"'query.filter'",
".",
"'.'",
".",
"strtolower",
"(",
"$",
"value",
"->",
"getParentName",
"(",
")",
")",
".",
"'.'",
".",
"strtolower",
"(",
"$",
"value",
"->",
"getFieldName",
"(",
")",
")",
";",
"// Get an existing instance or register a new one",
"return",
"app",
"(",
")",
"->",
"bound",
"(",
"$",
"handler",
")",
"?",
"app",
"(",
"$",
"handler",
")",
":",
"app",
"(",
")",
"->",
"instance",
"(",
"$",
"handler",
",",
"app",
"(",
"static",
"::",
"class",
")",
")",
";",
"}"
]
| Get the single instance of the query filter for a field.
@param \Nuwave\Lighthouse\Schema\Values\FieldValue $value
@return static | [
"Get",
"the",
"single",
"instance",
"of",
"the",
"query",
"filter",
"for",
"a",
"field",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Execution/QueryFilter.php#L48-L58 | train |
nuwave/lighthouse | src/Execution/QueryFilter.php | QueryFilter.apply | public static function apply($query, array $args, array $scopes, ResolveInfo $resolveInfo)
{
/** @var \Nuwave\Lighthouse\Execution\QueryFilter $queryFilter */
if ($queryFilter = $resolveInfo->queryFilter ?? false) {
$query = $queryFilter->filter($query, $args);
}
foreach ($scopes as $scope) {
call_user_func([$query, $scope], $args);
}
return $query;
} | php | public static function apply($query, array $args, array $scopes, ResolveInfo $resolveInfo)
{
/** @var \Nuwave\Lighthouse\Execution\QueryFilter $queryFilter */
if ($queryFilter = $resolveInfo->queryFilter ?? false) {
$query = $queryFilter->filter($query, $args);
}
foreach ($scopes as $scope) {
call_user_func([$query, $scope], $args);
}
return $query;
} | [
"public",
"static",
"function",
"apply",
"(",
"$",
"query",
",",
"array",
"$",
"args",
",",
"array",
"$",
"scopes",
",",
"ResolveInfo",
"$",
"resolveInfo",
")",
"{",
"/** @var \\Nuwave\\Lighthouse\\Execution\\QueryFilter $queryFilter */",
"if",
"(",
"$",
"queryFilter",
"=",
"$",
"resolveInfo",
"->",
"queryFilter",
"??",
"false",
")",
"{",
"$",
"query",
"=",
"$",
"queryFilter",
"->",
"filter",
"(",
"$",
"query",
",",
"$",
"args",
")",
";",
"}",
"foreach",
"(",
"$",
"scopes",
"as",
"$",
"scope",
")",
"{",
"call_user_func",
"(",
"[",
"$",
"query",
",",
"$",
"scope",
"]",
",",
"$",
"args",
")",
";",
"}",
"return",
"$",
"query",
";",
"}"
]
| Check if the ResolveInfo contains a QueryFilter instance and apply it to the query if given.
@param \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder $query
@param array $args
@param string[] $scopes
@param \GraphQL\Type\Definition\ResolveInfo $resolveInfo
@return \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder | [
"Check",
"if",
"the",
"ResolveInfo",
"contains",
"a",
"QueryFilter",
"instance",
"and",
"apply",
"it",
"to",
"the",
"query",
"if",
"given",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Execution/QueryFilter.php#L69-L81 | train |
nuwave/lighthouse | src/Execution/QueryFilter.php | QueryFilter.filter | public function filter($query, array $args = [])
{
$valuesGroupedByFilterKey = [];
/**
* @var string
* @var mixed $value
*/
foreach ($args as $key => $value) {
/**
* @var string
* @var string[] $argNames
*/
foreach ($this->multiArgumentFiltersArgNames as $filterKey => $argNames) {
// Group together the values if multiple arguments are given the same key
if (in_array($key, $argNames)) {
$valuesGroupedByFilterKey[$filterKey][] = $value;
}
}
// Filters that only take a single argument can be applied directly
if ($filterInfo = Arr::get($this->singleArgumentFilters, $key)) {
/** @var \Nuwave\Lighthouse\Support\Contracts\ArgFilterDirective $argFilterDirective */
$argFilterDirective = $filterInfo['filter'];
$columnName = $filterInfo['columnName'];
$query = $argFilterDirective->applyFilter($query, $columnName, $value);
}
}
/**
* @var string
* @var array $values
*/
foreach ($valuesGroupedByFilterKey as $filterKey => $values) {
$columnName = Str::before($filterKey, '.');
if ($values) {
$argFilterDirective = $this->multiArgumentFilters[$filterKey];
$query = $argFilterDirective->applyFilter($query, $columnName, $values);
}
}
return $query;
} | php | public function filter($query, array $args = [])
{
$valuesGroupedByFilterKey = [];
/**
* @var string
* @var mixed $value
*/
foreach ($args as $key => $value) {
/**
* @var string
* @var string[] $argNames
*/
foreach ($this->multiArgumentFiltersArgNames as $filterKey => $argNames) {
// Group together the values if multiple arguments are given the same key
if (in_array($key, $argNames)) {
$valuesGroupedByFilterKey[$filterKey][] = $value;
}
}
// Filters that only take a single argument can be applied directly
if ($filterInfo = Arr::get($this->singleArgumentFilters, $key)) {
/** @var \Nuwave\Lighthouse\Support\Contracts\ArgFilterDirective $argFilterDirective */
$argFilterDirective = $filterInfo['filter'];
$columnName = $filterInfo['columnName'];
$query = $argFilterDirective->applyFilter($query, $columnName, $value);
}
}
/**
* @var string
* @var array $values
*/
foreach ($valuesGroupedByFilterKey as $filterKey => $values) {
$columnName = Str::before($filterKey, '.');
if ($values) {
$argFilterDirective = $this->multiArgumentFilters[$filterKey];
$query = $argFilterDirective->applyFilter($query, $columnName, $values);
}
}
return $query;
} | [
"public",
"function",
"filter",
"(",
"$",
"query",
",",
"array",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"$",
"valuesGroupedByFilterKey",
"=",
"[",
"]",
";",
"/**\n * @var string\n * @var mixed $value\n */",
"foreach",
"(",
"$",
"args",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"/**\n * @var string\n * @var string[] $argNames\n */",
"foreach",
"(",
"$",
"this",
"->",
"multiArgumentFiltersArgNames",
"as",
"$",
"filterKey",
"=>",
"$",
"argNames",
")",
"{",
"// Group together the values if multiple arguments are given the same key",
"if",
"(",
"in_array",
"(",
"$",
"key",
",",
"$",
"argNames",
")",
")",
"{",
"$",
"valuesGroupedByFilterKey",
"[",
"$",
"filterKey",
"]",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"// Filters that only take a single argument can be applied directly",
"if",
"(",
"$",
"filterInfo",
"=",
"Arr",
"::",
"get",
"(",
"$",
"this",
"->",
"singleArgumentFilters",
",",
"$",
"key",
")",
")",
"{",
"/** @var \\Nuwave\\Lighthouse\\Support\\Contracts\\ArgFilterDirective $argFilterDirective */",
"$",
"argFilterDirective",
"=",
"$",
"filterInfo",
"[",
"'filter'",
"]",
";",
"$",
"columnName",
"=",
"$",
"filterInfo",
"[",
"'columnName'",
"]",
";",
"$",
"query",
"=",
"$",
"argFilterDirective",
"->",
"applyFilter",
"(",
"$",
"query",
",",
"$",
"columnName",
",",
"$",
"value",
")",
";",
"}",
"}",
"/**\n * @var string\n * @var array $values\n */",
"foreach",
"(",
"$",
"valuesGroupedByFilterKey",
"as",
"$",
"filterKey",
"=>",
"$",
"values",
")",
"{",
"$",
"columnName",
"=",
"Str",
"::",
"before",
"(",
"$",
"filterKey",
",",
"'.'",
")",
";",
"if",
"(",
"$",
"values",
")",
"{",
"$",
"argFilterDirective",
"=",
"$",
"this",
"->",
"multiArgumentFilters",
"[",
"$",
"filterKey",
"]",
";",
"$",
"query",
"=",
"$",
"argFilterDirective",
"->",
"applyFilter",
"(",
"$",
"query",
",",
"$",
"columnName",
",",
"$",
"values",
")",
";",
"}",
"}",
"return",
"$",
"query",
";",
"}"
]
| Apply all registered filters to the query.
@param \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder $query
@param array $args
@return \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder | [
"Apply",
"all",
"registered",
"filters",
"to",
"the",
"query",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Execution/QueryFilter.php#L90-L135 | train |
nuwave/lighthouse | src/Execution/QueryFilter.php | QueryFilter.addArgumentFilter | public function addArgumentFilter(string $argumentName, string $columnName, ArgFilterDirective $argFilterDirective): self
{
if ($argFilterDirective->combinesMultipleArguments()) {
$filterKey = "{$columnName}.{$argFilterDirective->name()}";
$this->multiArgumentFilters[$filterKey] = $argFilterDirective;
$this->multiArgumentFiltersArgNames[$filterKey][] = $argumentName;
} else {
$this->singleArgumentFilters[$argumentName] = [
'filter' => $argFilterDirective,
'columnName' => $columnName,
];
}
return $this;
} | php | public function addArgumentFilter(string $argumentName, string $columnName, ArgFilterDirective $argFilterDirective): self
{
if ($argFilterDirective->combinesMultipleArguments()) {
$filterKey = "{$columnName}.{$argFilterDirective->name()}";
$this->multiArgumentFilters[$filterKey] = $argFilterDirective;
$this->multiArgumentFiltersArgNames[$filterKey][] = $argumentName;
} else {
$this->singleArgumentFilters[$argumentName] = [
'filter' => $argFilterDirective,
'columnName' => $columnName,
];
}
return $this;
} | [
"public",
"function",
"addArgumentFilter",
"(",
"string",
"$",
"argumentName",
",",
"string",
"$",
"columnName",
",",
"ArgFilterDirective",
"$",
"argFilterDirective",
")",
":",
"self",
"{",
"if",
"(",
"$",
"argFilterDirective",
"->",
"combinesMultipleArguments",
"(",
")",
")",
"{",
"$",
"filterKey",
"=",
"\"{$columnName}.{$argFilterDirective->name()}\"",
";",
"$",
"this",
"->",
"multiArgumentFilters",
"[",
"$",
"filterKey",
"]",
"=",
"$",
"argFilterDirective",
";",
"$",
"this",
"->",
"multiArgumentFiltersArgNames",
"[",
"$",
"filterKey",
"]",
"[",
"]",
"=",
"$",
"argumentName",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"singleArgumentFilters",
"[",
"$",
"argumentName",
"]",
"=",
"[",
"'filter'",
"=>",
"$",
"argFilterDirective",
",",
"'columnName'",
"=>",
"$",
"columnName",
",",
"]",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Add the argument filter.
@param string $argumentName
@param string $columnName
@param \Nuwave\Lighthouse\Support\Contracts\ArgFilterDirective $argFilterDirective
@return $this | [
"Add",
"the",
"argument",
"filter",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Execution/QueryFilter.php#L145-L160 | train |
nuwave/lighthouse | src/Schema/Directives/WhereDirective.php | WhereDirective.handleBuilder | public function handleBuilder($builder, $value)
{
// Allow users to overwrite the default "where" clause, e.g. "whereYear"
$clause = $this->directiveArgValue('clause', 'where');
return $builder->{$clause}(
$this->directiveArgValue('key', $this->definitionNode->name->value),
$operator = $this->directiveArgValue('operator', '='),
$value
);
} | php | public function handleBuilder($builder, $value)
{
// Allow users to overwrite the default "where" clause, e.g. "whereYear"
$clause = $this->directiveArgValue('clause', 'where');
return $builder->{$clause}(
$this->directiveArgValue('key', $this->definitionNode->name->value),
$operator = $this->directiveArgValue('operator', '='),
$value
);
} | [
"public",
"function",
"handleBuilder",
"(",
"$",
"builder",
",",
"$",
"value",
")",
"{",
"// Allow users to overwrite the default \"where\" clause, e.g. \"whereYear\"",
"$",
"clause",
"=",
"$",
"this",
"->",
"directiveArgValue",
"(",
"'clause'",
",",
"'where'",
")",
";",
"return",
"$",
"builder",
"->",
"{",
"$",
"clause",
"}",
"(",
"$",
"this",
"->",
"directiveArgValue",
"(",
"'key'",
",",
"$",
"this",
"->",
"definitionNode",
"->",
"name",
"->",
"value",
")",
",",
"$",
"operator",
"=",
"$",
"this",
"->",
"directiveArgValue",
"(",
"'operator'",
",",
"'='",
")",
",",
"$",
"value",
")",
";",
"}"
]
| Add any "WHERE" clause to the builder.
@param \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder $builder
@param mixed $value
@return \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder | [
"Add",
"any",
"WHERE",
"clause",
"to",
"the",
"builder",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/Directives/WhereDirective.php#L26-L36 | train |
nuwave/lighthouse | src/Subscriptions/SubscriptionServiceProvider.php | SubscriptionServiceProvider.register | public function register(): void
{
$this->app->singleton(BroadcastManager::class);
$this->app->singleton(SubscriptionRegistry::class);
$this->app->singleton(StoresSubscriptions::class, StorageManager::class);
$this->app->bind(ContextSerializer::class, Serializer::class);
$this->app->bind(AuthorizesSubscriptions::class, Authorizer::class);
$this->app->bind(SubscriptionIterator::class, SyncIterator::class);
$this->app->bind(SubscriptionExceptionHandler::class, ExceptionHandler::class);
$this->app->bind(BroadcastsSubscriptions::class, SubscriptionBroadcaster::class);
$this->app->bind(ProvidesSubscriptionResolver::class, SubscriptionResolverProvider::class);
} | php | public function register(): void
{
$this->app->singleton(BroadcastManager::class);
$this->app->singleton(SubscriptionRegistry::class);
$this->app->singleton(StoresSubscriptions::class, StorageManager::class);
$this->app->bind(ContextSerializer::class, Serializer::class);
$this->app->bind(AuthorizesSubscriptions::class, Authorizer::class);
$this->app->bind(SubscriptionIterator::class, SyncIterator::class);
$this->app->bind(SubscriptionExceptionHandler::class, ExceptionHandler::class);
$this->app->bind(BroadcastsSubscriptions::class, SubscriptionBroadcaster::class);
$this->app->bind(ProvidesSubscriptionResolver::class, SubscriptionResolverProvider::class);
} | [
"public",
"function",
"register",
"(",
")",
":",
"void",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"BroadcastManager",
"::",
"class",
")",
";",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"SubscriptionRegistry",
"::",
"class",
")",
";",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"StoresSubscriptions",
"::",
"class",
",",
"StorageManager",
"::",
"class",
")",
";",
"$",
"this",
"->",
"app",
"->",
"bind",
"(",
"ContextSerializer",
"::",
"class",
",",
"Serializer",
"::",
"class",
")",
";",
"$",
"this",
"->",
"app",
"->",
"bind",
"(",
"AuthorizesSubscriptions",
"::",
"class",
",",
"Authorizer",
"::",
"class",
")",
";",
"$",
"this",
"->",
"app",
"->",
"bind",
"(",
"SubscriptionIterator",
"::",
"class",
",",
"SyncIterator",
"::",
"class",
")",
";",
"$",
"this",
"->",
"app",
"->",
"bind",
"(",
"SubscriptionExceptionHandler",
"::",
"class",
",",
"ExceptionHandler",
"::",
"class",
")",
";",
"$",
"this",
"->",
"app",
"->",
"bind",
"(",
"BroadcastsSubscriptions",
"::",
"class",
",",
"SubscriptionBroadcaster",
"::",
"class",
")",
";",
"$",
"this",
"->",
"app",
"->",
"bind",
"(",
"ProvidesSubscriptionResolver",
"::",
"class",
",",
"SubscriptionResolverProvider",
"::",
"class",
")",
";",
"}"
]
| Register subscription services.
@return void | [
"Register",
"subscription",
"services",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Subscriptions/SubscriptionServiceProvider.php#L65-L77 | train |
nuwave/lighthouse | src/Schema/AST/ASTHelper.php | ASTHelper.mergeUniqueNodeList | public static function mergeUniqueNodeList($original, $addition, bool $overwriteDuplicates = false): NodeList
{
$newNames = (new Collection($addition))
->pluck('name.value')
->filter()
->all();
$remainingDefinitions = (new Collection($original))
->reject(function ($definition) use ($newNames, $overwriteDuplicates): bool {
$oldName = $definition->name->value;
$collisionOccurred = in_array(
$oldName,
$newNames
);
if ($collisionOccurred && ! $overwriteDuplicates) {
throw new DefinitionException(
"Duplicate definition {$oldName} found when merging."
);
}
return $collisionOccurred;
})
->values()
->all();
return self::mergeNodeList($remainingDefinitions, $addition);
} | php | public static function mergeUniqueNodeList($original, $addition, bool $overwriteDuplicates = false): NodeList
{
$newNames = (new Collection($addition))
->pluck('name.value')
->filter()
->all();
$remainingDefinitions = (new Collection($original))
->reject(function ($definition) use ($newNames, $overwriteDuplicates): bool {
$oldName = $definition->name->value;
$collisionOccurred = in_array(
$oldName,
$newNames
);
if ($collisionOccurred && ! $overwriteDuplicates) {
throw new DefinitionException(
"Duplicate definition {$oldName} found when merging."
);
}
return $collisionOccurred;
})
->values()
->all();
return self::mergeNodeList($remainingDefinitions, $addition);
} | [
"public",
"static",
"function",
"mergeUniqueNodeList",
"(",
"$",
"original",
",",
"$",
"addition",
",",
"bool",
"$",
"overwriteDuplicates",
"=",
"false",
")",
":",
"NodeList",
"{",
"$",
"newNames",
"=",
"(",
"new",
"Collection",
"(",
"$",
"addition",
")",
")",
"->",
"pluck",
"(",
"'name.value'",
")",
"->",
"filter",
"(",
")",
"->",
"all",
"(",
")",
";",
"$",
"remainingDefinitions",
"=",
"(",
"new",
"Collection",
"(",
"$",
"original",
")",
")",
"->",
"reject",
"(",
"function",
"(",
"$",
"definition",
")",
"use",
"(",
"$",
"newNames",
",",
"$",
"overwriteDuplicates",
")",
":",
"bool",
"{",
"$",
"oldName",
"=",
"$",
"definition",
"->",
"name",
"->",
"value",
";",
"$",
"collisionOccurred",
"=",
"in_array",
"(",
"$",
"oldName",
",",
"$",
"newNames",
")",
";",
"if",
"(",
"$",
"collisionOccurred",
"&&",
"!",
"$",
"overwriteDuplicates",
")",
"{",
"throw",
"new",
"DefinitionException",
"(",
"\"Duplicate definition {$oldName} found when merging.\"",
")",
";",
"}",
"return",
"$",
"collisionOccurred",
";",
"}",
")",
"->",
"values",
"(",
")",
"->",
"all",
"(",
")",
";",
"return",
"self",
"::",
"mergeNodeList",
"(",
"$",
"remainingDefinitions",
",",
"$",
"addition",
")",
";",
"}"
]
| This function will merge two lists uniquely by name.
@param \GraphQL\Language\AST\NodeList|array $original
@param \GraphQL\Language\AST\NodeList|array $addition
@param bool $overwriteDuplicates By default this throws if a collision occurs. If
this is set to true, the fields of the original list will be overwritten.
@return \GraphQL\Language\AST\NodeList | [
"This",
"function",
"will",
"merge",
"two",
"lists",
"uniquely",
"by",
"name",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/AST/ASTHelper.php#L54-L81 | train |
nuwave/lighthouse | src/Schema/AST/ASTHelper.php | ASTHelper.directiveHasArgument | public static function directiveHasArgument(DirectiveNode $directiveDefinition, string $name): bool
{
return (new Collection($directiveDefinition->arguments))
->contains(function (ArgumentNode $argumentNode) use ($name): bool {
return $argumentNode->name->value === $name;
});
} | php | public static function directiveHasArgument(DirectiveNode $directiveDefinition, string $name): bool
{
return (new Collection($directiveDefinition->arguments))
->contains(function (ArgumentNode $argumentNode) use ($name): bool {
return $argumentNode->name->value === $name;
});
} | [
"public",
"static",
"function",
"directiveHasArgument",
"(",
"DirectiveNode",
"$",
"directiveDefinition",
",",
"string",
"$",
"name",
")",
":",
"bool",
"{",
"return",
"(",
"new",
"Collection",
"(",
"$",
"directiveDefinition",
"->",
"arguments",
")",
")",
"->",
"contains",
"(",
"function",
"(",
"ArgumentNode",
"$",
"argumentNode",
")",
"use",
"(",
"$",
"name",
")",
":",
"bool",
"{",
"return",
"$",
"argumentNode",
"->",
"name",
"->",
"value",
"===",
"$",
"name",
";",
"}",
")",
";",
"}"
]
| Does the given directive have an argument of the given name?
@param \GraphQL\Language\AST\DirectiveNode $directiveDefinition
@param string $name
@return bool | [
"Does",
"the",
"given",
"directive",
"have",
"an",
"argument",
"of",
"the",
"given",
"name?"
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/AST/ASTHelper.php#L140-L146 | train |
nuwave/lighthouse | src/Schema/AST/ASTHelper.php | ASTHelper.argValue | public static function argValue(ArgumentNode $arg, $default = null)
{
$valueNode = $arg->value;
if (! $valueNode) {
return $default;
}
return AST::valueFromASTUntyped($valueNode);
} | php | public static function argValue(ArgumentNode $arg, $default = null)
{
$valueNode = $arg->value;
if (! $valueNode) {
return $default;
}
return AST::valueFromASTUntyped($valueNode);
} | [
"public",
"static",
"function",
"argValue",
"(",
"ArgumentNode",
"$",
"arg",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"valueNode",
"=",
"$",
"arg",
"->",
"value",
";",
"if",
"(",
"!",
"$",
"valueNode",
")",
"{",
"return",
"$",
"default",
";",
"}",
"return",
"AST",
"::",
"valueFromASTUntyped",
"(",
"$",
"valueNode",
")",
";",
"}"
]
| Get argument's value.
@param \GraphQL\Language\AST\ArgumentNode $arg
@param mixed $default
@return mixed | [
"Get",
"argument",
"s",
"value",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/AST/ASTHelper.php#L173-L182 | train |
nuwave/lighthouse | src/Schema/AST/ASTHelper.php | ASTHelper.directiveDefinition | public static function directiveDefinition(Node $definitionNode, string $name): ?DirectiveNode
{
return (new Collection($definitionNode->directives))
->first(function (DirectiveNode $directiveDefinitionNode) use ($name): bool {
return $directiveDefinitionNode->name->value === $name;
});
} | php | public static function directiveDefinition(Node $definitionNode, string $name): ?DirectiveNode
{
return (new Collection($definitionNode->directives))
->first(function (DirectiveNode $directiveDefinitionNode) use ($name): bool {
return $directiveDefinitionNode->name->value === $name;
});
} | [
"public",
"static",
"function",
"directiveDefinition",
"(",
"Node",
"$",
"definitionNode",
",",
"string",
"$",
"name",
")",
":",
"?",
"DirectiveNode",
"{",
"return",
"(",
"new",
"Collection",
"(",
"$",
"definitionNode",
"->",
"directives",
")",
")",
"->",
"first",
"(",
"function",
"(",
"DirectiveNode",
"$",
"directiveDefinitionNode",
")",
"use",
"(",
"$",
"name",
")",
":",
"bool",
"{",
"return",
"$",
"directiveDefinitionNode",
"->",
"name",
"->",
"value",
"===",
"$",
"name",
";",
"}",
")",
";",
"}"
]
| This can be at most one directive, since directives can only be used once per location.
@param \GraphQL\Language\AST\Node $definitionNode
@param string $name
@return \GraphQL\Language\AST\DirectiveNode|null | [
"This",
"can",
"be",
"at",
"most",
"one",
"directive",
"since",
"directives",
"can",
"only",
"be",
"used",
"once",
"per",
"location",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/AST/ASTHelper.php#L191-L197 | train |
nuwave/lighthouse | src/Schema/AST/ASTHelper.php | ASTHelper.hasDirectiveDefinition | public static function hasDirectiveDefinition(Node $definitionNode, string $name): bool
{
return (new Collection($definitionNode->directives))
->contains(function (DirectiveNode $directiveDefinitionNode) use ($name): bool {
return $directiveDefinitionNode->name->value === $name;
});
} | php | public static function hasDirectiveDefinition(Node $definitionNode, string $name): bool
{
return (new Collection($definitionNode->directives))
->contains(function (DirectiveNode $directiveDefinitionNode) use ($name): bool {
return $directiveDefinitionNode->name->value === $name;
});
} | [
"public",
"static",
"function",
"hasDirectiveDefinition",
"(",
"Node",
"$",
"definitionNode",
",",
"string",
"$",
"name",
")",
":",
"bool",
"{",
"return",
"(",
"new",
"Collection",
"(",
"$",
"definitionNode",
"->",
"directives",
")",
")",
"->",
"contains",
"(",
"function",
"(",
"DirectiveNode",
"$",
"directiveDefinitionNode",
")",
"use",
"(",
"$",
"name",
")",
":",
"bool",
"{",
"return",
"$",
"directiveDefinitionNode",
"->",
"name",
"->",
"value",
"===",
"$",
"name",
";",
"}",
")",
";",
"}"
]
| Check if a node has a particular directive defined upon it.
@param \GraphQL\Language\AST\Node $definitionNode
@param string $name
@return bool | [
"Check",
"if",
"a",
"node",
"has",
"a",
"particular",
"directive",
"defined",
"upon",
"it",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/AST/ASTHelper.php#L206-L212 | train |
nuwave/lighthouse | src/Schema/AST/ASTHelper.php | ASTHelper.attachDirectiveToObjectTypeFields | public static function attachDirectiveToObjectTypeFields(DocumentAST $documentAST, DirectiveNode $directive): DocumentAST
{
return $documentAST->objectTypeDefinitions()
->reduce(
function (DocumentAST $document, ObjectTypeDefinitionNode $objectType) use ($directive): DocumentAST {
if (! data_get($objectType, 'name.value')) {
return $document;
}
$objectType->fields = new NodeList(
(new Collection($objectType->fields))
->map(function (FieldDefinitionNode $field) use ($directive): FieldDefinitionNode {
$field->directives = $field->directives->merge([$directive]);
return $field;
})
->all()
);
$document->setDefinition($objectType);
return $document;
},
$documentAST
);
} | php | public static function attachDirectiveToObjectTypeFields(DocumentAST $documentAST, DirectiveNode $directive): DocumentAST
{
return $documentAST->objectTypeDefinitions()
->reduce(
function (DocumentAST $document, ObjectTypeDefinitionNode $objectType) use ($directive): DocumentAST {
if (! data_get($objectType, 'name.value')) {
return $document;
}
$objectType->fields = new NodeList(
(new Collection($objectType->fields))
->map(function (FieldDefinitionNode $field) use ($directive): FieldDefinitionNode {
$field->directives = $field->directives->merge([$directive]);
return $field;
})
->all()
);
$document->setDefinition($objectType);
return $document;
},
$documentAST
);
} | [
"public",
"static",
"function",
"attachDirectiveToObjectTypeFields",
"(",
"DocumentAST",
"$",
"documentAST",
",",
"DirectiveNode",
"$",
"directive",
")",
":",
"DocumentAST",
"{",
"return",
"$",
"documentAST",
"->",
"objectTypeDefinitions",
"(",
")",
"->",
"reduce",
"(",
"function",
"(",
"DocumentAST",
"$",
"document",
",",
"ObjectTypeDefinitionNode",
"$",
"objectType",
")",
"use",
"(",
"$",
"directive",
")",
":",
"DocumentAST",
"{",
"if",
"(",
"!",
"data_get",
"(",
"$",
"objectType",
",",
"'name.value'",
")",
")",
"{",
"return",
"$",
"document",
";",
"}",
"$",
"objectType",
"->",
"fields",
"=",
"new",
"NodeList",
"(",
"(",
"new",
"Collection",
"(",
"$",
"objectType",
"->",
"fields",
")",
")",
"->",
"map",
"(",
"function",
"(",
"FieldDefinitionNode",
"$",
"field",
")",
"use",
"(",
"$",
"directive",
")",
":",
"FieldDefinitionNode",
"{",
"$",
"field",
"->",
"directives",
"=",
"$",
"field",
"->",
"directives",
"->",
"merge",
"(",
"[",
"$",
"directive",
"]",
")",
";",
"return",
"$",
"field",
";",
"}",
")",
"->",
"all",
"(",
")",
")",
";",
"$",
"document",
"->",
"setDefinition",
"(",
"$",
"objectType",
")",
";",
"return",
"$",
"document",
";",
"}",
",",
"$",
"documentAST",
")",
";",
"}"
]
| Attach directive to all registered object type fields.
@param \Nuwave\Lighthouse\Schema\AST\DocumentAST $documentAST
@param \GraphQL\Language\AST\DirectiveNode $directive
@return \Nuwave\Lighthouse\Schema\AST\DocumentAST | [
"Attach",
"directive",
"to",
"all",
"registered",
"object",
"type",
"fields",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/AST/ASTHelper.php#L243-L268 | train |
nuwave/lighthouse | src/Schema/AST/ASTHelper.php | ASTHelper.attachNodeInterfaceToObjectType | public static function attachNodeInterfaceToObjectType(ObjectTypeDefinitionNode $objectType, DocumentAST $documentAST): DocumentAST
{
$objectType->interfaces = self::mergeNodeList(
$objectType->interfaces,
[
Parser::parseType(
'Node',
['noLocation' => true]
),
]
);
$globalIdFieldDefinition = PartialParser::fieldDefinition(
config('lighthouse.global_id_field').': ID! @globalId'
);
$objectType->fields = $objectType->fields->merge([$globalIdFieldDefinition]);
return $documentAST->setDefinition($objectType);
} | php | public static function attachNodeInterfaceToObjectType(ObjectTypeDefinitionNode $objectType, DocumentAST $documentAST): DocumentAST
{
$objectType->interfaces = self::mergeNodeList(
$objectType->interfaces,
[
Parser::parseType(
'Node',
['noLocation' => true]
),
]
);
$globalIdFieldDefinition = PartialParser::fieldDefinition(
config('lighthouse.global_id_field').': ID! @globalId'
);
$objectType->fields = $objectType->fields->merge([$globalIdFieldDefinition]);
return $documentAST->setDefinition($objectType);
} | [
"public",
"static",
"function",
"attachNodeInterfaceToObjectType",
"(",
"ObjectTypeDefinitionNode",
"$",
"objectType",
",",
"DocumentAST",
"$",
"documentAST",
")",
":",
"DocumentAST",
"{",
"$",
"objectType",
"->",
"interfaces",
"=",
"self",
"::",
"mergeNodeList",
"(",
"$",
"objectType",
"->",
"interfaces",
",",
"[",
"Parser",
"::",
"parseType",
"(",
"'Node'",
",",
"[",
"'noLocation'",
"=>",
"true",
"]",
")",
",",
"]",
")",
";",
"$",
"globalIdFieldDefinition",
"=",
"PartialParser",
"::",
"fieldDefinition",
"(",
"config",
"(",
"'lighthouse.global_id_field'",
")",
".",
"': ID! @globalId'",
")",
";",
"$",
"objectType",
"->",
"fields",
"=",
"$",
"objectType",
"->",
"fields",
"->",
"merge",
"(",
"[",
"$",
"globalIdFieldDefinition",
"]",
")",
";",
"return",
"$",
"documentAST",
"->",
"setDefinition",
"(",
"$",
"objectType",
")",
";",
"}"
]
| This adds an Interface called "Node" to an ObjectType definition.
@param \GraphQL\Language\AST\ObjectTypeDefinitionNode $objectType
@param \Nuwave\Lighthouse\Schema\AST\DocumentAST $documentAST
@return \Nuwave\Lighthouse\Schema\AST\DocumentAST | [
"This",
"adds",
"an",
"Interface",
"called",
"Node",
"to",
"an",
"ObjectType",
"definition",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/AST/ASTHelper.php#L277-L295 | train |
nuwave/lighthouse | src/Pagination/ConnectionField.php | ConnectionField.pageInfoResolver | public function pageInfoResolver(LengthAwarePaginator $paginator): array
{
return [
'total' => $paginator->total(),
'count' => $paginator->count(),
'currentPage' => $paginator->currentPage(),
'lastPage' => $paginator->lastPage(),
'hasNextPage' => $paginator->hasMorePages(),
'hasPreviousPage' => $paginator->currentPage() > 1,
'startCursor' => $paginator->firstItem()
? Cursor::encode($paginator->firstItem())
: null,
'endCursor' => $paginator->lastItem()
? Cursor::encode($paginator->lastItem())
: null,
];
} | php | public function pageInfoResolver(LengthAwarePaginator $paginator): array
{
return [
'total' => $paginator->total(),
'count' => $paginator->count(),
'currentPage' => $paginator->currentPage(),
'lastPage' => $paginator->lastPage(),
'hasNextPage' => $paginator->hasMorePages(),
'hasPreviousPage' => $paginator->currentPage() > 1,
'startCursor' => $paginator->firstItem()
? Cursor::encode($paginator->firstItem())
: null,
'endCursor' => $paginator->lastItem()
? Cursor::encode($paginator->lastItem())
: null,
];
} | [
"public",
"function",
"pageInfoResolver",
"(",
"LengthAwarePaginator",
"$",
"paginator",
")",
":",
"array",
"{",
"return",
"[",
"'total'",
"=>",
"$",
"paginator",
"->",
"total",
"(",
")",
",",
"'count'",
"=>",
"$",
"paginator",
"->",
"count",
"(",
")",
",",
"'currentPage'",
"=>",
"$",
"paginator",
"->",
"currentPage",
"(",
")",
",",
"'lastPage'",
"=>",
"$",
"paginator",
"->",
"lastPage",
"(",
")",
",",
"'hasNextPage'",
"=>",
"$",
"paginator",
"->",
"hasMorePages",
"(",
")",
",",
"'hasPreviousPage'",
"=>",
"$",
"paginator",
"->",
"currentPage",
"(",
")",
">",
"1",
",",
"'startCursor'",
"=>",
"$",
"paginator",
"->",
"firstItem",
"(",
")",
"?",
"Cursor",
"::",
"encode",
"(",
"$",
"paginator",
"->",
"firstItem",
"(",
")",
")",
":",
"null",
",",
"'endCursor'",
"=>",
"$",
"paginator",
"->",
"lastItem",
"(",
")",
"?",
"Cursor",
"::",
"encode",
"(",
"$",
"paginator",
"->",
"lastItem",
"(",
")",
")",
":",
"null",
",",
"]",
";",
"}"
]
| Resolve page info for connection.
@param \Illuminate\Contracts\Pagination\LengthAwarePaginator $paginator
@return array | [
"Resolve",
"page",
"info",
"for",
"connection",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Pagination/ConnectionField.php#L16-L32 | train |
nuwave/lighthouse | src/Pagination/ConnectionField.php | ConnectionField.edgeResolver | public function edgeResolver(LengthAwarePaginator $paginator): Collection
{
$firstItem = $paginator->firstItem();
return $paginator->values()->map(function ($item, $index) use ($firstItem) {
return [
'cursor' => Cursor::encode($firstItem + $index),
'node' => $item,
];
});
} | php | public function edgeResolver(LengthAwarePaginator $paginator): Collection
{
$firstItem = $paginator->firstItem();
return $paginator->values()->map(function ($item, $index) use ($firstItem) {
return [
'cursor' => Cursor::encode($firstItem + $index),
'node' => $item,
];
});
} | [
"public",
"function",
"edgeResolver",
"(",
"LengthAwarePaginator",
"$",
"paginator",
")",
":",
"Collection",
"{",
"$",
"firstItem",
"=",
"$",
"paginator",
"->",
"firstItem",
"(",
")",
";",
"return",
"$",
"paginator",
"->",
"values",
"(",
")",
"->",
"map",
"(",
"function",
"(",
"$",
"item",
",",
"$",
"index",
")",
"use",
"(",
"$",
"firstItem",
")",
"{",
"return",
"[",
"'cursor'",
"=>",
"Cursor",
"::",
"encode",
"(",
"$",
"firstItem",
"+",
"$",
"index",
")",
",",
"'node'",
"=>",
"$",
"item",
",",
"]",
";",
"}",
")",
";",
"}"
]
| Resolve edges for connection.
@param \Illuminate\Contracts\Pagination\LengthAwarePaginator $paginator
@return \Illuminate\Support\Collection | [
"Resolve",
"edges",
"for",
"connection",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Pagination/ConnectionField.php#L40-L50 | train |
nuwave/lighthouse | src/Execution/DataLoader/RelationBatchLoader.php | RelationBatchLoader.resolve | public function resolve(): array
{
$modelRelationFetcher = $this->getRelationFetcher();
if ($this->first !== null) {
$modelRelationFetcher->loadRelationsForPage($this->first, $this->page);
} else {
$modelRelationFetcher->loadRelations();
}
return $modelRelationFetcher->getRelationDictionary($this->relationName);
} | php | public function resolve(): array
{
$modelRelationFetcher = $this->getRelationFetcher();
if ($this->first !== null) {
$modelRelationFetcher->loadRelationsForPage($this->first, $this->page);
} else {
$modelRelationFetcher->loadRelations();
}
return $modelRelationFetcher->getRelationDictionary($this->relationName);
} | [
"public",
"function",
"resolve",
"(",
")",
":",
"array",
"{",
"$",
"modelRelationFetcher",
"=",
"$",
"this",
"->",
"getRelationFetcher",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"first",
"!==",
"null",
")",
"{",
"$",
"modelRelationFetcher",
"->",
"loadRelationsForPage",
"(",
"$",
"this",
"->",
"first",
",",
"$",
"this",
"->",
"page",
")",
";",
"}",
"else",
"{",
"$",
"modelRelationFetcher",
"->",
"loadRelations",
"(",
")",
";",
"}",
"return",
"$",
"modelRelationFetcher",
"->",
"getRelationDictionary",
"(",
"$",
"this",
"->",
"relationName",
")",
";",
"}"
]
| Resolve the keys.
@return mixed[] | [
"Resolve",
"the",
"keys",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Execution/DataLoader/RelationBatchLoader.php#L82-L93 | train |
nuwave/lighthouse | src/Execution/DataLoader/RelationBatchLoader.php | RelationBatchLoader.getRelationFetcher | protected function getRelationFetcher(): ModelRelationFetcher
{
return new ModelRelationFetcher(
$this->getParentModels(),
[$this->relationName => function ($query) {
return $this->resolveInfo
->builder
->addScopes($this->scopes)
->apply($query, $this->args);
}]
);
} | php | protected function getRelationFetcher(): ModelRelationFetcher
{
return new ModelRelationFetcher(
$this->getParentModels(),
[$this->relationName => function ($query) {
return $this->resolveInfo
->builder
->addScopes($this->scopes)
->apply($query, $this->args);
}]
);
} | [
"protected",
"function",
"getRelationFetcher",
"(",
")",
":",
"ModelRelationFetcher",
"{",
"return",
"new",
"ModelRelationFetcher",
"(",
"$",
"this",
"->",
"getParentModels",
"(",
")",
",",
"[",
"$",
"this",
"->",
"relationName",
"=>",
"function",
"(",
"$",
"query",
")",
"{",
"return",
"$",
"this",
"->",
"resolveInfo",
"->",
"builder",
"->",
"addScopes",
"(",
"$",
"this",
"->",
"scopes",
")",
"->",
"apply",
"(",
"$",
"query",
",",
"$",
"this",
"->",
"args",
")",
";",
"}",
"]",
")",
";",
"}"
]
| Construct a new instance of a relation fetcher.
@return \Nuwave\Lighthouse\Execution\DataLoader\ModelRelationFetcher | [
"Construct",
"a",
"new",
"instance",
"of",
"a",
"relation",
"fetcher",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Execution/DataLoader/RelationBatchLoader.php#L100-L111 | train |
nuwave/lighthouse | src/Schema/Directives/BaseDirective.php | BaseDirective.getResolverFromArgument | public function getResolverFromArgument(string $argumentName): Closure
{
[$className, $methodName] = $this->getMethodArgumentParts($argumentName);
$namespacedClassName = $this->namespaceClassName($className);
return Utils::constructResolver($namespacedClassName, $methodName);
} | php | public function getResolverFromArgument(string $argumentName): Closure
{
[$className, $methodName] = $this->getMethodArgumentParts($argumentName);
$namespacedClassName = $this->namespaceClassName($className);
return Utils::constructResolver($namespacedClassName, $methodName);
} | [
"public",
"function",
"getResolverFromArgument",
"(",
"string",
"$",
"argumentName",
")",
":",
"Closure",
"{",
"[",
"$",
"className",
",",
"$",
"methodName",
"]",
"=",
"$",
"this",
"->",
"getMethodArgumentParts",
"(",
"$",
"argumentName",
")",
";",
"$",
"namespacedClassName",
"=",
"$",
"this",
"->",
"namespaceClassName",
"(",
"$",
"className",
")",
";",
"return",
"Utils",
"::",
"constructResolver",
"(",
"$",
"namespacedClassName",
",",
"$",
"methodName",
")",
";",
"}"
]
| Get a Closure that is defined through an argument on the directive.
@param string $argumentName
@return \Closure | [
"Get",
"a",
"Closure",
"that",
"is",
"defined",
"through",
"an",
"argument",
"on",
"the",
"directive",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/Directives/BaseDirective.php#L88-L95 | train |
nuwave/lighthouse | src/Schema/Directives/BaseDirective.php | BaseDirective.getMethodArgumentParts | protected function getMethodArgumentParts(string $argumentName): array
{
$argumentParts = explode(
'@',
$this->directiveArgValue($argumentName)
);
if (
count($argumentParts) !== 2
|| empty($argumentParts[0])
|| empty($argumentParts[1])
) {
throw new DirectiveException(
"Directive '{$this->name()}' must have an argument '{$argumentName}' in the form 'ClassName@methodName'"
);
}
return $argumentParts;
} | php | protected function getMethodArgumentParts(string $argumentName): array
{
$argumentParts = explode(
'@',
$this->directiveArgValue($argumentName)
);
if (
count($argumentParts) !== 2
|| empty($argumentParts[0])
|| empty($argumentParts[1])
) {
throw new DirectiveException(
"Directive '{$this->name()}' must have an argument '{$argumentName}' in the form 'ClassName@methodName'"
);
}
return $argumentParts;
} | [
"protected",
"function",
"getMethodArgumentParts",
"(",
"string",
"$",
"argumentName",
")",
":",
"array",
"{",
"$",
"argumentParts",
"=",
"explode",
"(",
"'@'",
",",
"$",
"this",
"->",
"directiveArgValue",
"(",
"$",
"argumentName",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"argumentParts",
")",
"!==",
"2",
"||",
"empty",
"(",
"$",
"argumentParts",
"[",
"0",
"]",
")",
"||",
"empty",
"(",
"$",
"argumentParts",
"[",
"1",
"]",
")",
")",
"{",
"throw",
"new",
"DirectiveException",
"(",
"\"Directive '{$this->name()}' must have an argument '{$argumentName}' in the form 'ClassName@methodName'\"",
")",
";",
"}",
"return",
"$",
"argumentParts",
";",
"}"
]
| Split a single method argument into its parts.
A method argument is expected to contain a class and a method name, separated by an @ symbol.
e.g. "App\My\Class@methodName"
This validates that exactly two parts are given and are not empty.
@param string $argumentName
@return string[] Contains two entries: [string $className, string $methodName]
@throws \Nuwave\Lighthouse\Exceptions\DirectiveException | [
"Split",
"a",
"single",
"method",
"argument",
"into",
"its",
"parts",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/Directives/BaseDirective.php#L177-L195 | train |
nuwave/lighthouse | src/Schema/Directives/BaseDirective.php | BaseDirective.namespaceModelClass | protected function namespaceModelClass(string $modelClassCandidate): string
{
return $this->namespaceClassName(
$modelClassCandidate,
(array) config('lighthouse.namespaces.models'),
function (string $classCandidate): bool {
return is_subclass_of($classCandidate, Model::class);
}
);
} | php | protected function namespaceModelClass(string $modelClassCandidate): string
{
return $this->namespaceClassName(
$modelClassCandidate,
(array) config('lighthouse.namespaces.models'),
function (string $classCandidate): bool {
return is_subclass_of($classCandidate, Model::class);
}
);
} | [
"protected",
"function",
"namespaceModelClass",
"(",
"string",
"$",
"modelClassCandidate",
")",
":",
"string",
"{",
"return",
"$",
"this",
"->",
"namespaceClassName",
"(",
"$",
"modelClassCandidate",
",",
"(",
"array",
")",
"config",
"(",
"'lighthouse.namespaces.models'",
")",
",",
"function",
"(",
"string",
"$",
"classCandidate",
")",
":",
"bool",
"{",
"return",
"is_subclass_of",
"(",
"$",
"classCandidate",
",",
"Model",
"::",
"class",
")",
";",
"}",
")",
";",
"}"
]
| Try adding the default model namespace and ensure the given class is a model.
@param string $modelClassCandidate
@return string | [
"Try",
"adding",
"the",
"default",
"model",
"namespace",
"and",
"ensure",
"the",
"given",
"class",
"is",
"a",
"model",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/Directives/BaseDirective.php#L203-L212 | train |
nuwave/lighthouse | src/Schema/NodeRegistry.php | NodeRegistry.registerModel | public function registerModel(string $typeName, string $modelName): self
{
$this->nodeResolver[$typeName] = function ($id) use ($modelName) {
return $modelName::find($id);
};
return $this;
} | php | public function registerModel(string $typeName, string $modelName): self
{
$this->nodeResolver[$typeName] = function ($id) use ($modelName) {
return $modelName::find($id);
};
return $this;
} | [
"public",
"function",
"registerModel",
"(",
"string",
"$",
"typeName",
",",
"string",
"$",
"modelName",
")",
":",
"self",
"{",
"$",
"this",
"->",
"nodeResolver",
"[",
"$",
"typeName",
"]",
"=",
"function",
"(",
"$",
"id",
")",
"use",
"(",
"$",
"modelName",
")",
"{",
"return",
"$",
"modelName",
"::",
"find",
"(",
"$",
"id",
")",
";",
"}",
";",
"return",
"$",
"this",
";",
"}"
]
| Register an Eloquent model that can be resolved as a Node.
@param string $typeName
@param string $modelName
@return $this | [
"Register",
"an",
"Eloquent",
"model",
"that",
"can",
"be",
"resolved",
"as",
"a",
"Node",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/NodeRegistry.php#L79-L86 | train |
nuwave/lighthouse | src/Schema/NodeRegistry.php | NodeRegistry.resolve | public function resolve($rootValue, array $args, GraphQLContext $context, ResolveInfo $resolveInfo)
{
[$decodedType, $decodedId] = $args['id'];
// Check if we have a resolver registered for the given type
if (! $resolver = Arr::get($this->nodeResolver, $decodedType)) {
throw new Error("[{$decodedType}] is not a registered node and cannot be resolved.");
}
// Stash the decoded type, as it will later be used to determine the correct return type of the node query
$this->currentType = $decodedType;
return $resolver($decodedId, $context, $resolveInfo);
} | php | public function resolve($rootValue, array $args, GraphQLContext $context, ResolveInfo $resolveInfo)
{
[$decodedType, $decodedId] = $args['id'];
// Check if we have a resolver registered for the given type
if (! $resolver = Arr::get($this->nodeResolver, $decodedType)) {
throw new Error("[{$decodedType}] is not a registered node and cannot be resolved.");
}
// Stash the decoded type, as it will later be used to determine the correct return type of the node query
$this->currentType = $decodedType;
return $resolver($decodedId, $context, $resolveInfo);
} | [
"public",
"function",
"resolve",
"(",
"$",
"rootValue",
",",
"array",
"$",
"args",
",",
"GraphQLContext",
"$",
"context",
",",
"ResolveInfo",
"$",
"resolveInfo",
")",
"{",
"[",
"$",
"decodedType",
",",
"$",
"decodedId",
"]",
"=",
"$",
"args",
"[",
"'id'",
"]",
";",
"// Check if we have a resolver registered for the given type",
"if",
"(",
"!",
"$",
"resolver",
"=",
"Arr",
"::",
"get",
"(",
"$",
"this",
"->",
"nodeResolver",
",",
"$",
"decodedType",
")",
")",
"{",
"throw",
"new",
"Error",
"(",
"\"[{$decodedType}] is not a registered node and cannot be resolved.\"",
")",
";",
"}",
"// Stash the decoded type, as it will later be used to determine the correct return type of the node query",
"$",
"this",
"->",
"currentType",
"=",
"$",
"decodedType",
";",
"return",
"$",
"resolver",
"(",
"$",
"decodedId",
",",
"$",
"context",
",",
"$",
"resolveInfo",
")",
";",
"}"
]
| Get the appropriate resolver for the node and call it with the decoded id.
@param mixed|null $rootValue
@param array $args
@param \Nuwave\Lighthouse\Support\Contracts\GraphQLContext $context
@param \GraphQL\Type\Definition\ResolveInfo $resolveInfo
@return mixed
@throws \GraphQL\Error\Error | [
"Get",
"the",
"appropriate",
"resolver",
"for",
"the",
"node",
"and",
"call",
"it",
"with",
"the",
"decoded",
"id",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/NodeRegistry.php#L99-L112 | train |
nuwave/lighthouse | src/Schema/AST/PartialParser.php | PartialParser.getFirstAndValidateType | protected static function getFirstAndValidateType(NodeList $list, string $expectedType): Node
{
if ($list->count() !== 1) {
throw new ParseException('More than one definition was found in the passed in schema.');
}
$node = $list[0];
return self::validateType($node, $expectedType);
} | php | protected static function getFirstAndValidateType(NodeList $list, string $expectedType): Node
{
if ($list->count() !== 1) {
throw new ParseException('More than one definition was found in the passed in schema.');
}
$node = $list[0];
return self::validateType($node, $expectedType);
} | [
"protected",
"static",
"function",
"getFirstAndValidateType",
"(",
"NodeList",
"$",
"list",
",",
"string",
"$",
"expectedType",
")",
":",
"Node",
"{",
"if",
"(",
"$",
"list",
"->",
"count",
"(",
")",
"!==",
"1",
")",
"{",
"throw",
"new",
"ParseException",
"(",
"'More than one definition was found in the passed in schema.'",
")",
";",
"}",
"$",
"node",
"=",
"$",
"list",
"[",
"0",
"]",
";",
"return",
"self",
"::",
"validateType",
"(",
"$",
"node",
",",
"$",
"expectedType",
")",
";",
"}"
]
| Get the first Node from a given NodeList and validate it.
@param \GraphQL\Language\AST\NodeList $list
@param string $expectedType
@return \GraphQL\Language\AST\Node
@throws \Nuwave\Lighthouse\Exceptions\ParseException | [
"Get",
"the",
"first",
"Node",
"from",
"a",
"given",
"NodeList",
"and",
"validate",
"it",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/AST/PartialParser.php#L297-L306 | train |
nuwave/lighthouse | src/Support/Pipeline.php | Pipeline.carry | protected function carry(): Closure
{
return function ($stack, $pipe) {
return function ($passable) use ($stack, $pipe) {
if ($this->always !== null) {
$passable = ($this->always)($passable, $pipe);
}
$slice = parent::carry();
$callable = $slice($stack, $pipe);
return $callable($passable);
};
};
} | php | protected function carry(): Closure
{
return function ($stack, $pipe) {
return function ($passable) use ($stack, $pipe) {
if ($this->always !== null) {
$passable = ($this->always)($passable, $pipe);
}
$slice = parent::carry();
$callable = $slice($stack, $pipe);
return $callable($passable);
};
};
} | [
"protected",
"function",
"carry",
"(",
")",
":",
"Closure",
"{",
"return",
"function",
"(",
"$",
"stack",
",",
"$",
"pipe",
")",
"{",
"return",
"function",
"(",
"$",
"passable",
")",
"use",
"(",
"$",
"stack",
",",
"$",
"pipe",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"always",
"!==",
"null",
")",
"{",
"$",
"passable",
"=",
"(",
"$",
"this",
"->",
"always",
")",
"(",
"$",
"passable",
",",
"$",
"pipe",
")",
";",
"}",
"$",
"slice",
"=",
"parent",
"::",
"carry",
"(",
")",
";",
"$",
"callable",
"=",
"$",
"slice",
"(",
"$",
"stack",
",",
"$",
"pipe",
")",
";",
"return",
"$",
"callable",
"(",
"$",
"passable",
")",
";",
"}",
";",
"}",
";",
"}"
]
| Get a \Closure that represents a slice of the application onion.
@return \Closure | [
"Get",
"a",
"\\",
"Closure",
"that",
"represents",
"a",
"slice",
"of",
"the",
"application",
"onion",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Support/Pipeline.php#L33-L47 | train |
nuwave/lighthouse | src/GraphQL.php | GraphQL.executeRequest | public function executeRequest(GraphQLRequest $request): array
{
$result = $this->executeQuery(
$request->query(),
$this->createsContext->generate(
app('request')
),
$request->variables(),
null,
$request->operationName()
);
return $this->applyDebugSettings($result);
} | php | public function executeRequest(GraphQLRequest $request): array
{
$result = $this->executeQuery(
$request->query(),
$this->createsContext->generate(
app('request')
),
$request->variables(),
null,
$request->operationName()
);
return $this->applyDebugSettings($result);
} | [
"public",
"function",
"executeRequest",
"(",
"GraphQLRequest",
"$",
"request",
")",
":",
"array",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"executeQuery",
"(",
"$",
"request",
"->",
"query",
"(",
")",
",",
"$",
"this",
"->",
"createsContext",
"->",
"generate",
"(",
"app",
"(",
"'request'",
")",
")",
",",
"$",
"request",
"->",
"variables",
"(",
")",
",",
"null",
",",
"$",
"request",
"->",
"operationName",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"applyDebugSettings",
"(",
"$",
"result",
")",
";",
"}"
]
| Execute a set of batched queries on the lighthouse schema and return a
collection of ExecutionResults.
@param \Nuwave\Lighthouse\Execution\GraphQLRequest $request
@return mixed[] | [
"Execute",
"a",
"set",
"of",
"batched",
"queries",
"on",
"the",
"lighthouse",
"schema",
"and",
"return",
"a",
"collection",
"of",
"ExecutionResults",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/GraphQL.php#L121-L134 | train |
nuwave/lighthouse | src/GraphQL.php | GraphQL.executeQuery | public function executeQuery(
$query,
GraphQLContext $context,
?array $variables = [],
$rootValue = null,
?string $operationName = null
): ExecutionResult {
// Building the executable schema might take a while to do,
// so we do it before we fire the StartExecution event.
// This allows tracking the time for batched queries independently.
$this->prepSchema();
$this->eventDispatcher->dispatch(
new StartExecution
);
$result = GraphQLBase::executeQuery(
$this->executableSchema,
$query,
$rootValue,
$context,
$variables,
$operationName,
null,
$this->getValidationRules() + DocumentValidator::defaultRules()
);
/** @var \Nuwave\Lighthouse\Execution\ExtensionsResponse[] $extensionsResponses */
$extensionsResponses = (array) $this->eventDispatcher->dispatch(
new BuildExtensionsResponse
);
foreach ($extensionsResponses as $extensionsResponse) {
if ($extensionsResponse) {
$result->extensions[$extensionsResponse->key()] = $extensionsResponse->content();
}
}
$result->setErrorsHandler(
function (array $errors, callable $formatter): array {
// User defined error handlers, implementing \Nuwave\Lighthouse\Execution\ErrorHandler
// This allows the user to register multiple handlers and pipe the errors through.
$handlers = config('lighthouse.error_handlers', []);
return array_map(
function (Error $error) use ($handlers, $formatter) {
return $this->pipeline
->send($error)
->through($handlers)
->then(function (Error $error) use ($formatter) {
return $formatter($error);
});
},
$errors
);
}
);
// Allow listeners to manipulate the result after each resolved query
$this->eventDispatcher->dispatch(
new ManipulateResult($result)
);
return $result;
} | php | public function executeQuery(
$query,
GraphQLContext $context,
?array $variables = [],
$rootValue = null,
?string $operationName = null
): ExecutionResult {
// Building the executable schema might take a while to do,
// so we do it before we fire the StartExecution event.
// This allows tracking the time for batched queries independently.
$this->prepSchema();
$this->eventDispatcher->dispatch(
new StartExecution
);
$result = GraphQLBase::executeQuery(
$this->executableSchema,
$query,
$rootValue,
$context,
$variables,
$operationName,
null,
$this->getValidationRules() + DocumentValidator::defaultRules()
);
/** @var \Nuwave\Lighthouse\Execution\ExtensionsResponse[] $extensionsResponses */
$extensionsResponses = (array) $this->eventDispatcher->dispatch(
new BuildExtensionsResponse
);
foreach ($extensionsResponses as $extensionsResponse) {
if ($extensionsResponse) {
$result->extensions[$extensionsResponse->key()] = $extensionsResponse->content();
}
}
$result->setErrorsHandler(
function (array $errors, callable $formatter): array {
// User defined error handlers, implementing \Nuwave\Lighthouse\Execution\ErrorHandler
// This allows the user to register multiple handlers and pipe the errors through.
$handlers = config('lighthouse.error_handlers', []);
return array_map(
function (Error $error) use ($handlers, $formatter) {
return $this->pipeline
->send($error)
->through($handlers)
->then(function (Error $error) use ($formatter) {
return $formatter($error);
});
},
$errors
);
}
);
// Allow listeners to manipulate the result after each resolved query
$this->eventDispatcher->dispatch(
new ManipulateResult($result)
);
return $result;
} | [
"public",
"function",
"executeQuery",
"(",
"$",
"query",
",",
"GraphQLContext",
"$",
"context",
",",
"?",
"array",
"$",
"variables",
"=",
"[",
"]",
",",
"$",
"rootValue",
"=",
"null",
",",
"?",
"string",
"$",
"operationName",
"=",
"null",
")",
":",
"ExecutionResult",
"{",
"// Building the executable schema might take a while to do,",
"// so we do it before we fire the StartExecution event.",
"// This allows tracking the time for batched queries independently.",
"$",
"this",
"->",
"prepSchema",
"(",
")",
";",
"$",
"this",
"->",
"eventDispatcher",
"->",
"dispatch",
"(",
"new",
"StartExecution",
")",
";",
"$",
"result",
"=",
"GraphQLBase",
"::",
"executeQuery",
"(",
"$",
"this",
"->",
"executableSchema",
",",
"$",
"query",
",",
"$",
"rootValue",
",",
"$",
"context",
",",
"$",
"variables",
",",
"$",
"operationName",
",",
"null",
",",
"$",
"this",
"->",
"getValidationRules",
"(",
")",
"+",
"DocumentValidator",
"::",
"defaultRules",
"(",
")",
")",
";",
"/** @var \\Nuwave\\Lighthouse\\Execution\\ExtensionsResponse[] $extensionsResponses */",
"$",
"extensionsResponses",
"=",
"(",
"array",
")",
"$",
"this",
"->",
"eventDispatcher",
"->",
"dispatch",
"(",
"new",
"BuildExtensionsResponse",
")",
";",
"foreach",
"(",
"$",
"extensionsResponses",
"as",
"$",
"extensionsResponse",
")",
"{",
"if",
"(",
"$",
"extensionsResponse",
")",
"{",
"$",
"result",
"->",
"extensions",
"[",
"$",
"extensionsResponse",
"->",
"key",
"(",
")",
"]",
"=",
"$",
"extensionsResponse",
"->",
"content",
"(",
")",
";",
"}",
"}",
"$",
"result",
"->",
"setErrorsHandler",
"(",
"function",
"(",
"array",
"$",
"errors",
",",
"callable",
"$",
"formatter",
")",
":",
"array",
"{",
"// User defined error handlers, implementing \\Nuwave\\Lighthouse\\Execution\\ErrorHandler",
"// This allows the user to register multiple handlers and pipe the errors through.",
"$",
"handlers",
"=",
"config",
"(",
"'lighthouse.error_handlers'",
",",
"[",
"]",
")",
";",
"return",
"array_map",
"(",
"function",
"(",
"Error",
"$",
"error",
")",
"use",
"(",
"$",
"handlers",
",",
"$",
"formatter",
")",
"{",
"return",
"$",
"this",
"->",
"pipeline",
"->",
"send",
"(",
"$",
"error",
")",
"->",
"through",
"(",
"$",
"handlers",
")",
"->",
"then",
"(",
"function",
"(",
"Error",
"$",
"error",
")",
"use",
"(",
"$",
"formatter",
")",
"{",
"return",
"$",
"formatter",
"(",
"$",
"error",
")",
";",
"}",
")",
";",
"}",
",",
"$",
"errors",
")",
";",
"}",
")",
";",
"// Allow listeners to manipulate the result after each resolved query",
"$",
"this",
"->",
"eventDispatcher",
"->",
"dispatch",
"(",
"new",
"ManipulateResult",
"(",
"$",
"result",
")",
")",
";",
"return",
"$",
"result",
";",
"}"
]
| Execute a GraphQL query on the Lighthouse schema and return the raw ExecutionResult.
To render the ExecutionResult, you will probably want to call `->toArray($debug)` on it,
with $debug being a combination of flags in \GraphQL\Error\Debug
@param string|\GraphQL\Language\AST\DocumentNode $query
@param \Nuwave\Lighthouse\Support\Contracts\GraphQLContext $context
@param mixed[] $variables
@param mixed|null $rootValue
@param string|null $operationName
@return \GraphQL\Executor\ExecutionResult | [
"Execute",
"a",
"GraphQL",
"query",
"on",
"the",
"Lighthouse",
"schema",
"and",
"return",
"the",
"raw",
"ExecutionResult",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/GraphQL.php#L167-L231 | train |
nuwave/lighthouse | src/GraphQL.php | GraphQL.prepSchema | public function prepSchema(): Schema
{
if (empty($this->executableSchema)) {
$this->executableSchema = $this->schemaBuilder->build(
$this->documentAST()
);
}
return $this->executableSchema;
} | php | public function prepSchema(): Schema
{
if (empty($this->executableSchema)) {
$this->executableSchema = $this->schemaBuilder->build(
$this->documentAST()
);
}
return $this->executableSchema;
} | [
"public",
"function",
"prepSchema",
"(",
")",
":",
"Schema",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"executableSchema",
")",
")",
"{",
"$",
"this",
"->",
"executableSchema",
"=",
"$",
"this",
"->",
"schemaBuilder",
"->",
"build",
"(",
"$",
"this",
"->",
"documentAST",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"executableSchema",
";",
"}"
]
| Ensure an executable GraphQL schema is present.
@return \GraphQL\Type\Schema | [
"Ensure",
"an",
"executable",
"GraphQL",
"schema",
"is",
"present",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/GraphQL.php#L238-L247 | train |
nuwave/lighthouse | src/GraphQL.php | GraphQL.getValidationRules | protected function getValidationRules(): array
{
return [
QueryComplexity::class => new QueryComplexity(config('lighthouse.security.max_query_complexity', 0)),
QueryDepth::class => new QueryDepth(config('lighthouse.security.max_query_depth', 0)),
DisableIntrospection::class => new DisableIntrospection(config('lighthouse.security.disable_introspection', false)),
];
} | php | protected function getValidationRules(): array
{
return [
QueryComplexity::class => new QueryComplexity(config('lighthouse.security.max_query_complexity', 0)),
QueryDepth::class => new QueryDepth(config('lighthouse.security.max_query_depth', 0)),
DisableIntrospection::class => new DisableIntrospection(config('lighthouse.security.disable_introspection', false)),
];
} | [
"protected",
"function",
"getValidationRules",
"(",
")",
":",
"array",
"{",
"return",
"[",
"QueryComplexity",
"::",
"class",
"=>",
"new",
"QueryComplexity",
"(",
"config",
"(",
"'lighthouse.security.max_query_complexity'",
",",
"0",
")",
")",
",",
"QueryDepth",
"::",
"class",
"=>",
"new",
"QueryDepth",
"(",
"config",
"(",
"'lighthouse.security.max_query_depth'",
",",
"0",
")",
")",
",",
"DisableIntrospection",
"::",
"class",
"=>",
"new",
"DisableIntrospection",
"(",
"config",
"(",
"'lighthouse.security.disable_introspection'",
",",
"false",
")",
")",
",",
"]",
";",
"}"
]
| Construct the validation rules with values given in the config.
@return \GraphQL\Validator\Rules\ValidationRule[] | [
"Construct",
"the",
"validation",
"rules",
"with",
"values",
"given",
"in",
"the",
"config",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/GraphQL.php#L254-L261 | train |
nuwave/lighthouse | src/GraphQL.php | GraphQL.documentAST | public function documentAST(): DocumentAST
{
if (empty($this->documentAST)) {
$this->documentAST = config('lighthouse.cache.enable')
? app('cache')
->rememberForever(
config('lighthouse.cache.key'),
function (): DocumentAST {
return $this->buildAST();
}
)
: $this->buildAST();
}
return $this->documentAST;
} | php | public function documentAST(): DocumentAST
{
if (empty($this->documentAST)) {
$this->documentAST = config('lighthouse.cache.enable')
? app('cache')
->rememberForever(
config('lighthouse.cache.key'),
function (): DocumentAST {
return $this->buildAST();
}
)
: $this->buildAST();
}
return $this->documentAST;
} | [
"public",
"function",
"documentAST",
"(",
")",
":",
"DocumentAST",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"documentAST",
")",
")",
"{",
"$",
"this",
"->",
"documentAST",
"=",
"config",
"(",
"'lighthouse.cache.enable'",
")",
"?",
"app",
"(",
"'cache'",
")",
"->",
"rememberForever",
"(",
"config",
"(",
"'lighthouse.cache.key'",
")",
",",
"function",
"(",
")",
":",
"DocumentAST",
"{",
"return",
"$",
"this",
"->",
"buildAST",
"(",
")",
";",
"}",
")",
":",
"$",
"this",
"->",
"buildAST",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"documentAST",
";",
"}"
]
| Get instance of DocumentAST.
@return \Nuwave\Lighthouse\Schema\AST\DocumentAST | [
"Get",
"instance",
"of",
"DocumentAST",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/GraphQL.php#L268-L283 | train |
nuwave/lighthouse | src/GraphQL.php | GraphQL.buildAST | protected function buildAST(): DocumentAST
{
$schemaString = $this->schemaSourceProvider->getSchemaString();
// Allow to register listeners that add in additional schema definitions.
// This can be used by plugins to hook into the schema building process
// while still allowing the user to add in their schema as usual.
$additionalSchemas = (array) $this->eventDispatcher->dispatch(
new BuildSchemaString($schemaString)
);
$documentAST = $this->astBuilder->build(
implode(
PHP_EOL,
Arr::prepend($additionalSchemas, $schemaString)
)
);
// Listeners may manipulate the DocumentAST that is passed by reference
// into the ManipulateAST event. This can be useful for extensions
// that want to programmatically change the schema.
$this->eventDispatcher->dispatch(
new ManipulateAST($documentAST)
);
return $documentAST;
} | php | protected function buildAST(): DocumentAST
{
$schemaString = $this->schemaSourceProvider->getSchemaString();
// Allow to register listeners that add in additional schema definitions.
// This can be used by plugins to hook into the schema building process
// while still allowing the user to add in their schema as usual.
$additionalSchemas = (array) $this->eventDispatcher->dispatch(
new BuildSchemaString($schemaString)
);
$documentAST = $this->astBuilder->build(
implode(
PHP_EOL,
Arr::prepend($additionalSchemas, $schemaString)
)
);
// Listeners may manipulate the DocumentAST that is passed by reference
// into the ManipulateAST event. This can be useful for extensions
// that want to programmatically change the schema.
$this->eventDispatcher->dispatch(
new ManipulateAST($documentAST)
);
return $documentAST;
} | [
"protected",
"function",
"buildAST",
"(",
")",
":",
"DocumentAST",
"{",
"$",
"schemaString",
"=",
"$",
"this",
"->",
"schemaSourceProvider",
"->",
"getSchemaString",
"(",
")",
";",
"// Allow to register listeners that add in additional schema definitions.",
"// This can be used by plugins to hook into the schema building process",
"// while still allowing the user to add in their schema as usual.",
"$",
"additionalSchemas",
"=",
"(",
"array",
")",
"$",
"this",
"->",
"eventDispatcher",
"->",
"dispatch",
"(",
"new",
"BuildSchemaString",
"(",
"$",
"schemaString",
")",
")",
";",
"$",
"documentAST",
"=",
"$",
"this",
"->",
"astBuilder",
"->",
"build",
"(",
"implode",
"(",
"PHP_EOL",
",",
"Arr",
"::",
"prepend",
"(",
"$",
"additionalSchemas",
",",
"$",
"schemaString",
")",
")",
")",
";",
"// Listeners may manipulate the DocumentAST that is passed by reference",
"// into the ManipulateAST event. This can be useful for extensions",
"// that want to programmatically change the schema.",
"$",
"this",
"->",
"eventDispatcher",
"->",
"dispatch",
"(",
"new",
"ManipulateAST",
"(",
"$",
"documentAST",
")",
")",
";",
"return",
"$",
"documentAST",
";",
"}"
]
| Get the schema string and build an AST out of it.
@return \Nuwave\Lighthouse\Schema\AST\DocumentAST | [
"Get",
"the",
"schema",
"string",
"and",
"build",
"an",
"AST",
"out",
"of",
"it",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/GraphQL.php#L290-L316 | train |
nuwave/lighthouse | src/Schema/Directives/OrderByDirective.php | OrderByDirective.handleBuilder | public function handleBuilder($builder, $value)
{
foreach ($value as $orderByClause) {
$builder->orderBy(
$orderByClause['field'],
$orderByClause['order']
);
}
return $builder;
} | php | public function handleBuilder($builder, $value)
{
foreach ($value as $orderByClause) {
$builder->orderBy(
$orderByClause['field'],
$orderByClause['order']
);
}
return $builder;
} | [
"public",
"function",
"handleBuilder",
"(",
"$",
"builder",
",",
"$",
"value",
")",
"{",
"foreach",
"(",
"$",
"value",
"as",
"$",
"orderByClause",
")",
"{",
"$",
"builder",
"->",
"orderBy",
"(",
"$",
"orderByClause",
"[",
"'field'",
"]",
",",
"$",
"orderByClause",
"[",
"'order'",
"]",
")",
";",
"}",
"return",
"$",
"builder",
";",
"}"
]
| Apply an "ORDER BY" clause.
@param \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder $builder
@param mixed $value
@return \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder | [
"Apply",
"an",
"ORDER",
"BY",
"clause",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/Directives/OrderByDirective.php#L35-L45 | train |
nuwave/lighthouse | src/Schema/Directives/OrderByDirective.php | OrderByDirective.manipulateSchema | public function manipulateSchema(InputValueDefinitionNode $argDefinition, FieldDefinitionNode $fieldDefinition, ObjectTypeDefinitionNode $parentType, DocumentAST $current)
{
$expectedOrderByClause = ASTHelper::cloneNode($argDefinition);
// Users may define this as NonNull if they want
if ($argDefinition->type instanceof NonNullTypeNode) {
$expectedOrderByClause = $argDefinition->type;
}
if (
data_get(
$expectedOrderByClause,
// Must be a list
'type'
// of non-nullable
.'.type'
// input objects
.'.type.name.value'
) !== 'OrderByClause'
) {
throw new DefinitionException(
"Must define the argument type of {$argDefinition->name->value} on field {$fieldDefinition->name->value} as [OrderByClause!]."
);
}
return $current;
} | php | public function manipulateSchema(InputValueDefinitionNode $argDefinition, FieldDefinitionNode $fieldDefinition, ObjectTypeDefinitionNode $parentType, DocumentAST $current)
{
$expectedOrderByClause = ASTHelper::cloneNode($argDefinition);
// Users may define this as NonNull if they want
if ($argDefinition->type instanceof NonNullTypeNode) {
$expectedOrderByClause = $argDefinition->type;
}
if (
data_get(
$expectedOrderByClause,
// Must be a list
'type'
// of non-nullable
.'.type'
// input objects
.'.type.name.value'
) !== 'OrderByClause'
) {
throw new DefinitionException(
"Must define the argument type of {$argDefinition->name->value} on field {$fieldDefinition->name->value} as [OrderByClause!]."
);
}
return $current;
} | [
"public",
"function",
"manipulateSchema",
"(",
"InputValueDefinitionNode",
"$",
"argDefinition",
",",
"FieldDefinitionNode",
"$",
"fieldDefinition",
",",
"ObjectTypeDefinitionNode",
"$",
"parentType",
",",
"DocumentAST",
"$",
"current",
")",
"{",
"$",
"expectedOrderByClause",
"=",
"ASTHelper",
"::",
"cloneNode",
"(",
"$",
"argDefinition",
")",
";",
"// Users may define this as NonNull if they want",
"if",
"(",
"$",
"argDefinition",
"->",
"type",
"instanceof",
"NonNullTypeNode",
")",
"{",
"$",
"expectedOrderByClause",
"=",
"$",
"argDefinition",
"->",
"type",
";",
"}",
"if",
"(",
"data_get",
"(",
"$",
"expectedOrderByClause",
",",
"// Must be a list",
"'type'",
"// of non-nullable",
".",
"'.type'",
"// input objects",
".",
"'.type.name.value'",
")",
"!==",
"'OrderByClause'",
")",
"{",
"throw",
"new",
"DefinitionException",
"(",
"\"Must define the argument type of {$argDefinition->name->value} on field {$fieldDefinition->name->value} as [OrderByClause!].\"",
")",
";",
"}",
"return",
"$",
"current",
";",
"}"
]
| Validate the input argument definition.
@param \GraphQL\Language\AST\InputValueDefinitionNode $argDefinition
@param \GraphQL\Language\AST\FieldDefinitionNode $fieldDefinition
@param \GraphQL\Language\AST\ObjectTypeDefinitionNode $parentType
@param \Nuwave\Lighthouse\Schema\AST\DocumentAST $current
@return \Nuwave\Lighthouse\Schema\AST\DocumentAST | [
"Validate",
"the",
"input",
"argument",
"definition",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/Directives/OrderByDirective.php#L56-L82 | train |
nuwave/lighthouse | src/LighthouseServiceProvider.php | LighthouseServiceProvider.loadRoutesFrom | protected function loadRoutesFrom($path): void
{
if (Str::contains($this->app->version(), 'Lumen')) {
require realpath($path);
return;
}
parent::loadRoutesFrom($path);
} | php | protected function loadRoutesFrom($path): void
{
if (Str::contains($this->app->version(), 'Lumen')) {
require realpath($path);
return;
}
parent::loadRoutesFrom($path);
} | [
"protected",
"function",
"loadRoutesFrom",
"(",
"$",
"path",
")",
":",
"void",
"{",
"if",
"(",
"Str",
"::",
"contains",
"(",
"$",
"this",
"->",
"app",
"->",
"version",
"(",
")",
",",
"'Lumen'",
")",
")",
"{",
"require",
"realpath",
"(",
"$",
"path",
")",
";",
"return",
";",
"}",
"parent",
"::",
"loadRoutesFrom",
"(",
"$",
"path",
")",
";",
"}"
]
| Load routes from provided path.
@param string $path
@return void | [
"Load",
"routes",
"from",
"provided",
"path",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/LighthouseServiceProvider.php#L87-L96 | train |
nuwave/lighthouse | src/Schema/Factories/NodeFactory.php | NodeFactory.handle | public function handle(TypeDefinitionNode $definition): Type
{
$nodeValue = new NodeValue($definition);
return $this->pipeline
->send($nodeValue)
->through(
$this->directiveFactory->createNodeMiddleware($definition)
)
->via('handleNode')
->then(function (NodeValue $value) use ($definition): Type {
$nodeResolver = $this->directiveFactory->createNodeResolver($definition);
if ($nodeResolver) {
return $nodeResolver->resolveNode($value);
}
return $this->resolveType($definition);
});
} | php | public function handle(TypeDefinitionNode $definition): Type
{
$nodeValue = new NodeValue($definition);
return $this->pipeline
->send($nodeValue)
->through(
$this->directiveFactory->createNodeMiddleware($definition)
)
->via('handleNode')
->then(function (NodeValue $value) use ($definition): Type {
$nodeResolver = $this->directiveFactory->createNodeResolver($definition);
if ($nodeResolver) {
return $nodeResolver->resolveNode($value);
}
return $this->resolveType($definition);
});
} | [
"public",
"function",
"handle",
"(",
"TypeDefinitionNode",
"$",
"definition",
")",
":",
"Type",
"{",
"$",
"nodeValue",
"=",
"new",
"NodeValue",
"(",
"$",
"definition",
")",
";",
"return",
"$",
"this",
"->",
"pipeline",
"->",
"send",
"(",
"$",
"nodeValue",
")",
"->",
"through",
"(",
"$",
"this",
"->",
"directiveFactory",
"->",
"createNodeMiddleware",
"(",
"$",
"definition",
")",
")",
"->",
"via",
"(",
"'handleNode'",
")",
"->",
"then",
"(",
"function",
"(",
"NodeValue",
"$",
"value",
")",
"use",
"(",
"$",
"definition",
")",
":",
"Type",
"{",
"$",
"nodeResolver",
"=",
"$",
"this",
"->",
"directiveFactory",
"->",
"createNodeResolver",
"(",
"$",
"definition",
")",
";",
"if",
"(",
"$",
"nodeResolver",
")",
"{",
"return",
"$",
"nodeResolver",
"->",
"resolveNode",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"this",
"->",
"resolveType",
"(",
"$",
"definition",
")",
";",
"}",
")",
";",
"}"
]
| Transform node to type.
@param \GraphQL\Language\AST\TypeDefinitionNode $definition
@return \GraphQL\Type\Definition\Type | [
"Transform",
"node",
"to",
"type",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/Factories/NodeFactory.php#L84-L103 | train |
nuwave/lighthouse | src/Schema/Factories/NodeFactory.php | NodeFactory.resolveType | protected function resolveType(TypeDefinitionNode $typeDefinition): Type
{
// Ignore TypeExtensionNode since they are merged before we get here
switch (get_class($typeDefinition)) {
case EnumTypeDefinitionNode::class:
return $this->resolveEnumType($typeDefinition);
case ScalarTypeDefinitionNode::class:
return $this->resolveScalarType($typeDefinition);
case ObjectTypeDefinitionNode::class:
return $this->resolveObjectType($typeDefinition);
case InputObjectTypeDefinitionNode::class:
return $this->resolveInputObjectType($typeDefinition);
case InterfaceTypeDefinitionNode::class:
return $this->resolveInterfaceType($typeDefinition);
case UnionTypeDefinitionNode::class:
return $this->resolveUnionType($typeDefinition);
default:
throw new InvariantViolation(
"Unknown type for definition [{$typeDefinition->name->value}]"
);
}
} | php | protected function resolveType(TypeDefinitionNode $typeDefinition): Type
{
// Ignore TypeExtensionNode since they are merged before we get here
switch (get_class($typeDefinition)) {
case EnumTypeDefinitionNode::class:
return $this->resolveEnumType($typeDefinition);
case ScalarTypeDefinitionNode::class:
return $this->resolveScalarType($typeDefinition);
case ObjectTypeDefinitionNode::class:
return $this->resolveObjectType($typeDefinition);
case InputObjectTypeDefinitionNode::class:
return $this->resolveInputObjectType($typeDefinition);
case InterfaceTypeDefinitionNode::class:
return $this->resolveInterfaceType($typeDefinition);
case UnionTypeDefinitionNode::class:
return $this->resolveUnionType($typeDefinition);
default:
throw new InvariantViolation(
"Unknown type for definition [{$typeDefinition->name->value}]"
);
}
} | [
"protected",
"function",
"resolveType",
"(",
"TypeDefinitionNode",
"$",
"typeDefinition",
")",
":",
"Type",
"{",
"// Ignore TypeExtensionNode since they are merged before we get here",
"switch",
"(",
"get_class",
"(",
"$",
"typeDefinition",
")",
")",
"{",
"case",
"EnumTypeDefinitionNode",
"::",
"class",
":",
"return",
"$",
"this",
"->",
"resolveEnumType",
"(",
"$",
"typeDefinition",
")",
";",
"case",
"ScalarTypeDefinitionNode",
"::",
"class",
":",
"return",
"$",
"this",
"->",
"resolveScalarType",
"(",
"$",
"typeDefinition",
")",
";",
"case",
"ObjectTypeDefinitionNode",
"::",
"class",
":",
"return",
"$",
"this",
"->",
"resolveObjectType",
"(",
"$",
"typeDefinition",
")",
";",
"case",
"InputObjectTypeDefinitionNode",
"::",
"class",
":",
"return",
"$",
"this",
"->",
"resolveInputObjectType",
"(",
"$",
"typeDefinition",
")",
";",
"case",
"InterfaceTypeDefinitionNode",
"::",
"class",
":",
"return",
"$",
"this",
"->",
"resolveInterfaceType",
"(",
"$",
"typeDefinition",
")",
";",
"case",
"UnionTypeDefinitionNode",
"::",
"class",
":",
"return",
"$",
"this",
"->",
"resolveUnionType",
"(",
"$",
"typeDefinition",
")",
";",
"default",
":",
"throw",
"new",
"InvariantViolation",
"(",
"\"Unknown type for definition [{$typeDefinition->name->value}]\"",
")",
";",
"}",
"}"
]
| Transform value to type.
@param \GraphQL\Language\AST\TypeDefinitionNode $typeDefinition
@return \GraphQL\Type\Definition\Type
@throws \Nuwave\Lighthouse\Exceptions\DefinitionException | [
"Transform",
"value",
"to",
"type",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/Factories/NodeFactory.php#L113-L134 | train |
nuwave/lighthouse | src/Schema/Factories/NodeFactory.php | NodeFactory.resolveFieldsFunction | protected function resolveFieldsFunction($definition): Closure
{
return function () use ($definition): array {
return (new Collection($definition->fields))
->mapWithKeys(function (FieldDefinitionNode $fieldDefinition) use ($definition): array {
$fieldValue = new FieldValue(
new NodeValue($definition),
$fieldDefinition
);
return [
$fieldDefinition->name->value => app(FieldFactory::class)->handle($fieldValue),
];
})
->toArray();
};
} | php | protected function resolveFieldsFunction($definition): Closure
{
return function () use ($definition): array {
return (new Collection($definition->fields))
->mapWithKeys(function (FieldDefinitionNode $fieldDefinition) use ($definition): array {
$fieldValue = new FieldValue(
new NodeValue($definition),
$fieldDefinition
);
return [
$fieldDefinition->name->value => app(FieldFactory::class)->handle($fieldValue),
];
})
->toArray();
};
} | [
"protected",
"function",
"resolveFieldsFunction",
"(",
"$",
"definition",
")",
":",
"Closure",
"{",
"return",
"function",
"(",
")",
"use",
"(",
"$",
"definition",
")",
":",
"array",
"{",
"return",
"(",
"new",
"Collection",
"(",
"$",
"definition",
"->",
"fields",
")",
")",
"->",
"mapWithKeys",
"(",
"function",
"(",
"FieldDefinitionNode",
"$",
"fieldDefinition",
")",
"use",
"(",
"$",
"definition",
")",
":",
"array",
"{",
"$",
"fieldValue",
"=",
"new",
"FieldValue",
"(",
"new",
"NodeValue",
"(",
"$",
"definition",
")",
",",
"$",
"fieldDefinition",
")",
";",
"return",
"[",
"$",
"fieldDefinition",
"->",
"name",
"->",
"value",
"=>",
"app",
"(",
"FieldFactory",
"::",
"class",
")",
"->",
"handle",
"(",
"$",
"fieldValue",
")",
",",
"]",
";",
"}",
")",
"->",
"toArray",
"(",
")",
";",
"}",
";",
"}"
]
| Returns a closure that lazy loads the fields for a constructed type.
@param \GraphQL\Language\AST\ObjectTypeDefinitionNode|\GraphQL\Language\AST\InterfaceTypeDefinitionNode $definition
@return \Closure | [
"Returns",
"a",
"closure",
"that",
"lazy",
"loads",
"the",
"fields",
"for",
"a",
"constructed",
"type",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/Factories/NodeFactory.php#L226-L242 | train |
nuwave/lighthouse | src/Schema/SchemaBuilder.php | SchemaBuilder.build | public function build($documentAST)
{
/** @var \GraphQL\Language\AST\TypeDefinitionNode $typeDefinition */
foreach ($documentAST->typeDefinitions() as $typeDefinition) {
$type = $this->nodeFactory->handle($typeDefinition);
$this->typeRegistry->register($type);
switch ($type->name) {
case 'Query':
/** @var \Nuwave\Lighthouse\Schema\Conversion\DefinitionNodeConverter $queryType */
$queryType = $type;
continue 2;
case 'Mutation':
/** @var \GraphQL\Type\Definition\ObjectType $mutationType */
$mutationType = $type;
continue 2;
case 'Subscription':
/** @var \GraphQL\Type\Definition\ObjectType $subscriptionType */
$subscriptionType = $type;
continue 2;
default:
$types[] = $type;
}
}
if (empty($queryType)) {
throw new InvariantViolation(
'The root Query type must be present in the schema.'
);
}
$config = SchemaConfig::create()
// Always set Query since it is required
->setQuery(
$queryType
)
->setDirectives(
$this->convertDirectives($documentAST)
->toArray()
);
// Those are optional so only add them if they are present in the schema
if (isset($mutationType)) {
$config->setMutation($mutationType);
}
if (isset($subscriptionType)) {
$config->setSubscription($subscriptionType);
}
// Not using lazy loading, as we do not have a way of discovering
// orphaned types at the moment
if (isset($types)) {
$config->setTypes($types);
}
return new Schema($config);
} | php | public function build($documentAST)
{
/** @var \GraphQL\Language\AST\TypeDefinitionNode $typeDefinition */
foreach ($documentAST->typeDefinitions() as $typeDefinition) {
$type = $this->nodeFactory->handle($typeDefinition);
$this->typeRegistry->register($type);
switch ($type->name) {
case 'Query':
/** @var \Nuwave\Lighthouse\Schema\Conversion\DefinitionNodeConverter $queryType */
$queryType = $type;
continue 2;
case 'Mutation':
/** @var \GraphQL\Type\Definition\ObjectType $mutationType */
$mutationType = $type;
continue 2;
case 'Subscription':
/** @var \GraphQL\Type\Definition\ObjectType $subscriptionType */
$subscriptionType = $type;
continue 2;
default:
$types[] = $type;
}
}
if (empty($queryType)) {
throw new InvariantViolation(
'The root Query type must be present in the schema.'
);
}
$config = SchemaConfig::create()
// Always set Query since it is required
->setQuery(
$queryType
)
->setDirectives(
$this->convertDirectives($documentAST)
->toArray()
);
// Those are optional so only add them if they are present in the schema
if (isset($mutationType)) {
$config->setMutation($mutationType);
}
if (isset($subscriptionType)) {
$config->setSubscription($subscriptionType);
}
// Not using lazy loading, as we do not have a way of discovering
// orphaned types at the moment
if (isset($types)) {
$config->setTypes($types);
}
return new Schema($config);
} | [
"public",
"function",
"build",
"(",
"$",
"documentAST",
")",
"{",
"/** @var \\GraphQL\\Language\\AST\\TypeDefinitionNode $typeDefinition */",
"foreach",
"(",
"$",
"documentAST",
"->",
"typeDefinitions",
"(",
")",
"as",
"$",
"typeDefinition",
")",
"{",
"$",
"type",
"=",
"$",
"this",
"->",
"nodeFactory",
"->",
"handle",
"(",
"$",
"typeDefinition",
")",
";",
"$",
"this",
"->",
"typeRegistry",
"->",
"register",
"(",
"$",
"type",
")",
";",
"switch",
"(",
"$",
"type",
"->",
"name",
")",
"{",
"case",
"'Query'",
":",
"/** @var \\Nuwave\\Lighthouse\\Schema\\Conversion\\DefinitionNodeConverter $queryType */",
"$",
"queryType",
"=",
"$",
"type",
";",
"continue",
"2",
";",
"case",
"'Mutation'",
":",
"/** @var \\GraphQL\\Type\\Definition\\ObjectType $mutationType */",
"$",
"mutationType",
"=",
"$",
"type",
";",
"continue",
"2",
";",
"case",
"'Subscription'",
":",
"/** @var \\GraphQL\\Type\\Definition\\ObjectType $subscriptionType */",
"$",
"subscriptionType",
"=",
"$",
"type",
";",
"continue",
"2",
";",
"default",
":",
"$",
"types",
"[",
"]",
"=",
"$",
"type",
";",
"}",
"}",
"if",
"(",
"empty",
"(",
"$",
"queryType",
")",
")",
"{",
"throw",
"new",
"InvariantViolation",
"(",
"'The root Query type must be present in the schema.'",
")",
";",
"}",
"$",
"config",
"=",
"SchemaConfig",
"::",
"create",
"(",
")",
"// Always set Query since it is required",
"->",
"setQuery",
"(",
"$",
"queryType",
")",
"->",
"setDirectives",
"(",
"$",
"this",
"->",
"convertDirectives",
"(",
"$",
"documentAST",
")",
"->",
"toArray",
"(",
")",
")",
";",
"// Those are optional so only add them if they are present in the schema",
"if",
"(",
"isset",
"(",
"$",
"mutationType",
")",
")",
"{",
"$",
"config",
"->",
"setMutation",
"(",
"$",
"mutationType",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"subscriptionType",
")",
")",
"{",
"$",
"config",
"->",
"setSubscription",
"(",
"$",
"subscriptionType",
")",
";",
"}",
"// Not using lazy loading, as we do not have a way of discovering",
"// orphaned types at the moment",
"if",
"(",
"isset",
"(",
"$",
"types",
")",
")",
"{",
"$",
"config",
"->",
"setTypes",
"(",
"$",
"types",
")",
";",
"}",
"return",
"new",
"Schema",
"(",
"$",
"config",
")",
";",
"}"
]
| Build an executable schema from AST.
@param \Nuwave\Lighthouse\Schema\AST\DocumentAST $documentAST
@return \GraphQL\Type\Schema | [
"Build",
"an",
"executable",
"schema",
"from",
"AST",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/SchemaBuilder.php#L56-L111 | train |
nuwave/lighthouse | src/Schema/SchemaBuilder.php | SchemaBuilder.convertDirectives | protected function convertDirectives(DocumentAST $document): Collection
{
return $document->directiveDefinitions()
->map(function (DirectiveDefinitionNode $directive) {
return new Directive([
'name' => $directive->name->value,
'description' => data_get($directive->description, 'value'),
'locations' => (new Collection($directive->locations))
->map(function ($location) {
return $location->value;
})
->toArray(),
'args' => (new Collection($directive->arguments))
->map(function (InputValueDefinitionNode $argument) {
$fieldArgumentConfig = [
'name' => $argument->name->value,
'description' => data_get($argument->description, 'value'),
'type' => $this->definitionNodeConverter->toType($argument->type),
];
if ($defaultValue = $argument->defaultValue) {
$fieldArgumentConfig += [
'defaultValue' => $defaultValue,
];
}
return new FieldArgument($fieldArgumentConfig);
})
->toArray(),
'astNode' => $directive,
]);
});
} | php | protected function convertDirectives(DocumentAST $document): Collection
{
return $document->directiveDefinitions()
->map(function (DirectiveDefinitionNode $directive) {
return new Directive([
'name' => $directive->name->value,
'description' => data_get($directive->description, 'value'),
'locations' => (new Collection($directive->locations))
->map(function ($location) {
return $location->value;
})
->toArray(),
'args' => (new Collection($directive->arguments))
->map(function (InputValueDefinitionNode $argument) {
$fieldArgumentConfig = [
'name' => $argument->name->value,
'description' => data_get($argument->description, 'value'),
'type' => $this->definitionNodeConverter->toType($argument->type),
];
if ($defaultValue = $argument->defaultValue) {
$fieldArgumentConfig += [
'defaultValue' => $defaultValue,
];
}
return new FieldArgument($fieldArgumentConfig);
})
->toArray(),
'astNode' => $directive,
]);
});
} | [
"protected",
"function",
"convertDirectives",
"(",
"DocumentAST",
"$",
"document",
")",
":",
"Collection",
"{",
"return",
"$",
"document",
"->",
"directiveDefinitions",
"(",
")",
"->",
"map",
"(",
"function",
"(",
"DirectiveDefinitionNode",
"$",
"directive",
")",
"{",
"return",
"new",
"Directive",
"(",
"[",
"'name'",
"=>",
"$",
"directive",
"->",
"name",
"->",
"value",
",",
"'description'",
"=>",
"data_get",
"(",
"$",
"directive",
"->",
"description",
",",
"'value'",
")",
",",
"'locations'",
"=>",
"(",
"new",
"Collection",
"(",
"$",
"directive",
"->",
"locations",
")",
")",
"->",
"map",
"(",
"function",
"(",
"$",
"location",
")",
"{",
"return",
"$",
"location",
"->",
"value",
";",
"}",
")",
"->",
"toArray",
"(",
")",
",",
"'args'",
"=>",
"(",
"new",
"Collection",
"(",
"$",
"directive",
"->",
"arguments",
")",
")",
"->",
"map",
"(",
"function",
"(",
"InputValueDefinitionNode",
"$",
"argument",
")",
"{",
"$",
"fieldArgumentConfig",
"=",
"[",
"'name'",
"=>",
"$",
"argument",
"->",
"name",
"->",
"value",
",",
"'description'",
"=>",
"data_get",
"(",
"$",
"argument",
"->",
"description",
",",
"'value'",
")",
",",
"'type'",
"=>",
"$",
"this",
"->",
"definitionNodeConverter",
"->",
"toType",
"(",
"$",
"argument",
"->",
"type",
")",
",",
"]",
";",
"if",
"(",
"$",
"defaultValue",
"=",
"$",
"argument",
"->",
"defaultValue",
")",
"{",
"$",
"fieldArgumentConfig",
"+=",
"[",
"'defaultValue'",
"=>",
"$",
"defaultValue",
",",
"]",
";",
"}",
"return",
"new",
"FieldArgument",
"(",
"$",
"fieldArgumentConfig",
")",
";",
"}",
")",
"->",
"toArray",
"(",
")",
",",
"'astNode'",
"=>",
"$",
"directive",
",",
"]",
")",
";",
"}",
")",
";",
"}"
]
| Set custom client directives.
@param \Nuwave\Lighthouse\Schema\AST\DocumentAST $document
@return \Illuminate\Support\Collection<\GraphQL\Type\Definition\Directive> | [
"Set",
"custom",
"client",
"directives",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/SchemaBuilder.php#L119-L151 | train |
nuwave/lighthouse | src/Defer/DeferrableDirective.php | DeferrableDirective.shouldDefer | protected function shouldDefer(TypeNode $fieldType, ResolveInfo $resolveInfo): bool
{
if (strtolower($resolveInfo->operation->operation) === 'mutation') {
return false;
}
foreach ($resolveInfo->fieldNodes as $fieldNode) {
$deferDirective = ASTHelper::directiveDefinition($fieldNode, 'defer');
if (! $deferDirective) {
return false;
}
if (! ASTHelper::directiveArgValue($deferDirective, 'if', true)) {
return false;
}
$skipDirective = ASTHelper::directiveDefinition($fieldNode, 'skip');
$includeDirective = ASTHelper::directiveDefinition($fieldNode, 'include');
$shouldSkip = $skipDirective
? ASTHelper::directiveArgValue($skipDirective, 'if', false)
: false;
$shouldInclude = $includeDirective
? ASTHelper::directiveArgValue($includeDirective, 'if', false)
: false;
if ($shouldSkip || $shouldInclude) {
return false;
}
}
if ($fieldType instanceof NonNullTypeNode) {
throw new ParseClientException('The @defer directive cannot be placed on a Non-Nullable field.');
}
return true;
} | php | protected function shouldDefer(TypeNode $fieldType, ResolveInfo $resolveInfo): bool
{
if (strtolower($resolveInfo->operation->operation) === 'mutation') {
return false;
}
foreach ($resolveInfo->fieldNodes as $fieldNode) {
$deferDirective = ASTHelper::directiveDefinition($fieldNode, 'defer');
if (! $deferDirective) {
return false;
}
if (! ASTHelper::directiveArgValue($deferDirective, 'if', true)) {
return false;
}
$skipDirective = ASTHelper::directiveDefinition($fieldNode, 'skip');
$includeDirective = ASTHelper::directiveDefinition($fieldNode, 'include');
$shouldSkip = $skipDirective
? ASTHelper::directiveArgValue($skipDirective, 'if', false)
: false;
$shouldInclude = $includeDirective
? ASTHelper::directiveArgValue($includeDirective, 'if', false)
: false;
if ($shouldSkip || $shouldInclude) {
return false;
}
}
if ($fieldType instanceof NonNullTypeNode) {
throw new ParseClientException('The @defer directive cannot be placed on a Non-Nullable field.');
}
return true;
} | [
"protected",
"function",
"shouldDefer",
"(",
"TypeNode",
"$",
"fieldType",
",",
"ResolveInfo",
"$",
"resolveInfo",
")",
":",
"bool",
"{",
"if",
"(",
"strtolower",
"(",
"$",
"resolveInfo",
"->",
"operation",
"->",
"operation",
")",
"===",
"'mutation'",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"$",
"resolveInfo",
"->",
"fieldNodes",
"as",
"$",
"fieldNode",
")",
"{",
"$",
"deferDirective",
"=",
"ASTHelper",
"::",
"directiveDefinition",
"(",
"$",
"fieldNode",
",",
"'defer'",
")",
";",
"if",
"(",
"!",
"$",
"deferDirective",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"ASTHelper",
"::",
"directiveArgValue",
"(",
"$",
"deferDirective",
",",
"'if'",
",",
"true",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"skipDirective",
"=",
"ASTHelper",
"::",
"directiveDefinition",
"(",
"$",
"fieldNode",
",",
"'skip'",
")",
";",
"$",
"includeDirective",
"=",
"ASTHelper",
"::",
"directiveDefinition",
"(",
"$",
"fieldNode",
",",
"'include'",
")",
";",
"$",
"shouldSkip",
"=",
"$",
"skipDirective",
"?",
"ASTHelper",
"::",
"directiveArgValue",
"(",
"$",
"skipDirective",
",",
"'if'",
",",
"false",
")",
":",
"false",
";",
"$",
"shouldInclude",
"=",
"$",
"includeDirective",
"?",
"ASTHelper",
"::",
"directiveArgValue",
"(",
"$",
"includeDirective",
",",
"'if'",
",",
"false",
")",
":",
"false",
";",
"if",
"(",
"$",
"shouldSkip",
"||",
"$",
"shouldInclude",
")",
"{",
"return",
"false",
";",
"}",
"}",
"if",
"(",
"$",
"fieldType",
"instanceof",
"NonNullTypeNode",
")",
"{",
"throw",
"new",
"ParseClientException",
"(",
"'The @defer directive cannot be placed on a Non-Nullable field.'",
")",
";",
"}",
"return",
"true",
";",
"}"
]
| Determine if field should be deferred.
@param \GraphQL\Language\AST\TypeNode $fieldType
@param \GraphQL\Type\Definition\ResolveInfo $resolveInfo
@return bool
@throws \Nuwave\Lighthouse\Exceptions\ParseClientException | [
"Determine",
"if",
"field",
"should",
"be",
"deferred",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Defer/DeferrableDirective.php#L86-L123 | train |
nuwave/lighthouse | src/Schema/Directives/CanDirective.php | CanDirective.handleField | public function handleField(FieldValue $value, Closure $next): FieldValue
{
$previousResolver = $value->getResolver();
return $next(
$value->setResolver(
function ($root, array $args, GraphQLContext $context, ResolveInfo $resolveInfo) use ($previousResolver) {
$gate = app(Gate::class);
$gateArguments = $this->getGateArguments();
if ($id = $args['id'] ?? null) {
/** @var \Illuminate\Database\Eloquent\Model $modelClass */
$modelClass = $this->getModelClass();
$gateArguments[0] = $modelClass::findOrFail($id);
}
$this->getAbilities()->each(
function (string $ability) use ($context, $gate, $gateArguments): void {
$this->authorize($context->user(), $gate, $ability, $gateArguments);
}
);
return call_user_func_array($previousResolver, func_get_args());
}
)
);
} | php | public function handleField(FieldValue $value, Closure $next): FieldValue
{
$previousResolver = $value->getResolver();
return $next(
$value->setResolver(
function ($root, array $args, GraphQLContext $context, ResolveInfo $resolveInfo) use ($previousResolver) {
$gate = app(Gate::class);
$gateArguments = $this->getGateArguments();
if ($id = $args['id'] ?? null) {
/** @var \Illuminate\Database\Eloquent\Model $modelClass */
$modelClass = $this->getModelClass();
$gateArguments[0] = $modelClass::findOrFail($id);
}
$this->getAbilities()->each(
function (string $ability) use ($context, $gate, $gateArguments): void {
$this->authorize($context->user(), $gate, $ability, $gateArguments);
}
);
return call_user_func_array($previousResolver, func_get_args());
}
)
);
} | [
"public",
"function",
"handleField",
"(",
"FieldValue",
"$",
"value",
",",
"Closure",
"$",
"next",
")",
":",
"FieldValue",
"{",
"$",
"previousResolver",
"=",
"$",
"value",
"->",
"getResolver",
"(",
")",
";",
"return",
"$",
"next",
"(",
"$",
"value",
"->",
"setResolver",
"(",
"function",
"(",
"$",
"root",
",",
"array",
"$",
"args",
",",
"GraphQLContext",
"$",
"context",
",",
"ResolveInfo",
"$",
"resolveInfo",
")",
"use",
"(",
"$",
"previousResolver",
")",
"{",
"$",
"gate",
"=",
"app",
"(",
"Gate",
"::",
"class",
")",
";",
"$",
"gateArguments",
"=",
"$",
"this",
"->",
"getGateArguments",
"(",
")",
";",
"if",
"(",
"$",
"id",
"=",
"$",
"args",
"[",
"'id'",
"]",
"??",
"null",
")",
"{",
"/** @var \\Illuminate\\Database\\Eloquent\\Model $modelClass */",
"$",
"modelClass",
"=",
"$",
"this",
"->",
"getModelClass",
"(",
")",
";",
"$",
"gateArguments",
"[",
"0",
"]",
"=",
"$",
"modelClass",
"::",
"findOrFail",
"(",
"$",
"id",
")",
";",
"}",
"$",
"this",
"->",
"getAbilities",
"(",
")",
"->",
"each",
"(",
"function",
"(",
"string",
"$",
"ability",
")",
"use",
"(",
"$",
"context",
",",
"$",
"gate",
",",
"$",
"gateArguments",
")",
":",
"void",
"{",
"$",
"this",
"->",
"authorize",
"(",
"$",
"context",
"->",
"user",
"(",
")",
",",
"$",
"gate",
",",
"$",
"ability",
",",
"$",
"gateArguments",
")",
";",
"}",
")",
";",
"return",
"call_user_func_array",
"(",
"$",
"previousResolver",
",",
"func_get_args",
"(",
")",
")",
";",
"}",
")",
")",
";",
"}"
]
| Ensure the user is authorized to access this field.
@param \Nuwave\Lighthouse\Schema\Values\FieldValue $value
@param \Closure $next
@return \Nuwave\Lighthouse\Schema\Values\FieldValue | [
"Ensure",
"the",
"user",
"is",
"authorized",
"to",
"access",
"this",
"field",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/Directives/CanDirective.php#L33-L60 | train |
nuwave/lighthouse | src/Execution/MutationExecutor.php | MutationExecutor.saveModelWithPotentialParent | protected static function saveModelWithPotentialParent(Model $model, Collection $args, ?Relation $parentRelation = null): Model
{
[$belongsTo, $remaining] = self::partitionArgsByRelationType(
new ReflectionClass($model),
$args,
BelongsTo::class
);
// Use all the remaining attributes and fill the model
$model->fill(
$remaining->all()
);
$belongsTo->each(function (array $nestedOperations, string $relationName) use ($model): void {
/** @var \Illuminate\Database\Eloquent\Relations\BelongsTo $relation */
$relation = $model->{$relationName}();
if ($create = $nestedOperations['create'] ?? false) {
$belongsToModel = self::executeCreate(
$relation->getModel()->newInstance(),
new Collection($create)
);
$relation->associate($belongsToModel);
}
if ($connect = $nestedOperations['connect'] ?? false) {
// Inverse can be hasOne or hasMany
/** @var \Illuminate\Database\Eloquent\Relations\BelongsTo $belongsTo */
$belongsTo = $model->{$relationName}();
$belongsTo->associate($connect);
}
if ($update = $nestedOperations['update'] ?? false) {
$belongsToModel = self::executeUpdate(
$relation->getModel()->newInstance(),
new Collection($update)
);
$relation->associate($belongsToModel);
}
// We proceed with disconnecting/deleting only if the given $values is truthy.
// There is no other information to be passed when issuing those operations,
// but GraphQL forces us to pass some value. It would be unintuitive for
// the end user if the given value had no effect on the execution.
if ($nestedOperations['disconnect'] ?? false) {
$relation->dissociate();
}
if ($nestedOperations['delete'] ?? false) {
$relation->delete();
}
});
if ($parentRelation && ! $parentRelation instanceof BelongsToMany) {
// If we are already resolving a nested create, we might
// already have an instance of the parent relation available.
// In that case, use it to set the current model as a child.
$parentRelation->save($model);
return $model;
}
$model->save();
if ($parentRelation instanceof BelongsToMany) {
$parentRelation->syncWithoutDetaching($model);
}
return $model;
} | php | protected static function saveModelWithPotentialParent(Model $model, Collection $args, ?Relation $parentRelation = null): Model
{
[$belongsTo, $remaining] = self::partitionArgsByRelationType(
new ReflectionClass($model),
$args,
BelongsTo::class
);
// Use all the remaining attributes and fill the model
$model->fill(
$remaining->all()
);
$belongsTo->each(function (array $nestedOperations, string $relationName) use ($model): void {
/** @var \Illuminate\Database\Eloquent\Relations\BelongsTo $relation */
$relation = $model->{$relationName}();
if ($create = $nestedOperations['create'] ?? false) {
$belongsToModel = self::executeCreate(
$relation->getModel()->newInstance(),
new Collection($create)
);
$relation->associate($belongsToModel);
}
if ($connect = $nestedOperations['connect'] ?? false) {
// Inverse can be hasOne or hasMany
/** @var \Illuminate\Database\Eloquent\Relations\BelongsTo $belongsTo */
$belongsTo = $model->{$relationName}();
$belongsTo->associate($connect);
}
if ($update = $nestedOperations['update'] ?? false) {
$belongsToModel = self::executeUpdate(
$relation->getModel()->newInstance(),
new Collection($update)
);
$relation->associate($belongsToModel);
}
// We proceed with disconnecting/deleting only if the given $values is truthy.
// There is no other information to be passed when issuing those operations,
// but GraphQL forces us to pass some value. It would be unintuitive for
// the end user if the given value had no effect on the execution.
if ($nestedOperations['disconnect'] ?? false) {
$relation->dissociate();
}
if ($nestedOperations['delete'] ?? false) {
$relation->delete();
}
});
if ($parentRelation && ! $parentRelation instanceof BelongsToMany) {
// If we are already resolving a nested create, we might
// already have an instance of the parent relation available.
// In that case, use it to set the current model as a child.
$parentRelation->save($model);
return $model;
}
$model->save();
if ($parentRelation instanceof BelongsToMany) {
$parentRelation->syncWithoutDetaching($model);
}
return $model;
} | [
"protected",
"static",
"function",
"saveModelWithPotentialParent",
"(",
"Model",
"$",
"model",
",",
"Collection",
"$",
"args",
",",
"?",
"Relation",
"$",
"parentRelation",
"=",
"null",
")",
":",
"Model",
"{",
"[",
"$",
"belongsTo",
",",
"$",
"remaining",
"]",
"=",
"self",
"::",
"partitionArgsByRelationType",
"(",
"new",
"ReflectionClass",
"(",
"$",
"model",
")",
",",
"$",
"args",
",",
"BelongsTo",
"::",
"class",
")",
";",
"// Use all the remaining attributes and fill the model",
"$",
"model",
"->",
"fill",
"(",
"$",
"remaining",
"->",
"all",
"(",
")",
")",
";",
"$",
"belongsTo",
"->",
"each",
"(",
"function",
"(",
"array",
"$",
"nestedOperations",
",",
"string",
"$",
"relationName",
")",
"use",
"(",
"$",
"model",
")",
":",
"void",
"{",
"/** @var \\Illuminate\\Database\\Eloquent\\Relations\\BelongsTo $relation */",
"$",
"relation",
"=",
"$",
"model",
"->",
"{",
"$",
"relationName",
"}",
"(",
")",
";",
"if",
"(",
"$",
"create",
"=",
"$",
"nestedOperations",
"[",
"'create'",
"]",
"??",
"false",
")",
"{",
"$",
"belongsToModel",
"=",
"self",
"::",
"executeCreate",
"(",
"$",
"relation",
"->",
"getModel",
"(",
")",
"->",
"newInstance",
"(",
")",
",",
"new",
"Collection",
"(",
"$",
"create",
")",
")",
";",
"$",
"relation",
"->",
"associate",
"(",
"$",
"belongsToModel",
")",
";",
"}",
"if",
"(",
"$",
"connect",
"=",
"$",
"nestedOperations",
"[",
"'connect'",
"]",
"??",
"false",
")",
"{",
"// Inverse can be hasOne or hasMany",
"/** @var \\Illuminate\\Database\\Eloquent\\Relations\\BelongsTo $belongsTo */",
"$",
"belongsTo",
"=",
"$",
"model",
"->",
"{",
"$",
"relationName",
"}",
"(",
")",
";",
"$",
"belongsTo",
"->",
"associate",
"(",
"$",
"connect",
")",
";",
"}",
"if",
"(",
"$",
"update",
"=",
"$",
"nestedOperations",
"[",
"'update'",
"]",
"??",
"false",
")",
"{",
"$",
"belongsToModel",
"=",
"self",
"::",
"executeUpdate",
"(",
"$",
"relation",
"->",
"getModel",
"(",
")",
"->",
"newInstance",
"(",
")",
",",
"new",
"Collection",
"(",
"$",
"update",
")",
")",
";",
"$",
"relation",
"->",
"associate",
"(",
"$",
"belongsToModel",
")",
";",
"}",
"// We proceed with disconnecting/deleting only if the given $values is truthy.",
"// There is no other information to be passed when issuing those operations,",
"// but GraphQL forces us to pass some value. It would be unintuitive for",
"// the end user if the given value had no effect on the execution.",
"if",
"(",
"$",
"nestedOperations",
"[",
"'disconnect'",
"]",
"??",
"false",
")",
"{",
"$",
"relation",
"->",
"dissociate",
"(",
")",
";",
"}",
"if",
"(",
"$",
"nestedOperations",
"[",
"'delete'",
"]",
"??",
"false",
")",
"{",
"$",
"relation",
"->",
"delete",
"(",
")",
";",
"}",
"}",
")",
";",
"if",
"(",
"$",
"parentRelation",
"&&",
"!",
"$",
"parentRelation",
"instanceof",
"BelongsToMany",
")",
"{",
"// If we are already resolving a nested create, we might",
"// already have an instance of the parent relation available.",
"// In that case, use it to set the current model as a child.",
"$",
"parentRelation",
"->",
"save",
"(",
"$",
"model",
")",
";",
"return",
"$",
"model",
";",
"}",
"$",
"model",
"->",
"save",
"(",
")",
";",
"if",
"(",
"$",
"parentRelation",
"instanceof",
"BelongsToMany",
")",
"{",
"$",
"parentRelation",
"->",
"syncWithoutDetaching",
"(",
"$",
"model",
")",
";",
"}",
"return",
"$",
"model",
";",
"}"
]
| Save a model that maybe has a parent.
@param \Illuminate\Database\Eloquent\Model $model
@param \Illuminate\Support\Collection $args
@param \Illuminate\Database\Eloquent\Relations\Relation|null $parentRelation
@return \Illuminate\Database\Eloquent\Model | [
"Save",
"a",
"model",
"that",
"maybe",
"has",
"a",
"parent",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Execution/MutationExecutor.php#L111-L180 | train |
nuwave/lighthouse | src/Execution/MutationExecutor.php | MutationExecutor.handleMultiRelationCreate | protected static function handleMultiRelationCreate(Collection $multiValues, Relation $relation): void
{
$multiValues->each(function ($singleValues) use ($relation): void {
self::handleSingleRelationCreate(new Collection($singleValues), $relation);
});
} | php | protected static function handleMultiRelationCreate(Collection $multiValues, Relation $relation): void
{
$multiValues->each(function ($singleValues) use ($relation): void {
self::handleSingleRelationCreate(new Collection($singleValues), $relation);
});
} | [
"protected",
"static",
"function",
"handleMultiRelationCreate",
"(",
"Collection",
"$",
"multiValues",
",",
"Relation",
"$",
"relation",
")",
":",
"void",
"{",
"$",
"multiValues",
"->",
"each",
"(",
"function",
"(",
"$",
"singleValues",
")",
"use",
"(",
"$",
"relation",
")",
":",
"void",
"{",
"self",
"::",
"handleSingleRelationCreate",
"(",
"new",
"Collection",
"(",
"$",
"singleValues",
")",
",",
"$",
"relation",
")",
";",
"}",
")",
";",
"}"
]
| Handle the creation with multiple relations.
@param \Illuminate\Support\Collection $multiValues
@param \Illuminate\Database\Eloquent\Relations\Relation $relation
@return void | [
"Handle",
"the",
"creation",
"with",
"multiple",
"relations",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Execution/MutationExecutor.php#L189-L194 | train |
nuwave/lighthouse | src/Execution/MutationExecutor.php | MutationExecutor.handleSingleRelationCreate | protected static function handleSingleRelationCreate(Collection $singleValues, Relation $relation): void
{
self::executeCreate(
$relation->getModel()->newInstance(),
$singleValues,
$relation
);
} | php | protected static function handleSingleRelationCreate(Collection $singleValues, Relation $relation): void
{
self::executeCreate(
$relation->getModel()->newInstance(),
$singleValues,
$relation
);
} | [
"protected",
"static",
"function",
"handleSingleRelationCreate",
"(",
"Collection",
"$",
"singleValues",
",",
"Relation",
"$",
"relation",
")",
":",
"void",
"{",
"self",
"::",
"executeCreate",
"(",
"$",
"relation",
"->",
"getModel",
"(",
")",
"->",
"newInstance",
"(",
")",
",",
"$",
"singleValues",
",",
"$",
"relation",
")",
";",
"}"
]
| Handle the creation with a single relation.
@param \Illuminate\Support\Collection $singleValues
@param \Illuminate\Database\Eloquent\Relations\Relation $relation
@return void | [
"Handle",
"the",
"creation",
"with",
"a",
"single",
"relation",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Execution/MutationExecutor.php#L203-L210 | train |
nuwave/lighthouse | src/Execution/MutationExecutor.php | MutationExecutor.partitionArgsByRelationType | protected static function partitionArgsByRelationType(ReflectionClass $modelReflection, Collection $args, string $relationClass): Collection
{
return $args->partition(
function ($value, string $key) use ($modelReflection, $relationClass): bool {
if (! $modelReflection->hasMethod($key)) {
return false;
}
$relationMethodCandidate = $modelReflection->getMethod($key);
if (! $returnType = $relationMethodCandidate->getReturnType()) {
return false;
}
if (! $returnType instanceof ReflectionNamedType) {
return false;
}
return $relationClass === $returnType->getName();
}
);
} | php | protected static function partitionArgsByRelationType(ReflectionClass $modelReflection, Collection $args, string $relationClass): Collection
{
return $args->partition(
function ($value, string $key) use ($modelReflection, $relationClass): bool {
if (! $modelReflection->hasMethod($key)) {
return false;
}
$relationMethodCandidate = $modelReflection->getMethod($key);
if (! $returnType = $relationMethodCandidate->getReturnType()) {
return false;
}
if (! $returnType instanceof ReflectionNamedType) {
return false;
}
return $relationClass === $returnType->getName();
}
);
} | [
"protected",
"static",
"function",
"partitionArgsByRelationType",
"(",
"ReflectionClass",
"$",
"modelReflection",
",",
"Collection",
"$",
"args",
",",
"string",
"$",
"relationClass",
")",
":",
"Collection",
"{",
"return",
"$",
"args",
"->",
"partition",
"(",
"function",
"(",
"$",
"value",
",",
"string",
"$",
"key",
")",
"use",
"(",
"$",
"modelReflection",
",",
"$",
"relationClass",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"$",
"modelReflection",
"->",
"hasMethod",
"(",
"$",
"key",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"relationMethodCandidate",
"=",
"$",
"modelReflection",
"->",
"getMethod",
"(",
"$",
"key",
")",
";",
"if",
"(",
"!",
"$",
"returnType",
"=",
"$",
"relationMethodCandidate",
"->",
"getReturnType",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"returnType",
"instanceof",
"ReflectionNamedType",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"relationClass",
"===",
"$",
"returnType",
"->",
"getName",
"(",
")",
";",
"}",
")",
";",
"}"
]
| Extract all the arguments that correspond to a relation of a certain type on the model.
For example, if the args input looks like this:
[
'comments' =>
['foo' => 'Bar'],
'name' => 'Ralf',
]
and the model has a method "comments" that returns a HasMany relationship,
the result will be:
[
[
'comments' =>
['foo' => 'Bar'],
],
[
'name' => 'Ralf',
]
]
@param \ReflectionClass $modelReflection
@param \Illuminate\Support\Collection $args
@param string $relationClass
@return \Illuminate\Support\Collection [relationshipArgs, remainingArgs] | [
"Extract",
"all",
"the",
"arguments",
"that",
"correspond",
"to",
"a",
"relation",
"of",
"a",
"certain",
"type",
"on",
"the",
"model",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Execution/MutationExecutor.php#L365-L385 | train |
nuwave/lighthouse | src/Schema/Directives/BuilderDirective.php | BuilderDirective.handleBuilder | public function handleBuilder($builder, $value)
{
return call_user_func(
$this->getResolverFromArgument('method'),
$builder,
$value,
$this->definitionNode
);
} | php | public function handleBuilder($builder, $value)
{
return call_user_func(
$this->getResolverFromArgument('method'),
$builder,
$value,
$this->definitionNode
);
} | [
"public",
"function",
"handleBuilder",
"(",
"$",
"builder",
",",
"$",
"value",
")",
"{",
"return",
"call_user_func",
"(",
"$",
"this",
"->",
"getResolverFromArgument",
"(",
"'method'",
")",
",",
"$",
"builder",
",",
"$",
"value",
",",
"$",
"this",
"->",
"definitionNode",
")",
";",
"}"
]
| Dynamically call a user-defined method to enhance the builder.
@param \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder $builder
@param mixed $value
@return \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder | [
"Dynamically",
"call",
"a",
"user",
"-",
"defined",
"method",
"to",
"enhance",
"the",
"builder",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/Directives/BuilderDirective.php#L26-L34 | train |
nuwave/lighthouse | src/Subscriptions/Broadcasters/PusherBroadcaster.php | PusherBroadcaster.hook | public function hook(Request $request): JsonResponse
{
(new Collection($request->input('events', [])))
->filter(function ($event): bool {
return Arr::get($event, 'name') === 'channel_vacated';
})
->each(function (array $event): void {
$this->storage->deleteSubscriber(
Arr::get($event, 'channel')
);
});
return response()->json(['message' => 'okay']);
} | php | public function hook(Request $request): JsonResponse
{
(new Collection($request->input('events', [])))
->filter(function ($event): bool {
return Arr::get($event, 'name') === 'channel_vacated';
})
->each(function (array $event): void {
$this->storage->deleteSubscriber(
Arr::get($event, 'channel')
);
});
return response()->json(['message' => 'okay']);
} | [
"public",
"function",
"hook",
"(",
"Request",
"$",
"request",
")",
":",
"JsonResponse",
"{",
"(",
"new",
"Collection",
"(",
"$",
"request",
"->",
"input",
"(",
"'events'",
",",
"[",
"]",
")",
")",
")",
"->",
"filter",
"(",
"function",
"(",
"$",
"event",
")",
":",
"bool",
"{",
"return",
"Arr",
"::",
"get",
"(",
"$",
"event",
",",
"'name'",
")",
"===",
"'channel_vacated'",
";",
"}",
")",
"->",
"each",
"(",
"function",
"(",
"array",
"$",
"event",
")",
":",
"void",
"{",
"$",
"this",
"->",
"storage",
"->",
"deleteSubscriber",
"(",
"Arr",
"::",
"get",
"(",
"$",
"event",
",",
"'channel'",
")",
")",
";",
"}",
")",
";",
"return",
"response",
"(",
")",
"->",
"json",
"(",
"[",
"'message'",
"=>",
"'okay'",
"]",
")",
";",
"}"
]
| Handle subscription web hook.
@param \Illuminate\Http\Request $request
@return \Illuminate\Http\JsonResponse | [
"Handle",
"subscription",
"web",
"hook",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Subscriptions/Broadcasters/PusherBroadcaster.php#L74-L87 | train |
nuwave/lighthouse | src/Execution/DataLoader/BatchLoader.php | BatchLoader.instance | public static function instance(string $loaderClass, array $pathToField, array $constructorArgs = []): self
{
// The path to the field serves as the unique key for the instance
$instanceName = static::instanceKey($pathToField);
// If we are resolving a batched query, we need to assign each
// query a uniquely indexed instance
/** @var \Nuwave\Lighthouse\Execution\GraphQLRequest $graphQLRequest */
$graphQLRequest = app(GraphQLRequest::class);
if ($graphQLRequest->isBatched()) {
$currentBatchIndex = $graphQLRequest->batchIndex();
$instanceName = "batch_{$currentBatchIndex}_{$instanceName}";
}
// Only register a new instance if it is not already bound
$instance = app()->bound($instanceName)
? app($instanceName)
: app()->instance(
$instanceName,
app()->makeWith($loaderClass, $constructorArgs)
);
if (! $instance instanceof self) {
throw new Exception(
"The given class '$loaderClass' must resolve to an instance of Nuwave\Lighthouse\Execution\DataLoader\BatchLoader"
);
}
return $instance;
} | php | public static function instance(string $loaderClass, array $pathToField, array $constructorArgs = []): self
{
// The path to the field serves as the unique key for the instance
$instanceName = static::instanceKey($pathToField);
// If we are resolving a batched query, we need to assign each
// query a uniquely indexed instance
/** @var \Nuwave\Lighthouse\Execution\GraphQLRequest $graphQLRequest */
$graphQLRequest = app(GraphQLRequest::class);
if ($graphQLRequest->isBatched()) {
$currentBatchIndex = $graphQLRequest->batchIndex();
$instanceName = "batch_{$currentBatchIndex}_{$instanceName}";
}
// Only register a new instance if it is not already bound
$instance = app()->bound($instanceName)
? app($instanceName)
: app()->instance(
$instanceName,
app()->makeWith($loaderClass, $constructorArgs)
);
if (! $instance instanceof self) {
throw new Exception(
"The given class '$loaderClass' must resolve to an instance of Nuwave\Lighthouse\Execution\DataLoader\BatchLoader"
);
}
return $instance;
} | [
"public",
"static",
"function",
"instance",
"(",
"string",
"$",
"loaderClass",
",",
"array",
"$",
"pathToField",
",",
"array",
"$",
"constructorArgs",
"=",
"[",
"]",
")",
":",
"self",
"{",
"// The path to the field serves as the unique key for the instance",
"$",
"instanceName",
"=",
"static",
"::",
"instanceKey",
"(",
"$",
"pathToField",
")",
";",
"// If we are resolving a batched query, we need to assign each",
"// query a uniquely indexed instance",
"/** @var \\Nuwave\\Lighthouse\\Execution\\GraphQLRequest $graphQLRequest */",
"$",
"graphQLRequest",
"=",
"app",
"(",
"GraphQLRequest",
"::",
"class",
")",
";",
"if",
"(",
"$",
"graphQLRequest",
"->",
"isBatched",
"(",
")",
")",
"{",
"$",
"currentBatchIndex",
"=",
"$",
"graphQLRequest",
"->",
"batchIndex",
"(",
")",
";",
"$",
"instanceName",
"=",
"\"batch_{$currentBatchIndex}_{$instanceName}\"",
";",
"}",
"// Only register a new instance if it is not already bound",
"$",
"instance",
"=",
"app",
"(",
")",
"->",
"bound",
"(",
"$",
"instanceName",
")",
"?",
"app",
"(",
"$",
"instanceName",
")",
":",
"app",
"(",
")",
"->",
"instance",
"(",
"$",
"instanceName",
",",
"app",
"(",
")",
"->",
"makeWith",
"(",
"$",
"loaderClass",
",",
"$",
"constructorArgs",
")",
")",
";",
"if",
"(",
"!",
"$",
"instance",
"instanceof",
"self",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"The given class '$loaderClass' must resolve to an instance of Nuwave\\Lighthouse\\Execution\\DataLoader\\BatchLoader\"",
")",
";",
"}",
"return",
"$",
"instance",
";",
"}"
]
| Return an instance of a BatchLoader for a specific field.
@param string $loaderClass The class name of the concrete BatchLoader to instantiate
@param mixed[] $pathToField Path to the GraphQL field from the root, is used as a key for BatchLoader instances
@param mixed[] $constructorArgs Those arguments are passed to the constructor of the new BatchLoader instance
@return static
@throws \Exception | [
"Return",
"an",
"instance",
"of",
"a",
"BatchLoader",
"for",
"a",
"specific",
"field",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Execution/DataLoader/BatchLoader.php#L48-L77 | train |
nuwave/lighthouse | src/Execution/DataLoader/BatchLoader.php | BatchLoader.instanceKey | public static function instanceKey(array $path): string
{
return (new Collection($path))
->filter(function ($path): bool {
// Ignore numeric path entries, as those signify an array of fields.
// Combining the queries for those is the very purpose of the
// batch loader, so they must not be included.
return ! is_numeric($path);
})
->implode('_');
} | php | public static function instanceKey(array $path): string
{
return (new Collection($path))
->filter(function ($path): bool {
// Ignore numeric path entries, as those signify an array of fields.
// Combining the queries for those is the very purpose of the
// batch loader, so they must not be included.
return ! is_numeric($path);
})
->implode('_');
} | [
"public",
"static",
"function",
"instanceKey",
"(",
"array",
"$",
"path",
")",
":",
"string",
"{",
"return",
"(",
"new",
"Collection",
"(",
"$",
"path",
")",
")",
"->",
"filter",
"(",
"function",
"(",
"$",
"path",
")",
":",
"bool",
"{",
"// Ignore numeric path entries, as those signify an array of fields.",
"// Combining the queries for those is the very purpose of the",
"// batch loader, so they must not be included.",
"return",
"!",
"is_numeric",
"(",
"$",
"path",
")",
";",
"}",
")",
"->",
"implode",
"(",
"'_'",
")",
";",
"}"
]
| Generate a unique key for the instance, using the path in the query.
@param mixed[] $path
@return string | [
"Generate",
"a",
"unique",
"key",
"for",
"the",
"instance",
"using",
"the",
"path",
"in",
"the",
"query",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Execution/DataLoader/BatchLoader.php#L85-L95 | train |
nuwave/lighthouse | src/Execution/DataLoader/BatchLoader.php | BatchLoader.load | public function load($key, array $metaInfo = []): Deferred
{
$key = $this->buildKey($key);
$this->keys[$key] = $metaInfo;
return new Deferred(function () use ($key) {
if (! $this->hasLoaded) {
$this->results = $this->resolve();
$this->hasLoaded = true;
}
return $this->results[$key];
});
} | php | public function load($key, array $metaInfo = []): Deferred
{
$key = $this->buildKey($key);
$this->keys[$key] = $metaInfo;
return new Deferred(function () use ($key) {
if (! $this->hasLoaded) {
$this->results = $this->resolve();
$this->hasLoaded = true;
}
return $this->results[$key];
});
} | [
"public",
"function",
"load",
"(",
"$",
"key",
",",
"array",
"$",
"metaInfo",
"=",
"[",
"]",
")",
":",
"Deferred",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"buildKey",
"(",
"$",
"key",
")",
";",
"$",
"this",
"->",
"keys",
"[",
"$",
"key",
"]",
"=",
"$",
"metaInfo",
";",
"return",
"new",
"Deferred",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasLoaded",
")",
"{",
"$",
"this",
"->",
"results",
"=",
"$",
"this",
"->",
"resolve",
"(",
")",
";",
"$",
"this",
"->",
"hasLoaded",
"=",
"true",
";",
"}",
"return",
"$",
"this",
"->",
"results",
"[",
"$",
"key",
"]",
";",
"}",
")",
";",
"}"
]
| Load object by key.
@param mixed $key
@param mixed[] $metaInfo
@return \GraphQL\Deferred | [
"Load",
"object",
"by",
"key",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Execution/DataLoader/BatchLoader.php#L104-L117 | train |
nuwave/lighthouse | src/Support/Http/Middleware/AcceptJson.php | AcceptJson.handle | public function handle(Request $request, Closure $next)
{
$request->headers->set('Accept', 'application/json');
return $next($request);
} | php | public function handle(Request $request, Closure $next)
{
$request->headers->set('Accept', 'application/json');
return $next($request);
} | [
"public",
"function",
"handle",
"(",
"Request",
"$",
"request",
",",
"Closure",
"$",
"next",
")",
"{",
"$",
"request",
"->",
"headers",
"->",
"set",
"(",
"'Accept'",
",",
"'application/json'",
")",
";",
"return",
"$",
"next",
"(",
"$",
"request",
")",
";",
"}"
]
| Force the Accept header of the request.
@param \Illuminate\Http\Request $request
@param \Closure $next
@return \Illuminate\Http\JsonResponse | [
"Force",
"the",
"Accept",
"header",
"of",
"the",
"request",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Support/Http/Middleware/AcceptJson.php#L26-L31 | train |
nuwave/lighthouse | src/Support/Http/Responses/ResponseStream.php | ResponseStream.chunk | protected function chunk(array $data, bool $terminating): string
{
$json = json_encode($data, 0);
$length = $terminating
? strlen($json)
: strlen($json.self::EOL);
$chunk = implode(self::EOL, [
'Content-Type: application/json',
'Content-Length: '.$length,
null,
$json,
null,
]);
return $this->boundary().$chunk;
} | php | protected function chunk(array $data, bool $terminating): string
{
$json = json_encode($data, 0);
$length = $terminating
? strlen($json)
: strlen($json.self::EOL);
$chunk = implode(self::EOL, [
'Content-Type: application/json',
'Content-Length: '.$length,
null,
$json,
null,
]);
return $this->boundary().$chunk;
} | [
"protected",
"function",
"chunk",
"(",
"array",
"$",
"data",
",",
"bool",
"$",
"terminating",
")",
":",
"string",
"{",
"$",
"json",
"=",
"json_encode",
"(",
"$",
"data",
",",
"0",
")",
";",
"$",
"length",
"=",
"$",
"terminating",
"?",
"strlen",
"(",
"$",
"json",
")",
":",
"strlen",
"(",
"$",
"json",
".",
"self",
"::",
"EOL",
")",
";",
"$",
"chunk",
"=",
"implode",
"(",
"self",
"::",
"EOL",
",",
"[",
"'Content-Type: application/json'",
",",
"'Content-Length: '",
".",
"$",
"length",
",",
"null",
",",
"$",
"json",
",",
"null",
",",
"]",
")",
";",
"return",
"$",
"this",
"->",
"boundary",
"(",
")",
".",
"$",
"chunk",
";",
"}"
]
| Format chunked data.
@param array $data
@param bool $terminating
@return string | [
"Format",
"chunked",
"data",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Support/Http/Responses/ResponseStream.php#L86-L102 | train |
nuwave/lighthouse | src/Support/Http/Responses/ResponseStream.php | ResponseStream.emit | protected function emit(string $chunk): void
{
echo $chunk;
$this->flush(Closure::fromCallable('ob_flush'));
$this->flush(Closure::fromCallable('flush'));
} | php | protected function emit(string $chunk): void
{
echo $chunk;
$this->flush(Closure::fromCallable('ob_flush'));
$this->flush(Closure::fromCallable('flush'));
} | [
"protected",
"function",
"emit",
"(",
"string",
"$",
"chunk",
")",
":",
"void",
"{",
"echo",
"$",
"chunk",
";",
"$",
"this",
"->",
"flush",
"(",
"Closure",
"::",
"fromCallable",
"(",
"'ob_flush'",
")",
")",
";",
"$",
"this",
"->",
"flush",
"(",
"Closure",
"::",
"fromCallable",
"(",
"'flush'",
")",
")",
";",
"}"
]
| Stream chunked data to client.
@param string $chunk
@return void | [
"Stream",
"chunked",
"data",
"to",
"client",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Support/Http/Responses/ResponseStream.php#L110-L116 | train |
nuwave/lighthouse | src/Subscriptions/SubscriptionRegistry.php | SubscriptionRegistry.subscriptions | public function subscriptions(Subscriber $subscriber): Collection
{
// A subscription can be fired w/out a request so we must make
// sure the schema has been generated.
$this->graphQL->prepSchema();
return (new Collection($subscriber->query->definitions))
->filter(function (Node $node): bool {
return $node instanceof OperationDefinitionNode;
})
->filter(function (OperationDefinitionNode $node): bool {
return $node->operation === 'subscription';
})
->flatMap(function (OperationDefinitionNode $node) {
return (new Collection($node->selectionSet->selections))
->map(function (FieldNode $field): string {
return $field->name->value;
})
->toArray();
})
->map(function ($subscriptionField): GraphQLSubscription {
return Arr::get(
$this->subscriptions,
$subscriptionField,
new NotFoundSubscription
);
});
} | php | public function subscriptions(Subscriber $subscriber): Collection
{
// A subscription can be fired w/out a request so we must make
// sure the schema has been generated.
$this->graphQL->prepSchema();
return (new Collection($subscriber->query->definitions))
->filter(function (Node $node): bool {
return $node instanceof OperationDefinitionNode;
})
->filter(function (OperationDefinitionNode $node): bool {
return $node->operation === 'subscription';
})
->flatMap(function (OperationDefinitionNode $node) {
return (new Collection($node->selectionSet->selections))
->map(function (FieldNode $field): string {
return $field->name->value;
})
->toArray();
})
->map(function ($subscriptionField): GraphQLSubscription {
return Arr::get(
$this->subscriptions,
$subscriptionField,
new NotFoundSubscription
);
});
} | [
"public",
"function",
"subscriptions",
"(",
"Subscriber",
"$",
"subscriber",
")",
":",
"Collection",
"{",
"// A subscription can be fired w/out a request so we must make",
"// sure the schema has been generated.",
"$",
"this",
"->",
"graphQL",
"->",
"prepSchema",
"(",
")",
";",
"return",
"(",
"new",
"Collection",
"(",
"$",
"subscriber",
"->",
"query",
"->",
"definitions",
")",
")",
"->",
"filter",
"(",
"function",
"(",
"Node",
"$",
"node",
")",
":",
"bool",
"{",
"return",
"$",
"node",
"instanceof",
"OperationDefinitionNode",
";",
"}",
")",
"->",
"filter",
"(",
"function",
"(",
"OperationDefinitionNode",
"$",
"node",
")",
":",
"bool",
"{",
"return",
"$",
"node",
"->",
"operation",
"===",
"'subscription'",
";",
"}",
")",
"->",
"flatMap",
"(",
"function",
"(",
"OperationDefinitionNode",
"$",
"node",
")",
"{",
"return",
"(",
"new",
"Collection",
"(",
"$",
"node",
"->",
"selectionSet",
"->",
"selections",
")",
")",
"->",
"map",
"(",
"function",
"(",
"FieldNode",
"$",
"field",
")",
":",
"string",
"{",
"return",
"$",
"field",
"->",
"name",
"->",
"value",
";",
"}",
")",
"->",
"toArray",
"(",
")",
";",
"}",
")",
"->",
"map",
"(",
"function",
"(",
"$",
"subscriptionField",
")",
":",
"GraphQLSubscription",
"{",
"return",
"Arr",
"::",
"get",
"(",
"$",
"this",
"->",
"subscriptions",
",",
"$",
"subscriptionField",
",",
"new",
"NotFoundSubscription",
")",
";",
"}",
")",
";",
"}"
]
| Get registered subscriptions.
@param \Nuwave\Lighthouse\Subscriptions\Subscriber $subscriber
@return \Illuminate\Support\Collection | [
"Get",
"registered",
"subscriptions",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Subscriptions/SubscriptionRegistry.php#L131-L158 | train |
nuwave/lighthouse | src/Schema/AST/DocumentAST.php | DocumentAST.typeExtensionUniqueKey | protected function typeExtensionUniqueKey(TypeExtensionNode $typeExtensionNode): string
{
$fieldNames = (new Collection($typeExtensionNode->fields))
->map(function ($field): string {
return $field->name->value;
})
->implode(':');
return $typeExtensionNode->name->value.$fieldNames;
} | php | protected function typeExtensionUniqueKey(TypeExtensionNode $typeExtensionNode): string
{
$fieldNames = (new Collection($typeExtensionNode->fields))
->map(function ($field): string {
return $field->name->value;
})
->implode(':');
return $typeExtensionNode->name->value.$fieldNames;
} | [
"protected",
"function",
"typeExtensionUniqueKey",
"(",
"TypeExtensionNode",
"$",
"typeExtensionNode",
")",
":",
"string",
"{",
"$",
"fieldNames",
"=",
"(",
"new",
"Collection",
"(",
"$",
"typeExtensionNode",
"->",
"fields",
")",
")",
"->",
"map",
"(",
"function",
"(",
"$",
"field",
")",
":",
"string",
"{",
"return",
"$",
"field",
"->",
"name",
"->",
"value",
";",
"}",
")",
"->",
"implode",
"(",
"':'",
")",
";",
"return",
"$",
"typeExtensionNode",
"->",
"name",
"->",
"value",
".",
"$",
"fieldNames",
";",
"}"
]
| Return a unique key that identifies a type extension.
@param \GraphQL\Language\AST\TypeExtensionNode $typeExtensionNode
@return string | [
"Return",
"a",
"unique",
"key",
"that",
"identifies",
"a",
"type",
"extension",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/AST/DocumentAST.php#L71-L80 | train |
nuwave/lighthouse | src/Schema/AST/DocumentAST.php | DocumentAST.fromSource | public static function fromSource(string $schema): self
{
try {
return new static(
Parser::parse(
$schema,
// Ignore location since it only bloats the AST
['noLocation' => true]
)
);
} catch (SyntaxError $syntaxError) {
// Throw our own error class instead, since otherwise a schema definition
// error would get rendered to the Client.
throw new ParseException(
$syntaxError->getMessage()
);
}
} | php | public static function fromSource(string $schema): self
{
try {
return new static(
Parser::parse(
$schema,
// Ignore location since it only bloats the AST
['noLocation' => true]
)
);
} catch (SyntaxError $syntaxError) {
// Throw our own error class instead, since otherwise a schema definition
// error would get rendered to the Client.
throw new ParseException(
$syntaxError->getMessage()
);
}
} | [
"public",
"static",
"function",
"fromSource",
"(",
"string",
"$",
"schema",
")",
":",
"self",
"{",
"try",
"{",
"return",
"new",
"static",
"(",
"Parser",
"::",
"parse",
"(",
"$",
"schema",
",",
"// Ignore location since it only bloats the AST",
"[",
"'noLocation'",
"=>",
"true",
"]",
")",
")",
";",
"}",
"catch",
"(",
"SyntaxError",
"$",
"syntaxError",
")",
"{",
"// Throw our own error class instead, since otherwise a schema definition",
"// error would get rendered to the Client.",
"throw",
"new",
"ParseException",
"(",
"$",
"syntaxError",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}"
]
| Create a new DocumentAST instance from a schema.
@param string $schema
@return static
@throws \Nuwave\Lighthouse\Exceptions\ParseException | [
"Create",
"a",
"new",
"DocumentAST",
"instance",
"from",
"a",
"schema",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/AST/DocumentAST.php#L90-L107 | train |
nuwave/lighthouse | src/Schema/AST/DocumentAST.php | DocumentAST.serialize | public function serialize(): string
{
return serialize(
$this->definitionMap
->mapWithKeys(function (DefinitionNode $node, string $key): array {
return [$key => AST::toArray($node)];
})
);
} | php | public function serialize(): string
{
return serialize(
$this->definitionMap
->mapWithKeys(function (DefinitionNode $node, string $key): array {
return [$key => AST::toArray($node)];
})
);
} | [
"public",
"function",
"serialize",
"(",
")",
":",
"string",
"{",
"return",
"serialize",
"(",
"$",
"this",
"->",
"definitionMap",
"->",
"mapWithKeys",
"(",
"function",
"(",
"DefinitionNode",
"$",
"node",
",",
"string",
"$",
"key",
")",
":",
"array",
"{",
"return",
"[",
"$",
"key",
"=>",
"AST",
"::",
"toArray",
"(",
"$",
"node",
")",
"]",
";",
"}",
")",
")",
";",
"}"
]
| Strip out irrelevant information to make serialization more efficient.
@return string | [
"Strip",
"out",
"irrelevant",
"information",
"to",
"make",
"serialization",
"more",
"efficient",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/AST/DocumentAST.php#L114-L122 | train |
nuwave/lighthouse | src/Schema/AST/DocumentAST.php | DocumentAST.unserialize | public function unserialize($serialized): void
{
$this->definitionMap = unserialize($serialized)
->mapWithKeys(function (array $node, string $key): array {
return [$key => AST::fromArray($node)];
});
} | php | public function unserialize($serialized): void
{
$this->definitionMap = unserialize($serialized)
->mapWithKeys(function (array $node, string $key): array {
return [$key => AST::fromArray($node)];
});
} | [
"public",
"function",
"unserialize",
"(",
"$",
"serialized",
")",
":",
"void",
"{",
"$",
"this",
"->",
"definitionMap",
"=",
"unserialize",
"(",
"$",
"serialized",
")",
"->",
"mapWithKeys",
"(",
"function",
"(",
"array",
"$",
"node",
",",
"string",
"$",
"key",
")",
":",
"array",
"{",
"return",
"[",
"$",
"key",
"=>",
"AST",
"::",
"fromArray",
"(",
"$",
"node",
")",
"]",
";",
"}",
")",
";",
"}"
]
| Construct from the string representation.
@param string $serialized
@return void | [
"Construct",
"from",
"the",
"string",
"representation",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/AST/DocumentAST.php#L130-L136 | train |
nuwave/lighthouse | src/Schema/AST/DocumentAST.php | DocumentAST.typeDefinitions | public function typeDefinitions(): Collection
{
return $this->definitionMap
->filter(function (DefinitionNode $node) {
return $node instanceof ScalarTypeDefinitionNode
|| $node instanceof ObjectTypeDefinitionNode
|| $node instanceof InterfaceTypeDefinitionNode
|| $node instanceof UnionTypeDefinitionNode
|| $node instanceof EnumTypeDefinitionNode
|| $node instanceof InputObjectTypeDefinitionNode;
});
} | php | public function typeDefinitions(): Collection
{
return $this->definitionMap
->filter(function (DefinitionNode $node) {
return $node instanceof ScalarTypeDefinitionNode
|| $node instanceof ObjectTypeDefinitionNode
|| $node instanceof InterfaceTypeDefinitionNode
|| $node instanceof UnionTypeDefinitionNode
|| $node instanceof EnumTypeDefinitionNode
|| $node instanceof InputObjectTypeDefinitionNode;
});
} | [
"public",
"function",
"typeDefinitions",
"(",
")",
":",
"Collection",
"{",
"return",
"$",
"this",
"->",
"definitionMap",
"->",
"filter",
"(",
"function",
"(",
"DefinitionNode",
"$",
"node",
")",
"{",
"return",
"$",
"node",
"instanceof",
"ScalarTypeDefinitionNode",
"||",
"$",
"node",
"instanceof",
"ObjectTypeDefinitionNode",
"||",
"$",
"node",
"instanceof",
"InterfaceTypeDefinitionNode",
"||",
"$",
"node",
"instanceof",
"UnionTypeDefinitionNode",
"||",
"$",
"node",
"instanceof",
"EnumTypeDefinitionNode",
"||",
"$",
"node",
"instanceof",
"InputObjectTypeDefinitionNode",
";",
"}",
")",
";",
"}"
]
| Get all type definitions from the document.
@return \Illuminate\Support\Collection<\GraphQL\Language\AST\TypeDefinitionNode> | [
"Get",
"all",
"type",
"definitions",
"from",
"the",
"document",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/AST/DocumentAST.php#L143-L154 | train |
nuwave/lighthouse | src/Schema/AST/DocumentAST.php | DocumentAST.extensionsForType | public function extensionsForType(string $extendedTypeName): Collection
{
return $this->typeExtensionsMap
->filter(function (TypeExtensionNode $typeExtension) use ($extendedTypeName): bool {
return $extendedTypeName === $typeExtension->name->value;
});
} | php | public function extensionsForType(string $extendedTypeName): Collection
{
return $this->typeExtensionsMap
->filter(function (TypeExtensionNode $typeExtension) use ($extendedTypeName): bool {
return $extendedTypeName === $typeExtension->name->value;
});
} | [
"public",
"function",
"extensionsForType",
"(",
"string",
"$",
"extendedTypeName",
")",
":",
"Collection",
"{",
"return",
"$",
"this",
"->",
"typeExtensionsMap",
"->",
"filter",
"(",
"function",
"(",
"TypeExtensionNode",
"$",
"typeExtension",
")",
"use",
"(",
"$",
"extendedTypeName",
")",
":",
"bool",
"{",
"return",
"$",
"extendedTypeName",
"===",
"$",
"typeExtension",
"->",
"name",
"->",
"value",
";",
"}",
")",
";",
"}"
]
| Get all extensions that apply to a named type.
@param string $extendedTypeName
@return \Illuminate\Support\Collection<\GraphQL\Language\AST\TypeExtensionNode> | [
"Get",
"all",
"extensions",
"that",
"apply",
"to",
"a",
"named",
"type",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/AST/DocumentAST.php#L172-L178 | train |
nuwave/lighthouse | src/Schema/AST/DocumentAST.php | DocumentAST.objectTypeDefinition | public function objectTypeDefinition(string $name): ?ObjectTypeDefinitionNode
{
return $this->objectTypeDefinitions()
->first(function (ObjectTypeDefinitionNode $objectType) use ($name): bool {
return $objectType->name->value === $name;
});
} | php | public function objectTypeDefinition(string $name): ?ObjectTypeDefinitionNode
{
return $this->objectTypeDefinitions()
->first(function (ObjectTypeDefinitionNode $objectType) use ($name): bool {
return $objectType->name->value === $name;
});
} | [
"public",
"function",
"objectTypeDefinition",
"(",
"string",
"$",
"name",
")",
":",
"?",
"ObjectTypeDefinitionNode",
"{",
"return",
"$",
"this",
"->",
"objectTypeDefinitions",
"(",
")",
"->",
"first",
"(",
"function",
"(",
"ObjectTypeDefinitionNode",
"$",
"objectType",
")",
"use",
"(",
"$",
"name",
")",
":",
"bool",
"{",
"return",
"$",
"objectType",
"->",
"name",
"->",
"value",
"===",
"$",
"name",
";",
"}",
")",
";",
"}"
]
| Get a single object type definition by name.
@param string $name
@return \GraphQL\Language\AST\ObjectTypeDefinitionNode|null | [
"Get",
"a",
"single",
"object",
"type",
"definition",
"by",
"name",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/AST/DocumentAST.php#L206-L212 | train |
nuwave/lighthouse | src/Schema/AST/DocumentAST.php | DocumentAST.definitionsByType | protected function definitionsByType(string $typeClassName): Collection
{
return $this->definitionMap
->filter(function (Node $node) use ($typeClassName) {
return $node instanceof $typeClassName;
});
} | php | protected function definitionsByType(string $typeClassName): Collection
{
return $this->definitionMap
->filter(function (Node $node) use ($typeClassName) {
return $node instanceof $typeClassName;
});
} | [
"protected",
"function",
"definitionsByType",
"(",
"string",
"$",
"typeClassName",
")",
":",
"Collection",
"{",
"return",
"$",
"this",
"->",
"definitionMap",
"->",
"filter",
"(",
"function",
"(",
"Node",
"$",
"node",
")",
"use",
"(",
"$",
"typeClassName",
")",
"{",
"return",
"$",
"node",
"instanceof",
"$",
"typeClassName",
";",
"}",
")",
";",
"}"
]
| Get all definitions of a given type.
@param string $typeClassName
@return \Illuminate\Support\Collection | [
"Get",
"all",
"definitions",
"of",
"a",
"given",
"type",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/AST/DocumentAST.php#L280-L286 | train |
nuwave/lighthouse | src/Schema/AST/DocumentAST.php | DocumentAST.addFieldToQueryType | public function addFieldToQueryType(FieldDefinitionNode $field): self
{
$query = $this->queryTypeDefinition();
$query->fields = ASTHelper::mergeNodeList($query->fields, [$field]);
$this->setDefinition($query);
return $this;
} | php | public function addFieldToQueryType(FieldDefinitionNode $field): self
{
$query = $this->queryTypeDefinition();
$query->fields = ASTHelper::mergeNodeList($query->fields, [$field]);
$this->setDefinition($query);
return $this;
} | [
"public",
"function",
"addFieldToQueryType",
"(",
"FieldDefinitionNode",
"$",
"field",
")",
":",
"self",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"queryTypeDefinition",
"(",
")",
";",
"$",
"query",
"->",
"fields",
"=",
"ASTHelper",
"::",
"mergeNodeList",
"(",
"$",
"query",
"->",
"fields",
",",
"[",
"$",
"field",
"]",
")",
";",
"$",
"this",
"->",
"setDefinition",
"(",
"$",
"query",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Add a single field to the query type.
@param \GraphQL\Language\AST\FieldDefinitionNode $field
@return $this | [
"Add",
"a",
"single",
"field",
"to",
"the",
"query",
"type",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/AST/DocumentAST.php#L294-L302 | train |
nuwave/lighthouse | src/Schema/Directives/SearchDirective.php | SearchDirective.handleBuilder | public function handleBuilder($builder, $value)
{
$within = $this->directiveArgValue('within');
/** @var \Illuminate\Database\Eloquent\Model $modelClass */
$modelClass = get_class(
$builder->getModel()
);
/** @var \Laravel\Scout\Builder $builder */
$builder = $modelClass::search($value);
if ($within !== null) {
$builder->within($within);
}
return $builder;
} | php | public function handleBuilder($builder, $value)
{
$within = $this->directiveArgValue('within');
/** @var \Illuminate\Database\Eloquent\Model $modelClass */
$modelClass = get_class(
$builder->getModel()
);
/** @var \Laravel\Scout\Builder $builder */
$builder = $modelClass::search($value);
if ($within !== null) {
$builder->within($within);
}
return $builder;
} | [
"public",
"function",
"handleBuilder",
"(",
"$",
"builder",
",",
"$",
"value",
")",
"{",
"$",
"within",
"=",
"$",
"this",
"->",
"directiveArgValue",
"(",
"'within'",
")",
";",
"/** @var \\Illuminate\\Database\\Eloquent\\Model $modelClass */",
"$",
"modelClass",
"=",
"get_class",
"(",
"$",
"builder",
"->",
"getModel",
"(",
")",
")",
";",
"/** @var \\Laravel\\Scout\\Builder $builder */",
"$",
"builder",
"=",
"$",
"modelClass",
"::",
"search",
"(",
"$",
"value",
")",
";",
"if",
"(",
"$",
"within",
"!==",
"null",
")",
"{",
"$",
"builder",
"->",
"within",
"(",
"$",
"within",
")",
";",
"}",
"return",
"$",
"builder",
";",
"}"
]
| Apply a scout search to the builder.
@param \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder $builder
@param mixed $value
@return \Laravel\Scout\Builder | [
"Apply",
"a",
"scout",
"search",
"to",
"the",
"builder",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/Directives/SearchDirective.php#L26-L43 | train |
nuwave/lighthouse | src/Support/DriverManager.php | DriverManager.driver | public function driver(?string $name = null)
{
$name = $name ?: $this->getDefaultDriver();
return $this->drivers[$name] = $this->get($name);
} | php | public function driver(?string $name = null)
{
$name = $name ?: $this->getDefaultDriver();
return $this->drivers[$name] = $this->get($name);
} | [
"public",
"function",
"driver",
"(",
"?",
"string",
"$",
"name",
"=",
"null",
")",
"{",
"$",
"name",
"=",
"$",
"name",
"?",
":",
"$",
"this",
"->",
"getDefaultDriver",
"(",
")",
";",
"return",
"$",
"this",
"->",
"drivers",
"[",
"$",
"name",
"]",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"name",
")",
";",
"}"
]
| Get a driver instance by name.
@param string|null $name
@return mixed | [
"Get",
"a",
"driver",
"instance",
"by",
"name",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Support/DriverManager.php#L56-L61 | train |
nuwave/lighthouse | src/Support/DriverManager.php | DriverManager.validateDriver | protected function validateDriver($driver)
{
$interface = $this->interface();
if (! (new ReflectionClass($driver))->implementsInterface($interface)) {
throw new InvalidDriverException(get_class($driver)." does not implement {$interface}");
}
return $driver;
} | php | protected function validateDriver($driver)
{
$interface = $this->interface();
if (! (new ReflectionClass($driver))->implementsInterface($interface)) {
throw new InvalidDriverException(get_class($driver)." does not implement {$interface}");
}
return $driver;
} | [
"protected",
"function",
"validateDriver",
"(",
"$",
"driver",
")",
"{",
"$",
"interface",
"=",
"$",
"this",
"->",
"interface",
"(",
")",
";",
"if",
"(",
"!",
"(",
"new",
"ReflectionClass",
"(",
"$",
"driver",
")",
")",
"->",
"implementsInterface",
"(",
"$",
"interface",
")",
")",
"{",
"throw",
"new",
"InvalidDriverException",
"(",
"get_class",
"(",
"$",
"driver",
")",
".",
"\" does not implement {$interface}\"",
")",
";",
"}",
"return",
"$",
"driver",
";",
"}"
]
| Validate driver implements the proper interface.
@param mixed $driver
@return mixed
@throws \Nuwave\Lighthouse\Exceptions\InvalidDriverException | [
"Validate",
"driver",
"implements",
"the",
"proper",
"interface",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Support/DriverManager.php#L171-L180 | train |
nuwave/lighthouse | src/Subscriptions/BroadcastManager.php | BroadcastManager.createPusherDriver | protected function createPusherDriver(array $config): PusherBroadcaster
{
$connection = $config['connection'] ?? 'pusher';
$driverConfig = config("broadcasting.connections.{$connection}");
if (empty($driverConfig) || $driverConfig['driver'] !== 'pusher') {
throw new RuntimeException("Could not initialize Pusher broadcast driver for connection: {$connection}.");
}
$appKey = Arr::get($driverConfig, 'key');
$appSecret = Arr::get($driverConfig, 'secret');
$appId = Arr::get($driverConfig, 'app_id');
$options = Arr::get($driverConfig, 'options', []);
$pusher = new Pusher($appKey, $appSecret, $appId, $options);
return new PusherBroadcaster($pusher);
} | php | protected function createPusherDriver(array $config): PusherBroadcaster
{
$connection = $config['connection'] ?? 'pusher';
$driverConfig = config("broadcasting.connections.{$connection}");
if (empty($driverConfig) || $driverConfig['driver'] !== 'pusher') {
throw new RuntimeException("Could not initialize Pusher broadcast driver for connection: {$connection}.");
}
$appKey = Arr::get($driverConfig, 'key');
$appSecret = Arr::get($driverConfig, 'secret');
$appId = Arr::get($driverConfig, 'app_id');
$options = Arr::get($driverConfig, 'options', []);
$pusher = new Pusher($appKey, $appSecret, $appId, $options);
return new PusherBroadcaster($pusher);
} | [
"protected",
"function",
"createPusherDriver",
"(",
"array",
"$",
"config",
")",
":",
"PusherBroadcaster",
"{",
"$",
"connection",
"=",
"$",
"config",
"[",
"'connection'",
"]",
"??",
"'pusher'",
";",
"$",
"driverConfig",
"=",
"config",
"(",
"\"broadcasting.connections.{$connection}\"",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"driverConfig",
")",
"||",
"$",
"driverConfig",
"[",
"'driver'",
"]",
"!==",
"'pusher'",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"Could not initialize Pusher broadcast driver for connection: {$connection}.\"",
")",
";",
"}",
"$",
"appKey",
"=",
"Arr",
"::",
"get",
"(",
"$",
"driverConfig",
",",
"'key'",
")",
";",
"$",
"appSecret",
"=",
"Arr",
"::",
"get",
"(",
"$",
"driverConfig",
",",
"'secret'",
")",
";",
"$",
"appId",
"=",
"Arr",
"::",
"get",
"(",
"$",
"driverConfig",
",",
"'app_id'",
")",
";",
"$",
"options",
"=",
"Arr",
"::",
"get",
"(",
"$",
"driverConfig",
",",
"'options'",
",",
"[",
"]",
")",
";",
"$",
"pusher",
"=",
"new",
"Pusher",
"(",
"$",
"appKey",
",",
"$",
"appSecret",
",",
"$",
"appId",
",",
"$",
"options",
")",
";",
"return",
"new",
"PusherBroadcaster",
"(",
"$",
"pusher",
")",
";",
"}"
]
| Create instance of pusher driver.
@param mixed[] $config
@return \Nuwave\Lighthouse\Subscriptions\Broadcasters\PusherBroadcaster
@throws \Pusher\PusherException | [
"Create",
"instance",
"of",
"pusher",
"driver",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Subscriptions/BroadcastManager.php#L58-L75 | train |
nuwave/lighthouse | src/Schema/Types/Scalars/DateTime.php | DateTime.serialize | public function serialize($value): string
{
if ($value instanceof Carbon) {
return $value->toDateTimeString();
}
return $this
->tryParsingDateTime($value, InvariantViolation::class)
->toDateTimeString();
} | php | public function serialize($value): string
{
if ($value instanceof Carbon) {
return $value->toDateTimeString();
}
return $this
->tryParsingDateTime($value, InvariantViolation::class)
->toDateTimeString();
} | [
"public",
"function",
"serialize",
"(",
"$",
"value",
")",
":",
"string",
"{",
"if",
"(",
"$",
"value",
"instanceof",
"Carbon",
")",
"{",
"return",
"$",
"value",
"->",
"toDateTimeString",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"tryParsingDateTime",
"(",
"$",
"value",
",",
"InvariantViolation",
"::",
"class",
")",
"->",
"toDateTimeString",
"(",
")",
";",
"}"
]
| Serialize an internal value, ensuring it is a valid datetime string.
@param \Carbon\Carbon|string $value
@return string | [
"Serialize",
"an",
"internal",
"value",
"ensuring",
"it",
"is",
"a",
"valid",
"datetime",
"string",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/Types/Scalars/DateTime.php#L21-L30 | train |
nuwave/lighthouse | src/Support/Http/Responses/Stream.php | Stream.chunkError | protected function chunkError(string $path, array $data): ?array
{
if (! isset($data['errors'])) {
return null;
}
return (new Collection($data['errors']))
->filter(function (array $error) use ($path): bool {
return Str::startsWith(implode('.', $error['path']), $path);
})
->values()
->toArray();
} | php | protected function chunkError(string $path, array $data): ?array
{
if (! isset($data['errors'])) {
return null;
}
return (new Collection($data['errors']))
->filter(function (array $error) use ($path): bool {
return Str::startsWith(implode('.', $error['path']), $path);
})
->values()
->toArray();
} | [
"protected",
"function",
"chunkError",
"(",
"string",
"$",
"path",
",",
"array",
"$",
"data",
")",
":",
"?",
"array",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"'errors'",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"(",
"new",
"Collection",
"(",
"$",
"data",
"[",
"'errors'",
"]",
")",
")",
"->",
"filter",
"(",
"function",
"(",
"array",
"$",
"error",
")",
"use",
"(",
"$",
"path",
")",
":",
"bool",
"{",
"return",
"Str",
"::",
"startsWith",
"(",
"implode",
"(",
"'.'",
",",
"$",
"error",
"[",
"'path'",
"]",
")",
",",
"$",
"path",
")",
";",
"}",
")",
"->",
"values",
"(",
")",
"->",
"toArray",
"(",
")",
";",
"}"
]
| Get error from chunk if it exists.
@param string $path
@param array $data
@return array|null | [
"Get",
"error",
"from",
"chunk",
"if",
"it",
"exists",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Support/Http/Responses/Stream.php#L17-L29 | train |
nuwave/lighthouse | src/Pagination/PaginatorField.php | PaginatorField.paginatorInfoResolver | public function paginatorInfoResolver(LengthAwarePaginator $root): array
{
return [
'count' => $root->count(),
'currentPage' => $root->currentPage(),
'firstItem' => $root->firstItem(),
'hasMorePages' => $root->hasMorePages(),
'lastItem' => $root->lastItem(),
'lastPage' => $root->lastPage(),
'perPage' => $root->perPage(),
'total' => $root->total(),
];
} | php | public function paginatorInfoResolver(LengthAwarePaginator $root): array
{
return [
'count' => $root->count(),
'currentPage' => $root->currentPage(),
'firstItem' => $root->firstItem(),
'hasMorePages' => $root->hasMorePages(),
'lastItem' => $root->lastItem(),
'lastPage' => $root->lastPage(),
'perPage' => $root->perPage(),
'total' => $root->total(),
];
} | [
"public",
"function",
"paginatorInfoResolver",
"(",
"LengthAwarePaginator",
"$",
"root",
")",
":",
"array",
"{",
"return",
"[",
"'count'",
"=>",
"$",
"root",
"->",
"count",
"(",
")",
",",
"'currentPage'",
"=>",
"$",
"root",
"->",
"currentPage",
"(",
")",
",",
"'firstItem'",
"=>",
"$",
"root",
"->",
"firstItem",
"(",
")",
",",
"'hasMorePages'",
"=>",
"$",
"root",
"->",
"hasMorePages",
"(",
")",
",",
"'lastItem'",
"=>",
"$",
"root",
"->",
"lastItem",
"(",
")",
",",
"'lastPage'",
"=>",
"$",
"root",
"->",
"lastPage",
"(",
")",
",",
"'perPage'",
"=>",
"$",
"root",
"->",
"perPage",
"(",
")",
",",
"'total'",
"=>",
"$",
"root",
"->",
"total",
"(",
")",
",",
"]",
";",
"}"
]
| Resolve paginator info for connection.
@param \Illuminate\Contracts\Pagination\LengthAwarePaginator $root
@return array | [
"Resolve",
"paginator",
"info",
"for",
"connection",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Pagination/PaginatorField.php#L16-L28 | train |
nuwave/lighthouse | src/Subscriptions/Iterators/SyncIterator.php | SyncIterator.process | public function process(Collection $items, Closure $cb, Closure $error = null): void
{
$items->each(function ($item) use ($cb, $error): void {
try {
$cb($item);
} catch (Exception $e) {
if (! $error) {
throw $e;
}
$error($e);
}
});
} | php | public function process(Collection $items, Closure $cb, Closure $error = null): void
{
$items->each(function ($item) use ($cb, $error): void {
try {
$cb($item);
} catch (Exception $e) {
if (! $error) {
throw $e;
}
$error($e);
}
});
} | [
"public",
"function",
"process",
"(",
"Collection",
"$",
"items",
",",
"Closure",
"$",
"cb",
",",
"Closure",
"$",
"error",
"=",
"null",
")",
":",
"void",
"{",
"$",
"items",
"->",
"each",
"(",
"function",
"(",
"$",
"item",
")",
"use",
"(",
"$",
"cb",
",",
"$",
"error",
")",
":",
"void",
"{",
"try",
"{",
"$",
"cb",
"(",
"$",
"item",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"if",
"(",
"!",
"$",
"error",
")",
"{",
"throw",
"$",
"e",
";",
"}",
"$",
"error",
"(",
"$",
"e",
")",
";",
"}",
"}",
")",
";",
"}"
]
| Process collection of items.
@param \Illuminate\Support\Collection $items
@param \Closure $cb
@param \Closure|null $error
@return void | [
"Process",
"collection",
"of",
"items",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Subscriptions/Iterators/SyncIterator.php#L20-L33 | train |
nuwave/lighthouse | src/Schema/Factories/DirectiveFactory.php | DirectiveFactory.create | public function create(string $directiveName, $definitionNode = null): Directive
{
$directive = $this->resolve($directiveName) ?? $this->createOrFail($directiveName);
return $definitionNode
? $this->hydrate($directive, $definitionNode)
: $directive;
} | php | public function create(string $directiveName, $definitionNode = null): Directive
{
$directive = $this->resolve($directiveName) ?? $this->createOrFail($directiveName);
return $definitionNode
? $this->hydrate($directive, $definitionNode)
: $directive;
} | [
"public",
"function",
"create",
"(",
"string",
"$",
"directiveName",
",",
"$",
"definitionNode",
"=",
"null",
")",
":",
"Directive",
"{",
"$",
"directive",
"=",
"$",
"this",
"->",
"resolve",
"(",
"$",
"directiveName",
")",
"??",
"$",
"this",
"->",
"createOrFail",
"(",
"$",
"directiveName",
")",
";",
"return",
"$",
"definitionNode",
"?",
"$",
"this",
"->",
"hydrate",
"(",
"$",
"directive",
",",
"$",
"definitionNode",
")",
":",
"$",
"directive",
";",
"}"
]
| Create a directive by the given directive name.
@param string $directiveName
@param \GraphQL\Language\AST\TypeSystemDefinitionNode|null $definitionNode
@return \Nuwave\Lighthouse\Support\Contracts\Directive | [
"Create",
"a",
"directive",
"by",
"the",
"given",
"directive",
"name",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/Factories/DirectiveFactory.php#L96-L103 | train |
nuwave/lighthouse | src/Schema/Factories/DirectiveFactory.php | DirectiveFactory.resolve | protected function resolve(string $directiveName): ?Directive
{
if ($className = Arr::get($this->resolved, $directiveName)) {
return app($className);
}
return null;
} | php | protected function resolve(string $directiveName): ?Directive
{
if ($className = Arr::get($this->resolved, $directiveName)) {
return app($className);
}
return null;
} | [
"protected",
"function",
"resolve",
"(",
"string",
"$",
"directiveName",
")",
":",
"?",
"Directive",
"{",
"if",
"(",
"$",
"className",
"=",
"Arr",
"::",
"get",
"(",
"$",
"this",
"->",
"resolved",
",",
"$",
"directiveName",
")",
")",
"{",
"return",
"app",
"(",
"$",
"className",
")",
";",
"}",
"return",
"null",
";",
"}"
]
| Create a directive from resolved directive classes.
@param string $directiveName
@return \Nuwave\Lighthouse\Support\Contracts\Directive|null | [
"Create",
"a",
"directive",
"from",
"resolved",
"directive",
"classes",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/Factories/DirectiveFactory.php#L111-L118 | train |
nuwave/lighthouse | src/Schema/Factories/DirectiveFactory.php | DirectiveFactory.hydrate | protected function hydrate(Directive $directive, $definitionNode): Directive
{
return $directive instanceof BaseDirective
? $directive->hydrate($definitionNode)
: $directive;
} | php | protected function hydrate(Directive $directive, $definitionNode): Directive
{
return $directive instanceof BaseDirective
? $directive->hydrate($definitionNode)
: $directive;
} | [
"protected",
"function",
"hydrate",
"(",
"Directive",
"$",
"directive",
",",
"$",
"definitionNode",
")",
":",
"Directive",
"{",
"return",
"$",
"directive",
"instanceof",
"BaseDirective",
"?",
"$",
"directive",
"->",
"hydrate",
"(",
"$",
"definitionNode",
")",
":",
"$",
"directive",
";",
"}"
]
| Set the given definition on the directive.
@param \Nuwave\Lighthouse\Support\Contracts\Directive $directive
@param \GraphQL\Language\AST\TypeSystemDefinitionNode $definitionNode
@return \Nuwave\Lighthouse\Support\Contracts\Directive | [
"Set",
"the",
"given",
"definition",
"on",
"the",
"directive",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/Factories/DirectiveFactory.php#L193-L198 | train |
nuwave/lighthouse | src/Schema/Factories/DirectiveFactory.php | DirectiveFactory.createAssociatedDirectivesOfType | protected function createAssociatedDirectivesOfType(Node $node, string $directiveClass): Collection
{
return (new Collection($node->directives))
->map(function (DirectiveNode $directive) use ($node) {
return $this->create($directive->name->value, $node);
})
->filter(function (Directive $directive) use ($directiveClass) {
return $directive instanceof $directiveClass;
});
} | php | protected function createAssociatedDirectivesOfType(Node $node, string $directiveClass): Collection
{
return (new Collection($node->directives))
->map(function (DirectiveNode $directive) use ($node) {
return $this->create($directive->name->value, $node);
})
->filter(function (Directive $directive) use ($directiveClass) {
return $directive instanceof $directiveClass;
});
} | [
"protected",
"function",
"createAssociatedDirectivesOfType",
"(",
"Node",
"$",
"node",
",",
"string",
"$",
"directiveClass",
")",
":",
"Collection",
"{",
"return",
"(",
"new",
"Collection",
"(",
"$",
"node",
"->",
"directives",
")",
")",
"->",
"map",
"(",
"function",
"(",
"DirectiveNode",
"$",
"directive",
")",
"use",
"(",
"$",
"node",
")",
"{",
"return",
"$",
"this",
"->",
"create",
"(",
"$",
"directive",
"->",
"name",
"->",
"value",
",",
"$",
"node",
")",
";",
"}",
")",
"->",
"filter",
"(",
"function",
"(",
"Directive",
"$",
"directive",
")",
"use",
"(",
"$",
"directiveClass",
")",
"{",
"return",
"$",
"directive",
"instanceof",
"$",
"directiveClass",
";",
"}",
")",
";",
"}"
]
| Get all directives of a certain type that are associated with an AST node.
@param \GraphQL\Language\AST\Node $node
@param string $directiveClass
@return \Illuminate\Support\Collection <$directiveClass> | [
"Get",
"all",
"directives",
"of",
"a",
"certain",
"type",
"that",
"are",
"associated",
"with",
"an",
"AST",
"node",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/Factories/DirectiveFactory.php#L207-L216 | train |
nuwave/lighthouse | src/Schema/Factories/DirectiveFactory.php | DirectiveFactory.createSingleDirectiveOfType | protected function createSingleDirectiveOfType(Node $node, string $directiveClass): ?Directive
{
$directives = $this->createAssociatedDirectivesOfType($node, $directiveClass);
if ($directives->count() > 1) {
$directiveNames = $directives->implode(', ');
throw new DirectiveException(
"Node [{$node->name->value}] can only have one directive of type [{$directiveClass}] but found [{$directiveNames}]"
);
}
return $directives->first();
} | php | protected function createSingleDirectiveOfType(Node $node, string $directiveClass): ?Directive
{
$directives = $this->createAssociatedDirectivesOfType($node, $directiveClass);
if ($directives->count() > 1) {
$directiveNames = $directives->implode(', ');
throw new DirectiveException(
"Node [{$node->name->value}] can only have one directive of type [{$directiveClass}] but found [{$directiveNames}]"
);
}
return $directives->first();
} | [
"protected",
"function",
"createSingleDirectiveOfType",
"(",
"Node",
"$",
"node",
",",
"string",
"$",
"directiveClass",
")",
":",
"?",
"Directive",
"{",
"$",
"directives",
"=",
"$",
"this",
"->",
"createAssociatedDirectivesOfType",
"(",
"$",
"node",
",",
"$",
"directiveClass",
")",
";",
"if",
"(",
"$",
"directives",
"->",
"count",
"(",
")",
">",
"1",
")",
"{",
"$",
"directiveNames",
"=",
"$",
"directives",
"->",
"implode",
"(",
"', '",
")",
";",
"throw",
"new",
"DirectiveException",
"(",
"\"Node [{$node->name->value}] can only have one directive of type [{$directiveClass}] but found [{$directiveNames}]\"",
")",
";",
"}",
"return",
"$",
"directives",
"->",
"first",
"(",
")",
";",
"}"
]
| Get a single directive of a type that belongs to an AST node.
Use this for directives types that can only occur once, such as field resolvers.
This throws if more than one such directive is found.
@param \GraphQL\Language\AST\Node $node
@param string $directiveClass
@return \Nuwave\Lighthouse\Support\Contracts\Directive|null
@throws \Nuwave\Lighthouse\Exceptions\DirectiveException | [
"Get",
"a",
"single",
"directive",
"of",
"a",
"type",
"that",
"belongs",
"to",
"an",
"AST",
"node",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/Factories/DirectiveFactory.php#L230-L243 | train |
nuwave/lighthouse | src/Schema/Factories/ArgumentFactory.php | ArgumentFactory.handle | public function handle(ArgumentValue $argumentValue): array
{
$definition = $argumentValue->getAstNode();
$argumentType = $argumentValue->getType();
$fieldArgument = [
'name' => $argumentValue->getName(),
'description' => data_get($definition->description, 'value'),
'type' => $argumentType,
'astNode' => $definition,
];
if ($defaultValue = $definition->defaultValue) {
$fieldArgument += [
// webonyx/graphql-php expects the internal value here, whereas the
// SDL uses the ENUM's name, so we run the conversion here
'defaultValue' => $argumentType instanceof EnumType
? $argumentType->getValue($defaultValue->value)->value
: AST::valueFromASTUntyped($defaultValue),
];
}
// Add any dynamically declared public properties of the FieldArgument
$fieldArgument += get_object_vars($argumentValue);
// Used to construct a FieldArgument class
return $fieldArgument;
} | php | public function handle(ArgumentValue $argumentValue): array
{
$definition = $argumentValue->getAstNode();
$argumentType = $argumentValue->getType();
$fieldArgument = [
'name' => $argumentValue->getName(),
'description' => data_get($definition->description, 'value'),
'type' => $argumentType,
'astNode' => $definition,
];
if ($defaultValue = $definition->defaultValue) {
$fieldArgument += [
// webonyx/graphql-php expects the internal value here, whereas the
// SDL uses the ENUM's name, so we run the conversion here
'defaultValue' => $argumentType instanceof EnumType
? $argumentType->getValue($defaultValue->value)->value
: AST::valueFromASTUntyped($defaultValue),
];
}
// Add any dynamically declared public properties of the FieldArgument
$fieldArgument += get_object_vars($argumentValue);
// Used to construct a FieldArgument class
return $fieldArgument;
} | [
"public",
"function",
"handle",
"(",
"ArgumentValue",
"$",
"argumentValue",
")",
":",
"array",
"{",
"$",
"definition",
"=",
"$",
"argumentValue",
"->",
"getAstNode",
"(",
")",
";",
"$",
"argumentType",
"=",
"$",
"argumentValue",
"->",
"getType",
"(",
")",
";",
"$",
"fieldArgument",
"=",
"[",
"'name'",
"=>",
"$",
"argumentValue",
"->",
"getName",
"(",
")",
",",
"'description'",
"=>",
"data_get",
"(",
"$",
"definition",
"->",
"description",
",",
"'value'",
")",
",",
"'type'",
"=>",
"$",
"argumentType",
",",
"'astNode'",
"=>",
"$",
"definition",
",",
"]",
";",
"if",
"(",
"$",
"defaultValue",
"=",
"$",
"definition",
"->",
"defaultValue",
")",
"{",
"$",
"fieldArgument",
"+=",
"[",
"// webonyx/graphql-php expects the internal value here, whereas the",
"// SDL uses the ENUM's name, so we run the conversion here",
"'defaultValue'",
"=>",
"$",
"argumentType",
"instanceof",
"EnumType",
"?",
"$",
"argumentType",
"->",
"getValue",
"(",
"$",
"defaultValue",
"->",
"value",
")",
"->",
"value",
":",
"AST",
"::",
"valueFromASTUntyped",
"(",
"$",
"defaultValue",
")",
",",
"]",
";",
"}",
"// Add any dynamically declared public properties of the FieldArgument",
"$",
"fieldArgument",
"+=",
"get_object_vars",
"(",
"$",
"argumentValue",
")",
";",
"// Used to construct a FieldArgument class",
"return",
"$",
"fieldArgument",
";",
"}"
]
| Convert argument definition to type.
@param \Nuwave\Lighthouse\Schema\Values\ArgumentValue $argumentValue
@return array | [
"Convert",
"argument",
"definition",
"to",
"type",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/Factories/ArgumentFactory.php#L17-L45 | train |
nuwave/lighthouse | src/Schema/Directives/WithDirective.php | WithDirective.handleField | public function handleField(FieldValue $value, Closure $next): FieldValue
{
$resolver = $value->getResolver();
return $next(
$value->setResolver(
function (Model $parent, array $args, GraphQLContext $context, ResolveInfo $resolveInfo) use ($resolver): Deferred {
$loader = BatchLoader::instance(
RelationBatchLoader::class,
$resolveInfo->path,
[
'relationName' => $this->directiveArgValue('relation', $this->definitionNode->name->value),
'args' => $args,
'scopes' => $this->directiveArgValue('scopes', []),
'resolveInfo' => $resolveInfo,
]
);
return new Deferred(function () use ($loader, $resolver, $parent, $args, $context, $resolveInfo) {
return $loader
->load(
$parent->getKey(),
['parent' => $parent]
)->then(
function () use ($resolver, $parent, $args, $context, $resolveInfo) {
return $resolver($parent, $args, $context, $resolveInfo);
}
);
});
}
)
);
} | php | public function handleField(FieldValue $value, Closure $next): FieldValue
{
$resolver = $value->getResolver();
return $next(
$value->setResolver(
function (Model $parent, array $args, GraphQLContext $context, ResolveInfo $resolveInfo) use ($resolver): Deferred {
$loader = BatchLoader::instance(
RelationBatchLoader::class,
$resolveInfo->path,
[
'relationName' => $this->directiveArgValue('relation', $this->definitionNode->name->value),
'args' => $args,
'scopes' => $this->directiveArgValue('scopes', []),
'resolveInfo' => $resolveInfo,
]
);
return new Deferred(function () use ($loader, $resolver, $parent, $args, $context, $resolveInfo) {
return $loader
->load(
$parent->getKey(),
['parent' => $parent]
)->then(
function () use ($resolver, $parent, $args, $context, $resolveInfo) {
return $resolver($parent, $args, $context, $resolveInfo);
}
);
});
}
)
);
} | [
"public",
"function",
"handleField",
"(",
"FieldValue",
"$",
"value",
",",
"Closure",
"$",
"next",
")",
":",
"FieldValue",
"{",
"$",
"resolver",
"=",
"$",
"value",
"->",
"getResolver",
"(",
")",
";",
"return",
"$",
"next",
"(",
"$",
"value",
"->",
"setResolver",
"(",
"function",
"(",
"Model",
"$",
"parent",
",",
"array",
"$",
"args",
",",
"GraphQLContext",
"$",
"context",
",",
"ResolveInfo",
"$",
"resolveInfo",
")",
"use",
"(",
"$",
"resolver",
")",
":",
"Deferred",
"{",
"$",
"loader",
"=",
"BatchLoader",
"::",
"instance",
"(",
"RelationBatchLoader",
"::",
"class",
",",
"$",
"resolveInfo",
"->",
"path",
",",
"[",
"'relationName'",
"=>",
"$",
"this",
"->",
"directiveArgValue",
"(",
"'relation'",
",",
"$",
"this",
"->",
"definitionNode",
"->",
"name",
"->",
"value",
")",
",",
"'args'",
"=>",
"$",
"args",
",",
"'scopes'",
"=>",
"$",
"this",
"->",
"directiveArgValue",
"(",
"'scopes'",
",",
"[",
"]",
")",
",",
"'resolveInfo'",
"=>",
"$",
"resolveInfo",
",",
"]",
")",
";",
"return",
"new",
"Deferred",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"loader",
",",
"$",
"resolver",
",",
"$",
"parent",
",",
"$",
"args",
",",
"$",
"context",
",",
"$",
"resolveInfo",
")",
"{",
"return",
"$",
"loader",
"->",
"load",
"(",
"$",
"parent",
"->",
"getKey",
"(",
")",
",",
"[",
"'parent'",
"=>",
"$",
"parent",
"]",
")",
"->",
"then",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"resolver",
",",
"$",
"parent",
",",
"$",
"args",
",",
"$",
"context",
",",
"$",
"resolveInfo",
")",
"{",
"return",
"$",
"resolver",
"(",
"$",
"parent",
",",
"$",
"args",
",",
"$",
"context",
",",
"$",
"resolveInfo",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}",
")",
")",
";",
"}"
]
| Eager load a relation on the parent instance.
@param \Nuwave\Lighthouse\Schema\Values\FieldValue $value
@param \Closure $next
@return \Nuwave\Lighthouse\Schema\Values\FieldValue | [
"Eager",
"load",
"a",
"relation",
"on",
"the",
"parent",
"instance",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/Directives/WithDirective.php#L34-L66 | train |
nuwave/lighthouse | src/Execution/ErrorBuffer.php | ErrorBuffer.defaultExceptionResolver | protected function defaultExceptionResolver(): Closure
{
return function (string $errorMessage) {
return (new GenericException($errorMessage))
->setExtensions([$this->errorType => $this->errors])
->setCategory($this->errorType);
};
} | php | protected function defaultExceptionResolver(): Closure
{
return function (string $errorMessage) {
return (new GenericException($errorMessage))
->setExtensions([$this->errorType => $this->errors])
->setCategory($this->errorType);
};
} | [
"protected",
"function",
"defaultExceptionResolver",
"(",
")",
":",
"Closure",
"{",
"return",
"function",
"(",
"string",
"$",
"errorMessage",
")",
"{",
"return",
"(",
"new",
"GenericException",
"(",
"$",
"errorMessage",
")",
")",
"->",
"setExtensions",
"(",
"[",
"$",
"this",
"->",
"errorType",
"=>",
"$",
"this",
"->",
"errors",
"]",
")",
"->",
"setCategory",
"(",
"$",
"this",
"->",
"errorType",
")",
";",
"}",
";",
"}"
]
| Construct a default exception resolver.
@return \Closure | [
"Construct",
"a",
"default",
"exception",
"resolver",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Execution/ErrorBuffer.php#L45-L52 | train |
nuwave/lighthouse | src/Execution/ErrorBuffer.php | ErrorBuffer.push | public function push(string $errorMessage, ?string $key = null): self
{
if ($key === null) {
$this->errors[] = $errorMessage;
} else {
$this->errors[$key][] = $errorMessage;
}
return $this;
} | php | public function push(string $errorMessage, ?string $key = null): self
{
if ($key === null) {
$this->errors[] = $errorMessage;
} else {
$this->errors[$key][] = $errorMessage;
}
return $this;
} | [
"public",
"function",
"push",
"(",
"string",
"$",
"errorMessage",
",",
"?",
"string",
"$",
"key",
"=",
"null",
")",
":",
"self",
"{",
"if",
"(",
"$",
"key",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"errors",
"[",
"]",
"=",
"$",
"errorMessage",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"errors",
"[",
"$",
"key",
"]",
"[",
"]",
"=",
"$",
"errorMessage",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Push an error message into the buffer.
@param string $errorMessage
@param string|null $key
@return $this | [
"Push",
"an",
"error",
"message",
"into",
"the",
"buffer",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Execution/ErrorBuffer.php#L85-L94 | train |
nuwave/lighthouse | src/Execution/ErrorBuffer.php | ErrorBuffer.flush | public function flush(string $errorMessage): void
{
if (! $this->hasErrors()) {
return;
}
$exception = $this->resolveException($errorMessage, $this);
$this->clearErrors();
throw $exception;
} | php | public function flush(string $errorMessage): void
{
if (! $this->hasErrors()) {
return;
}
$exception = $this->resolveException($errorMessage, $this);
$this->clearErrors();
throw $exception;
} | [
"public",
"function",
"flush",
"(",
"string",
"$",
"errorMessage",
")",
":",
"void",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasErrors",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"exception",
"=",
"$",
"this",
"->",
"resolveException",
"(",
"$",
"errorMessage",
",",
"$",
"this",
")",
";",
"$",
"this",
"->",
"clearErrors",
"(",
")",
";",
"throw",
"$",
"exception",
";",
"}"
]
| Flush the errors.
@param string $errorMessage
@return void
@throws \Exception | [
"Flush",
"the",
"errors",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Execution/ErrorBuffer.php#L104-L115 | train |
nuwave/lighthouse | src/Schema/Values/FieldValue.php | FieldValue.getReturnType | public function getReturnType(): Type
{
if (! isset($this->returnType)) {
$this->returnType = app(DefinitionNodeConverter::class)->toType(
$this->field->type
);
}
return $this->returnType;
} | php | public function getReturnType(): Type
{
if (! isset($this->returnType)) {
$this->returnType = app(DefinitionNodeConverter::class)->toType(
$this->field->type
);
}
return $this->returnType;
} | [
"public",
"function",
"getReturnType",
"(",
")",
":",
"Type",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"returnType",
")",
")",
"{",
"$",
"this",
"->",
"returnType",
"=",
"app",
"(",
"DefinitionNodeConverter",
"::",
"class",
")",
"->",
"toType",
"(",
"$",
"this",
"->",
"field",
"->",
"type",
")",
";",
"}",
"return",
"$",
"this",
"->",
"returnType",
";",
"}"
]
| Get an instance of the return type of the field.
@return \GraphQL\Type\Definition\Type | [
"Get",
"an",
"instance",
"of",
"the",
"return",
"type",
"of",
"the",
"field",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/Values/FieldValue.php#L119-L128 | train |
nuwave/lighthouse | src/Pagination/PaginationUtils.php | PaginationUtils.calculateCurrentPage | public static function calculateCurrentPage(int $first, int $after, int $defaultPage = 1): int
{
return $first && $after
? (int) floor(($first + $after) / $first)
: $defaultPage;
} | php | public static function calculateCurrentPage(int $first, int $after, int $defaultPage = 1): int
{
return $first && $after
? (int) floor(($first + $after) / $first)
: $defaultPage;
} | [
"public",
"static",
"function",
"calculateCurrentPage",
"(",
"int",
"$",
"first",
",",
"int",
"$",
"after",
",",
"int",
"$",
"defaultPage",
"=",
"1",
")",
":",
"int",
"{",
"return",
"$",
"first",
"&&",
"$",
"after",
"?",
"(",
"int",
")",
"floor",
"(",
"(",
"$",
"first",
"+",
"$",
"after",
")",
"/",
"$",
"first",
")",
":",
"$",
"defaultPage",
";",
"}"
]
| Calculate the current page to inform the user about the pagination state.
@param int $first
@param int $after
@param int $defaultPage
@return int | [
"Calculate",
"the",
"current",
"page",
"to",
"inform",
"the",
"user",
"about",
"the",
"pagination",
"state",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Pagination/PaginationUtils.php#L18-L23 | train |
nuwave/lighthouse | src/Schema/TypeRegistry.php | TypeRegistry.register | public function register(Type $type): self
{
$this->types[$type->name] = $type;
return $this;
} | php | public function register(Type $type): self
{
$this->types[$type->name] = $type;
return $this;
} | [
"public",
"function",
"register",
"(",
"Type",
"$",
"type",
")",
":",
"self",
"{",
"$",
"this",
"->",
"types",
"[",
"$",
"type",
"->",
"name",
"]",
"=",
"$",
"type",
";",
"return",
"$",
"this",
";",
"}"
]
| Register type with registry.
@param \GraphQL\Type\Definition\Type $type
@return $this | [
"Register",
"type",
"with",
"registry",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/TypeRegistry.php#L30-L35 | train |
nuwave/lighthouse | src/Schema/TypeRegistry.php | TypeRegistry.get | public function get(string $typeName): Type
{
if (! isset($this->types[$typeName])) {
throw new InvariantViolation("No type {$typeName} was registered.");
}
return $this->types[$typeName];
} | php | public function get(string $typeName): Type
{
if (! isset($this->types[$typeName])) {
throw new InvariantViolation("No type {$typeName} was registered.");
}
return $this->types[$typeName];
} | [
"public",
"function",
"get",
"(",
"string",
"$",
"typeName",
")",
":",
"Type",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"types",
"[",
"$",
"typeName",
"]",
")",
")",
"{",
"throw",
"new",
"InvariantViolation",
"(",
"\"No type {$typeName} was registered.\"",
")",
";",
"}",
"return",
"$",
"this",
"->",
"types",
"[",
"$",
"typeName",
"]",
";",
"}"
]
| Resolve type instance by name.
@param string $typeName
@return \GraphQL\Type\Definition\Type
@throws \GraphQL\Error\InvariantViolation | [
"Resolve",
"type",
"instance",
"by",
"name",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/TypeRegistry.php#L45-L52 | train |
nuwave/lighthouse | src/Pagination/PaginationManipulator.php | PaginationManipulator.transformToPaginatedField | public static function transformToPaginatedField(
PaginationType $paginationType,
FieldDefinitionNode $fieldDefinition,
ObjectTypeDefinitionNode $parentType,
DocumentAST $current,
?int $defaultCount = null,
?int $maxCount = null
): DocumentAST {
if ($paginationType->isConnection()) {
return self::registerConnection($fieldDefinition, $parentType, $current, $defaultCount, $maxCount);
}
return self::registerPaginator($fieldDefinition, $parentType, $current, $defaultCount, $maxCount);
} | php | public static function transformToPaginatedField(
PaginationType $paginationType,
FieldDefinitionNode $fieldDefinition,
ObjectTypeDefinitionNode $parentType,
DocumentAST $current,
?int $defaultCount = null,
?int $maxCount = null
): DocumentAST {
if ($paginationType->isConnection()) {
return self::registerConnection($fieldDefinition, $parentType, $current, $defaultCount, $maxCount);
}
return self::registerPaginator($fieldDefinition, $parentType, $current, $defaultCount, $maxCount);
} | [
"public",
"static",
"function",
"transformToPaginatedField",
"(",
"PaginationType",
"$",
"paginationType",
",",
"FieldDefinitionNode",
"$",
"fieldDefinition",
",",
"ObjectTypeDefinitionNode",
"$",
"parentType",
",",
"DocumentAST",
"$",
"current",
",",
"?",
"int",
"$",
"defaultCount",
"=",
"null",
",",
"?",
"int",
"$",
"maxCount",
"=",
"null",
")",
":",
"DocumentAST",
"{",
"if",
"(",
"$",
"paginationType",
"->",
"isConnection",
"(",
")",
")",
"{",
"return",
"self",
"::",
"registerConnection",
"(",
"$",
"fieldDefinition",
",",
"$",
"parentType",
",",
"$",
"current",
",",
"$",
"defaultCount",
",",
"$",
"maxCount",
")",
";",
"}",
"return",
"self",
"::",
"registerPaginator",
"(",
"$",
"fieldDefinition",
",",
"$",
"parentType",
",",
"$",
"current",
",",
"$",
"defaultCount",
",",
"$",
"maxCount",
")",
";",
"}"
]
| Transform the definition for a field to a field with pagination.
This makes either an offset-based Paginator or a cursor-based Connection.
The types in between are automatically generated and applied to the schema.
@param \Nuwave\Lighthouse\Pagination\PaginationType $paginationType
@param \GraphQL\Language\AST\FieldDefinitionNode $fieldDefinition
@param \GraphQL\Language\AST\ObjectTypeDefinitionNode $parentType
@param \Nuwave\Lighthouse\Schema\AST\DocumentAST $current
@param int|null $defaultCount
@param int|null $maxCount
@return \Nuwave\Lighthouse\Schema\AST\DocumentAST | [
"Transform",
"the",
"definition",
"for",
"a",
"field",
"to",
"a",
"field",
"with",
"pagination",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Pagination/PaginationManipulator.php#L27-L40 | train |
nuwave/lighthouse | src/Pagination/PaginationManipulator.php | PaginationManipulator.countArgument | protected static function countArgument(string $argumentName, ?int $defaultCount = null, ?int $maxCount = null): string
{
$description = '"Limits number of fetched elements.';
if ($maxCount) {
$description .= ' Maximum allowed value: '.$maxCount.'.';
}
$description .= "\"\n";
$definition = $argumentName.': Int'
.($defaultCount
? ' = '.$defaultCount
: '!'
);
return $description.$definition;
} | php | protected static function countArgument(string $argumentName, ?int $defaultCount = null, ?int $maxCount = null): string
{
$description = '"Limits number of fetched elements.';
if ($maxCount) {
$description .= ' Maximum allowed value: '.$maxCount.'.';
}
$description .= "\"\n";
$definition = $argumentName.': Int'
.($defaultCount
? ' = '.$defaultCount
: '!'
);
return $description.$definition;
} | [
"protected",
"static",
"function",
"countArgument",
"(",
"string",
"$",
"argumentName",
",",
"?",
"int",
"$",
"defaultCount",
"=",
"null",
",",
"?",
"int",
"$",
"maxCount",
"=",
"null",
")",
":",
"string",
"{",
"$",
"description",
"=",
"'\"Limits number of fetched elements.'",
";",
"if",
"(",
"$",
"maxCount",
")",
"{",
"$",
"description",
".=",
"' Maximum allowed value: '",
".",
"$",
"maxCount",
".",
"'.'",
";",
"}",
"$",
"description",
".=",
"\"\\\"\\n\"",
";",
"$",
"definition",
"=",
"$",
"argumentName",
".",
"': Int'",
".",
"(",
"$",
"defaultCount",
"?",
"' = '",
".",
"$",
"defaultCount",
":",
"'!'",
")",
";",
"return",
"$",
"description",
".",
"$",
"definition",
";",
"}"
]
| Build the count argument definition string, considering default and max values.
@param string $argumentName
@param int|null $defaultCount
@param int|null $maxCount
@return string | [
"Build",
"the",
"count",
"argument",
"definition",
"string",
"considering",
"default",
"and",
"max",
"values",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Pagination/PaginationManipulator.php#L148-L163 | train |
nuwave/lighthouse | src/Schema/Types/Scalars/Upload.php | Upload.parseValue | public function parseValue($value): UploadedFile
{
if (! $value instanceof UploadedFile) {
throw new Error(
'Could not get uploaded file, be sure to conform to GraphQL multipart request specification: https://github.com/jaydenseric/graphql-multipart-request-spec Instead got: '.Utils::printSafe($value)
);
}
return $value;
} | php | public function parseValue($value): UploadedFile
{
if (! $value instanceof UploadedFile) {
throw new Error(
'Could not get uploaded file, be sure to conform to GraphQL multipart request specification: https://github.com/jaydenseric/graphql-multipart-request-spec Instead got: '.Utils::printSafe($value)
);
}
return $value;
} | [
"public",
"function",
"parseValue",
"(",
"$",
"value",
")",
":",
"UploadedFile",
"{",
"if",
"(",
"!",
"$",
"value",
"instanceof",
"UploadedFile",
")",
"{",
"throw",
"new",
"Error",
"(",
"'Could not get uploaded file, be sure to conform to GraphQL multipart request specification: https://github.com/jaydenseric/graphql-multipart-request-spec Instead got: '",
".",
"Utils",
"::",
"printSafe",
"(",
"$",
"value",
")",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
]
| Parse a externally provided variable value into a Carbon instance.
@param mixed $value
@return \Illuminate\Http\UploadedFile
@throws \GraphQL\Error\Error | [
"Parse",
"a",
"externally",
"provided",
"variable",
"value",
"into",
"a",
"Carbon",
"instance",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Schema/Types/Scalars/Upload.php#L36-L45 | train |
nuwave/lighthouse | src/Pagination/Cursor.php | Cursor.decode | public static function decode(array $args): int
{
if ($cursor = Arr::get($args, 'after')) {
return (int) base64_decode($cursor);
}
return 0;
} | php | public static function decode(array $args): int
{
if ($cursor = Arr::get($args, 'after')) {
return (int) base64_decode($cursor);
}
return 0;
} | [
"public",
"static",
"function",
"decode",
"(",
"array",
"$",
"args",
")",
":",
"int",
"{",
"if",
"(",
"$",
"cursor",
"=",
"Arr",
"::",
"get",
"(",
"$",
"args",
",",
"'after'",
")",
")",
"{",
"return",
"(",
"int",
")",
"base64_decode",
"(",
"$",
"cursor",
")",
";",
"}",
"return",
"0",
";",
"}"
]
| Decode cursor from query arguments.
If no 'after' argument is provided or the contents are not a valid base64 string,
this will return 0. That will effectively reset pagination, so the user gets the
first slice.
@param array $args
@return int | [
"Decode",
"cursor",
"from",
"query",
"arguments",
"."
]
| f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8 | https://github.com/nuwave/lighthouse/blob/f92f779ab49e32bcb746f51e45b3dd0ad00dc8b8/src/Pagination/Cursor.php#L28-L35 | train |
babenkoivan/scout-elasticsearch-driver | src/Console/SearchableModelMakeCommand.php | SearchableModelMakeCommand.buildClass | protected function buildClass($name)
{
$stub = parent::buildClass($name);
$indexConfigurator = $this->getIndexConfigurator();
$stub = str_replace(
'DummyIndexConfigurator',
$indexConfigurator ? "{$indexConfigurator}::class" : 'null', $stub
);
$searchRule = $this->getSearchRule();
$stub = str_replace(
'DummySearchRule',
$searchRule ? "{$searchRule}::class" : '//', $stub
);
return $stub;
} | php | protected function buildClass($name)
{
$stub = parent::buildClass($name);
$indexConfigurator = $this->getIndexConfigurator();
$stub = str_replace(
'DummyIndexConfigurator',
$indexConfigurator ? "{$indexConfigurator}::class" : 'null', $stub
);
$searchRule = $this->getSearchRule();
$stub = str_replace(
'DummySearchRule',
$searchRule ? "{$searchRule}::class" : '//', $stub
);
return $stub;
} | [
"protected",
"function",
"buildClass",
"(",
"$",
"name",
")",
"{",
"$",
"stub",
"=",
"parent",
"::",
"buildClass",
"(",
"$",
"name",
")",
";",
"$",
"indexConfigurator",
"=",
"$",
"this",
"->",
"getIndexConfigurator",
"(",
")",
";",
"$",
"stub",
"=",
"str_replace",
"(",
"'DummyIndexConfigurator'",
",",
"$",
"indexConfigurator",
"?",
"\"{$indexConfigurator}::class\"",
":",
"'null'",
",",
"$",
"stub",
")",
";",
"$",
"searchRule",
"=",
"$",
"this",
"->",
"getSearchRule",
"(",
")",
";",
"$",
"stub",
"=",
"str_replace",
"(",
"'DummySearchRule'",
",",
"$",
"searchRule",
"?",
"\"{$searchRule}::class\"",
":",
"'//'",
",",
"$",
"stub",
")",
";",
"return",
"$",
"stub",
";",
"}"
]
| Build the class.
@param string $name
@return string | [
"Build",
"the",
"class",
"."
]
| f078a6f9d35b44e4ff440ea31e583973596e9726 | https://github.com/babenkoivan/scout-elasticsearch-driver/blob/f078a6f9d35b44e4ff440ea31e583973596e9726/src/Console/SearchableModelMakeCommand.php#L78-L97 | train |
babenkoivan/scout-elasticsearch-driver | src/ElasticEngine.php | ElasticEngine.buildSearchQueryPayloadCollection | public function buildSearchQueryPayloadCollection(Builder $builder, array $options = [])
{
$payloadCollection = collect();
if ($builder instanceof SearchBuilder) {
$searchRules = $builder->rules ?: $builder->model->getSearchRules();
foreach ($searchRules as $rule) {
$payload = new TypePayload($builder->model);
if (is_callable($rule)) {
$payload->setIfNotEmpty('body.query.bool', call_user_func($rule, $builder));
} else {
/** @var SearchRule $ruleEntity */
$ruleEntity = new $rule($builder);
if ($ruleEntity->isApplicable()) {
$payload->setIfNotEmpty('body.query.bool', $ruleEntity->buildQueryPayload());
if ($options['highlight'] ?? true) {
$payload->setIfNotEmpty('body.highlight', $ruleEntity->buildHighlightPayload());
}
} else {
continue;
}
}
$payloadCollection->push($payload);
}
} else {
$payload = (new TypePayload($builder->model))
->setIfNotEmpty('body.query.bool.must.match_all', new stdClass());
$payloadCollection->push($payload);
}
return $payloadCollection->map(function (TypePayload $payload) use ($builder, $options) {
$payload
->setIfNotEmpty('body._source', $builder->select)
->setIfNotEmpty('body.collapse.field', $builder->collapse)
->setIfNotEmpty('body.sort', $builder->orders)
->setIfNotEmpty('body.explain', $options['explain'] ?? null)
->setIfNotEmpty('body.profile', $options['profile'] ?? null)
->setIfNotNull('body.from', $builder->offset)
->setIfNotNull('body.size', $builder->limit);
foreach ($builder->wheres as $clause => $filters) {
$clauseKey = 'body.query.bool.filter.bool.'.$clause;
$clauseValue = array_merge(
$payload->get($clauseKey, []),
$filters
);
$payload->setIfNotEmpty($clauseKey, $clauseValue);
}
return $payload->get();
});
} | php | public function buildSearchQueryPayloadCollection(Builder $builder, array $options = [])
{
$payloadCollection = collect();
if ($builder instanceof SearchBuilder) {
$searchRules = $builder->rules ?: $builder->model->getSearchRules();
foreach ($searchRules as $rule) {
$payload = new TypePayload($builder->model);
if (is_callable($rule)) {
$payload->setIfNotEmpty('body.query.bool', call_user_func($rule, $builder));
} else {
/** @var SearchRule $ruleEntity */
$ruleEntity = new $rule($builder);
if ($ruleEntity->isApplicable()) {
$payload->setIfNotEmpty('body.query.bool', $ruleEntity->buildQueryPayload());
if ($options['highlight'] ?? true) {
$payload->setIfNotEmpty('body.highlight', $ruleEntity->buildHighlightPayload());
}
} else {
continue;
}
}
$payloadCollection->push($payload);
}
} else {
$payload = (new TypePayload($builder->model))
->setIfNotEmpty('body.query.bool.must.match_all', new stdClass());
$payloadCollection->push($payload);
}
return $payloadCollection->map(function (TypePayload $payload) use ($builder, $options) {
$payload
->setIfNotEmpty('body._source', $builder->select)
->setIfNotEmpty('body.collapse.field', $builder->collapse)
->setIfNotEmpty('body.sort', $builder->orders)
->setIfNotEmpty('body.explain', $options['explain'] ?? null)
->setIfNotEmpty('body.profile', $options['profile'] ?? null)
->setIfNotNull('body.from', $builder->offset)
->setIfNotNull('body.size', $builder->limit);
foreach ($builder->wheres as $clause => $filters) {
$clauseKey = 'body.query.bool.filter.bool.'.$clause;
$clauseValue = array_merge(
$payload->get($clauseKey, []),
$filters
);
$payload->setIfNotEmpty($clauseKey, $clauseValue);
}
return $payload->get();
});
} | [
"public",
"function",
"buildSearchQueryPayloadCollection",
"(",
"Builder",
"$",
"builder",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"payloadCollection",
"=",
"collect",
"(",
")",
";",
"if",
"(",
"$",
"builder",
"instanceof",
"SearchBuilder",
")",
"{",
"$",
"searchRules",
"=",
"$",
"builder",
"->",
"rules",
"?",
":",
"$",
"builder",
"->",
"model",
"->",
"getSearchRules",
"(",
")",
";",
"foreach",
"(",
"$",
"searchRules",
"as",
"$",
"rule",
")",
"{",
"$",
"payload",
"=",
"new",
"TypePayload",
"(",
"$",
"builder",
"->",
"model",
")",
";",
"if",
"(",
"is_callable",
"(",
"$",
"rule",
")",
")",
"{",
"$",
"payload",
"->",
"setIfNotEmpty",
"(",
"'body.query.bool'",
",",
"call_user_func",
"(",
"$",
"rule",
",",
"$",
"builder",
")",
")",
";",
"}",
"else",
"{",
"/** @var SearchRule $ruleEntity */",
"$",
"ruleEntity",
"=",
"new",
"$",
"rule",
"(",
"$",
"builder",
")",
";",
"if",
"(",
"$",
"ruleEntity",
"->",
"isApplicable",
"(",
")",
")",
"{",
"$",
"payload",
"->",
"setIfNotEmpty",
"(",
"'body.query.bool'",
",",
"$",
"ruleEntity",
"->",
"buildQueryPayload",
"(",
")",
")",
";",
"if",
"(",
"$",
"options",
"[",
"'highlight'",
"]",
"??",
"true",
")",
"{",
"$",
"payload",
"->",
"setIfNotEmpty",
"(",
"'body.highlight'",
",",
"$",
"ruleEntity",
"->",
"buildHighlightPayload",
"(",
")",
")",
";",
"}",
"}",
"else",
"{",
"continue",
";",
"}",
"}",
"$",
"payloadCollection",
"->",
"push",
"(",
"$",
"payload",
")",
";",
"}",
"}",
"else",
"{",
"$",
"payload",
"=",
"(",
"new",
"TypePayload",
"(",
"$",
"builder",
"->",
"model",
")",
")",
"->",
"setIfNotEmpty",
"(",
"'body.query.bool.must.match_all'",
",",
"new",
"stdClass",
"(",
")",
")",
";",
"$",
"payloadCollection",
"->",
"push",
"(",
"$",
"payload",
")",
";",
"}",
"return",
"$",
"payloadCollection",
"->",
"map",
"(",
"function",
"(",
"TypePayload",
"$",
"payload",
")",
"use",
"(",
"$",
"builder",
",",
"$",
"options",
")",
"{",
"$",
"payload",
"->",
"setIfNotEmpty",
"(",
"'body._source'",
",",
"$",
"builder",
"->",
"select",
")",
"->",
"setIfNotEmpty",
"(",
"'body.collapse.field'",
",",
"$",
"builder",
"->",
"collapse",
")",
"->",
"setIfNotEmpty",
"(",
"'body.sort'",
",",
"$",
"builder",
"->",
"orders",
")",
"->",
"setIfNotEmpty",
"(",
"'body.explain'",
",",
"$",
"options",
"[",
"'explain'",
"]",
"??",
"null",
")",
"->",
"setIfNotEmpty",
"(",
"'body.profile'",
",",
"$",
"options",
"[",
"'profile'",
"]",
"??",
"null",
")",
"->",
"setIfNotNull",
"(",
"'body.from'",
",",
"$",
"builder",
"->",
"offset",
")",
"->",
"setIfNotNull",
"(",
"'body.size'",
",",
"$",
"builder",
"->",
"limit",
")",
";",
"foreach",
"(",
"$",
"builder",
"->",
"wheres",
"as",
"$",
"clause",
"=>",
"$",
"filters",
")",
"{",
"$",
"clauseKey",
"=",
"'body.query.bool.filter.bool.'",
".",
"$",
"clause",
";",
"$",
"clauseValue",
"=",
"array_merge",
"(",
"$",
"payload",
"->",
"get",
"(",
"$",
"clauseKey",
",",
"[",
"]",
")",
",",
"$",
"filters",
")",
";",
"$",
"payload",
"->",
"setIfNotEmpty",
"(",
"$",
"clauseKey",
",",
"$",
"clauseValue",
")",
";",
"}",
"return",
"$",
"payload",
"->",
"get",
"(",
")",
";",
"}",
")",
";",
"}"
]
| Build the payload collection.
@param \Laravel\Scout\Builder $builder
@param array $options
@return \Illuminate\Support\Collection | [
"Build",
"the",
"payload",
"collection",
"."
]
| f078a6f9d35b44e4ff440ea31e583973596e9726 | https://github.com/babenkoivan/scout-elasticsearch-driver/blob/f078a6f9d35b44e4ff440ea31e583973596e9726/src/ElasticEngine.php#L98-L157 | train |
babenkoivan/scout-elasticsearch-driver | src/ElasticEngine.php | ElasticEngine.count | public function count(Builder $builder)
{
$count = 0;
$this
->buildSearchQueryPayloadCollection($builder, ['highlight' => false])
->each(function ($payload) use (&$count) {
$result = ElasticClient::count($payload);
$count = $result['count'];
if ($count > 0) {
return false;
}
});
return $count;
} | php | public function count(Builder $builder)
{
$count = 0;
$this
->buildSearchQueryPayloadCollection($builder, ['highlight' => false])
->each(function ($payload) use (&$count) {
$result = ElasticClient::count($payload);
$count = $result['count'];
if ($count > 0) {
return false;
}
});
return $count;
} | [
"public",
"function",
"count",
"(",
"Builder",
"$",
"builder",
")",
"{",
"$",
"count",
"=",
"0",
";",
"$",
"this",
"->",
"buildSearchQueryPayloadCollection",
"(",
"$",
"builder",
",",
"[",
"'highlight'",
"=>",
"false",
"]",
")",
"->",
"each",
"(",
"function",
"(",
"$",
"payload",
")",
"use",
"(",
"&",
"$",
"count",
")",
"{",
"$",
"result",
"=",
"ElasticClient",
"::",
"count",
"(",
"$",
"payload",
")",
";",
"$",
"count",
"=",
"$",
"result",
"[",
"'count'",
"]",
";",
"if",
"(",
"$",
"count",
">",
"0",
")",
"{",
"return",
"false",
";",
"}",
"}",
")",
";",
"return",
"$",
"count",
";",
"}"
]
| Return the number of documents found.
@param \Laravel\Scout\Builder $builder
@return int | [
"Return",
"the",
"number",
"of",
"documents",
"found",
"."
]
| f078a6f9d35b44e4ff440ea31e583973596e9726 | https://github.com/babenkoivan/scout-elasticsearch-driver/blob/f078a6f9d35b44e4ff440ea31e583973596e9726/src/ElasticEngine.php#L246-L263 | train |
babenkoivan/scout-elasticsearch-driver | src/ElasticEngine.php | ElasticEngine.searchRaw | public function searchRaw(Model $model, $query)
{
$payload = (new TypePayload($model))
->setIfNotEmpty('body', $query)
->get();
return ElasticClient::search($payload);
} | php | public function searchRaw(Model $model, $query)
{
$payload = (new TypePayload($model))
->setIfNotEmpty('body', $query)
->get();
return ElasticClient::search($payload);
} | [
"public",
"function",
"searchRaw",
"(",
"Model",
"$",
"model",
",",
"$",
"query",
")",
"{",
"$",
"payload",
"=",
"(",
"new",
"TypePayload",
"(",
"$",
"model",
")",
")",
"->",
"setIfNotEmpty",
"(",
"'body'",
",",
"$",
"query",
")",
"->",
"get",
"(",
")",
";",
"return",
"ElasticClient",
"::",
"search",
"(",
"$",
"payload",
")",
";",
"}"
]
| Make a raw search.
@param \Illuminate\Database\Eloquent\Model $model
@param array $query
@return mixed | [
"Make",
"a",
"raw",
"search",
"."
]
| f078a6f9d35b44e4ff440ea31e583973596e9726 | https://github.com/babenkoivan/scout-elasticsearch-driver/blob/f078a6f9d35b44e4ff440ea31e583973596e9726/src/ElasticEngine.php#L272-L279 | train |
babenkoivan/scout-elasticsearch-driver | src/Payloads/RawPayload.php | RawPayload.setIfNotEmpty | public function setIfNotEmpty($key, $value)
{
if (empty($value)) {
return $this;
}
return $this->set($key, $value);
} | php | public function setIfNotEmpty($key, $value)
{
if (empty($value)) {
return $this;
}
return $this->set($key, $value);
} | [
"public",
"function",
"setIfNotEmpty",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"this",
";",
"}",
"return",
"$",
"this",
"->",
"set",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}"
]
| Set a value if it's not empty.
@param string $key
@param mixed $value
@return $this | [
"Set",
"a",
"value",
"if",
"it",
"s",
"not",
"empty",
"."
]
| f078a6f9d35b44e4ff440ea31e583973596e9726 | https://github.com/babenkoivan/scout-elasticsearch-driver/blob/f078a6f9d35b44e4ff440ea31e583973596e9726/src/Payloads/RawPayload.php#L39-L46 | train |
babenkoivan/scout-elasticsearch-driver | src/Payloads/RawPayload.php | RawPayload.setIfNotNull | public function setIfNotNull($key, $value)
{
if (is_null($value)) {
return $this;
}
return $this->set($key, $value);
} | php | public function setIfNotNull($key, $value)
{
if (is_null($value)) {
return $this;
}
return $this->set($key, $value);
} | [
"public",
"function",
"setIfNotNull",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"this",
";",
"}",
"return",
"$",
"this",
"->",
"set",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}"
]
| Set a value if it's not null.
@param string $key
@param mixed $value
@return $this | [
"Set",
"a",
"value",
"if",
"it",
"s",
"not",
"null",
"."
]
| f078a6f9d35b44e4ff440ea31e583973596e9726 | https://github.com/babenkoivan/scout-elasticsearch-driver/blob/f078a6f9d35b44e4ff440ea31e583973596e9726/src/Payloads/RawPayload.php#L55-L62 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.