- How do I install this package in a Laravel project?
- Run `composer require lastdragon-ru/graphql-printer` in your project directory. The package supports PHP 8.0–8.5 and works with webonyx/graphql-php v14.11.9+ or v15.x. No additional Laravel-specific setup is required beyond Composer installation.
- Can I use this to generate a filtered schema for frontend teams?
- Yes. Use the `Printer::export()` method with options like `['types' => ['Query', 'User']]` to include only specific types. This reduces complexity for frontend developers while keeping the schema accurate. Combine with Laravel’s service container for easy access.
- What’s the difference between `print()` and `export()` methods?
- `print()` outputs a single type and its *direct* dependencies (e.g., fields, directives). `export()` includes *all* used types/directives recursively, ensuring a self-contained schema snippet. Use `export()` for standalone documentation and `print()` for debugging specific fragments.
- Does this work with Laravel’s Artisan commands?
- Absolutely. Wrap the printer in a custom Artisan command (e.g., `graphql:schema:dump`) to generate formatted output via CLI. Example: `php artisan graphql:schema:dump --type=User`. The package’s settings can be configured globally in a Laravel service provider.
- How do I handle large schemas (e.g., 500+ types) without performance issues?
- For large schemas, cache the introspection result (e.g., Redis) or use streaming output. The package itself doesn’t enforce limits, but you can optimize by filtering types/directives upfront (e.g., `['types' => ['Query', 'Mutation']]`). Test with your schema size in a staging environment first.
- Can I integrate this with GraphiQL or other GraphQL tools?
- Yes. Use the printer to generate a minimal schema snippet (e.g., for a specific query type) and embed it in GraphiQL’s docs or a Markdown file. The output is pure GraphQL text, so it’s compatible with any tool that accepts schema definitions.
- What Laravel versions does this package support?
- The package is framework-agnostic but works seamlessly with Laravel 8+. It relies on PHP’s Composer autoloading, so no Laravel-specific version constraints exist. Tested with Laravel 9+ and 10+ in production environments.
- How do I check which directives/types are unused in my schema?
- Use the `Printer::getUnusedTypes()` or `getUnusedDirectives()` methods (if available in your version) to analyze the schema. Alternatively, compare the full schema output with a filtered export (e.g., `export(['types' => ['Query']])`) to spot discrepancies manually.
- Will this conflict with existing GraphQL packages like `webonyx/graphql-php`?
- No. This package is a standalone printer and doesn’t modify your GraphQL server. It works alongside `webonyx/graphql-php` or `graphql-php/graphql` by consuming their schema objects. Pin your `graphql-php` version in `composer.json` to avoid dependency conflicts.
- Can I use this for CI/CD schema validation (e.g., diffing changes)?
- Yes. Generate schema snapshots in CI (e.g., GitHub Actions) using the printer’s CLI or programmatic output. Compare hashes or diff the text output against a baseline (e.g., `git diff`) to detect breaking changes. Example: `php artisan graphql:schema:dump > schema.graphql && git add schema.graphql`.