Linting for validating graphql.php class names match actual class names locally #1076
Replies: 1 comment
-
As part of your CI you could create a Laravel command like this: <?php declare(strict_types = 1);
namespace App\Console\Commands\GraphQL;
use App\Console\Command;
class ValidateSchema extends Command
{
/** @var string */
protected $signature = 'graphql:validateSchema
{--schema=default : Name of the GraphQL schema to run the query against}
';
/** @var string */
protected $description = 'Validate the given GraphQL schema and output the errors.';
public function handle(): int
{
$schemaName = (string) $this->option('schema');
$schema = app('graphql')->schema($schemaName);
$result = $schema->validate();
if ($result) {
$this->error("Errors have been detected in the given GraphQL schema '$schemaName':");
dump($result);
return 1;
}
$this->info("No errors found in GraphQL schema '$schemaName");
return 0;
}
} Now, if it would have caught this particular error: maybe not, because this is environment specific. Make sure your CI env is as close as possible to your prod env. I've seen this class-case-mismatch errors also, usually things work locally because MacOS and its case-insensitive file system but then fails in prod. Make sure you cover the classes in your tests and run them on a CI with case-sensitive FS. Personally due to this, I haven't experiences this particular issue in years. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
We had an issue recently where our api went completely down due to a 500 error. It was caused by the class name in one of our graphql.php defined types not matching the actual file class name, due to a casing difference.
It failed in a higher environment but not locally, and regardless of casing of the class name, the query worked.
Is there any linting that could prevent this issue or some sort of validation to prevent these errors?
Beta Was this translation helpful? Give feedback.
All reactions