Skip to content
This repository was archived by the owner on Apr 27, 2022. It is now read-only.

Commit 8717a24

Browse files
committed
remove graphql valid,the graphql-php valid is too strict
1 parent bcb09b2 commit 8717a24

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

src/GraphQL.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ public function getTypeResolution()
7474
/**
7575
* Receive schema data and incorporate configuration information
7676
*
77-
* 数组格式
77+
* array format
7878
* $schema = new [
7979
* 'query'=>[
80-
* //配置节点为该$key指向的类型,mutation,types也是如此
80+
* //the key is alias,mutation,types and so on
8181
* 'hello'=>HelloQuery::class
8282
* ],
8383
* 'mutation'=>[],
@@ -93,6 +93,7 @@ public function schema($schema = null)
9393
$schemaTypes = ArrayHelper::getValue($schema, 'types', []);
9494
$this->queries += $schemaQuery;
9595
$this->mutations += $schemaMutation;
96+
$this->types += $schemaTypes;
9697
$this->getTypeResolution()->setAlias($schemaTypes);
9798
}
9899
}
@@ -342,4 +343,20 @@ public function setErrorFormatter(Callable $errorFormatter)
342343
{
343344
$this->errorFormatter = $errorFormatter;
344345
}
346+
347+
/**
348+
* validate the schema.
349+
*
350+
* when initial the schema,the types parameter must not passed.
351+
*
352+
* @param Schema $schema
353+
*/
354+
public function assertValid($schema)
355+
{
356+
//the type come from the TypeResolution.
357+
foreach ($this->types as $name => $type) {
358+
$schema->getType($name);
359+
}
360+
$schema->assertValid();
361+
}
345362
}

src/GraphQLAction.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
use yii\base\InvalidParamException;
1515

1616
/**
17-
* GraphQLAction实现graph服务端的接入方法,并返回json格式的查询结果
18-
* 在controller中配置actions
17+
* GraphQLAction implements the access method of the graph server and returns the query results in the JSON format
18+
* configure in Controller actions method
1919
* ```php
2020
* function actions()
2121
* {
@@ -102,7 +102,7 @@ public function getGraphQLActions()
102102
$ret = array_merge($this->schemaArray[0], $this->schemaArray[1]);
103103
if (!$this->authActions) {
104104
//init
105-
$this->authActions = array_merge($this->schemaArray[0], $this->schemaArray[1]);
105+
$this->authActions = array_keys(array_merge($this->schemaArray[0], $this->schemaArray[1]));
106106
}
107107
return $ret;
108108
}
@@ -128,10 +128,10 @@ public function run()
128128
}
129129
}
130130
$schema = $this->graphQL->buildSchema($this->schemaArray === true ? null : $this->schemaArray);
131-
if ($this->enableSchemaAssertValid) {
132-
//调度状态下将执行构建查询
133-
$schema->assertValid();
134-
}
131+
//TODO the graphql-php's valid too strict,the lazy load has can't pass when execute mutation(must has query node)
132+
// if ($this->enableSchemaAssertValid) {
133+
// $this->graphQL->assertValid($schema);
134+
// }
135135
$val = $this->graphQL->execute($schema, null, Yii::$app, $this->variables, null);
136136
$result = $this->graphQL->getResult($val);
137137
return $result;

0 commit comments

Comments
 (0)