worksome / graphlint
A static analysis tool for GraphQl
Installs: 171 048
Dependents: 0
Suggesters: 0
Security: 0
Stars: 12
Watchers: 13
Forks: 2
Open Issues: 7
Type:project
Requires
- php: ^8.2
- illuminate/support: ^10.0
- jawira/case-converter: ^3.5
- symfony/config: ^6.0
- symfony/console: ^6.1
- symfony/dependency-injection: ^6.0
- symfony/filesystem: ^6.4
- symfony/http-kernel: ^6.0
- symplify/autowire-array-parameter: ^11.0
- symplify/package-builder: ^11.0
- thecodingmachine/safe: ^2.4
- webonyx/graphql-php: ^15.0.1
Requires (Dev)
- pestphp/pest: ^2.34
- symfony/var-dumper: ^6.4
- symplify/easy-testing: ^11.0
- worksome/coding-style: ^2.10.2
Suggests
- ext-dom: Required for Checkstyle output format.
- dev-main
- v0.11.4
- v0.11.3
- v0.11.2
- v0.11.1
- v0.11.0
- v0.10.1
- v0.10.0
- v0.9.0
- v0.8.0
- v0.7.0
- v0.6.2
- v0.6.1
- v0.6.0
- v0.5.3
- v0.5.2
- v0.5.1
- v0.5.0
- v0.4.4
- v0.4.3
- v0.4.2
- v0.4.1
- v0.4.0
- v0.3.1
- v0.3.0
- v0.2.1
- v0.2.0
- v0.1.4
- v0.1.3
- v0.1.2
- v0.1.1
- v0.1.0
- dev-feature/configuration-builder
- dev-dependabot/composer/symfony/var-dumper-tw-7.1
- dev-dependabot/composer/symfony/config-tw-7.0
This package is auto-updated.
Last update: 2024-10-25 15:39:32 UTC
README
A linting tool for GraphQL schemas.
This tool is meant for finding errors in your GraphQL schemas. It is not made for your Queries. The tool contains multiple inspections which can be added to the user's config file for checking for different things. The purpose of this tool is to implement the GraphQL Standard from Worksome.
Installation
The tool can be installed as a composer global dependency via
$ composer global require worksome/graphlint
or via Homebrew
brew tap worksome/tap brew install --formula worksome/tap/graphlint
Usage
The tool can be run via
$ graphlint path/to/schema.graphql
CI Usage with GitHub Actions
With GitHub Actions, we support using the cs2pr
tool to add inline annotations to your pull requests.
graphlint --format=checkstyle path/to/schema.graphql | cs2pr
Configuration
⚠️ Currently the package only supports running on compiled schema. It will later get support for running on original schemas also.
Create a file in the root called graphlint.php
with the following configuration.
<?php declare(strict_types=1); use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; use Worksome\Graphlint\Configuration\Visitor; use Worksome\Graphlint\Inspections\CamelCaseFieldDefinitionInspection; return function (ContainerConfigurator $config): void { $services = $config->services(); $services->set(CamelCaseFieldDefinitionInspection::class) ->tag(Visitor::COMPILED); };
To use the Worksome GraphQL standard:
<?php declare(strict_types=1); use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; use Worksome\Graphlint\GraphlintSet; return function (ContainerConfigurator $config): void { $config->import(GraphlintSet::Standard->value); };
The tool can have a configuration for schemas before compiling and after. Some libraries do not compile their schema, so for those only one of the tags should be used.
Ignoring problems
A problem can be suppressed by adding an ignore-next-line
comment before it.
interface Account { # @graphlint-ignore-next-line id: ID }
In some cases, it is not possible to add a comment because the schema is auto generated. For those cases, the error can be ignored by adding the following in the configuration file.
return function (ContainerConfigurator $config): void { $config->services() ->set(IgnoreByNameSuppressorInspection::class) ->call('configure', [ 'TEST', 'AccountInput.name' // Dotted value for only applying on some fields ]); };
Testing
This package ships with a docker configuration for running the tests. Assuming you have cloned the repository and have docker and docker-compose installed, you can run the tests by running
docker-compose run --rm composer install # Only needed the first time
docker-compose run --rm pest