Skip to content
This repository was archived by the owner on Mar 29, 2020. It is now read-only.

Commit cde4caf

Browse files
committed
ensure we have context
1 parent 70faa7e commit cde4caf

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

src/Traits/RelayMiddleware.php

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,25 @@ public function queryMiddleware(Request $request)
3131
$params = json_decode($params, true);
3232
}
3333

34-
$context = Context::get($schema, $query, null, $params);
35-
$operation = $context->operation->operation;
36-
$selectionSet = $context->operation->selectionSet->selections;
37-
38-
foreach ($selectionSet as $selection) {
39-
if (is_object($selection) && $selection instanceof \GraphQL\Language\AST\Field) {
40-
try {
41-
$schema = $relay->find(
42-
$selection->name->value,
43-
$context->operation->operation
44-
);
45-
46-
if (isset($schema['middleware']) && !empty($schema['middleware'])) {
47-
$this->relayMiddleware = array_merge($this->relayMiddleware, $schema['middleware']);
34+
if ($context = Context::get($schema, $query, null, $params)) {
35+
$context = Context::get($schema, $query, null, $params);
36+
$operation = $context->operation->operation;
37+
$selectionSet = $context->operation->selectionSet->selections;
38+
39+
foreach ($selectionSet as $selection) {
40+
if (is_object($selection) && $selection instanceof \GraphQL\Language\AST\Field) {
41+
try {
42+
$schema = $relay->find(
43+
$selection->name->value,
44+
$context->operation->operation
45+
);
46+
47+
if (isset($schema['middleware']) && !empty($schema['middleware'])) {
48+
$this->relayMiddleware = array_merge($this->relayMiddleware, $schema['middleware']);
49+
}
50+
} catch (\Exception $e) {
51+
continue;
4852
}
49-
} catch (\Exception $e) {
50-
continue;
5153
}
5254
}
5355
}

0 commit comments

Comments
 (0)