Skip to content

Conversation

@justlevine
Copy link
Collaborator

@justlevine justlevine commented May 20, 2025

What does this implement/fix? Explain your changes.

This PR improves the type safety across the codebase by reducing the use of mixed and addressing the resulting PHPStan errors.

Additionally, the SchemaConfig syntax was updated to use the [::create() syntax https://webonyx.github.io/graphql-php/schema-definition/#using-config-class], and wrapped in callable for an ostensible perf improvement.

Does this close any currently open issues?

Any other comments?

@justlevine justlevine requested a review from Copilot May 20, 2025 16:39
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR improves type safety across the codebase by updating phpdoc annotations and refining type definitions. Key changes include:

  • Enhanced generic annotations and templates in DebugLog and TypeRegistry.
  • Reworked schema configuration with a builder pattern in SchemaRegistry.
  • Updated docblocks in access-functions to enforce array-based configuration.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/Utils/DebugLog.php Updated phpdoc annotations to use generics for improved type safety
src/Registry/TypeRegistry.php Added TypeDef template and refined type loader and eager map logic
src/Registry/SchemaRegistry.php Migrated to a builder-pattern approach for schema configuration
access-functions.php Revised parameter annotations for better type consistency
Comments suppressed due to low confidence (1)

access-functions.php:225

  • The docblock now enforces that $config should be an array. Verify that all callers of register_graphql_interface_type pass an array to avoid unexpected issues. Consider adding a runtime check to enforce the expected type.
* @param array<string,mixed> $config    The Type config

@qlty-cloud-legacy
Copy link

Code Climate has analyzed commit 3eaa153 and detected 3 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 3

View more on Code Climate.

@justlevine justlevine changed the title chore: improve type safety [2nd pass] chore: improve type safety of TypeRegistry and schema registration May 20, 2025
@coveralls
Copy link

Coverage Status

coverage: 84.246% (+0.01%) from 84.234%
when pulling 3eaa153 on justlevine:chore/type-registry-types
into 161565b on wp-graphql:develop.

/**
* Filter the type before it is loaded into the registry.
*
* @param ?TypeDef $type The type to load.
Copy link
Collaborator Author

@justlevine justlevine May 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what's letting us do all this type-narrowing without it being a real breaking change, since InstrumentSchema::instrument_resolvers() would fatal error if anything other than a Type is passed here.

Which has been in the codebase since 2021: 6c7cc42

Copy link
Collaborator

@jasonbahl jasonbahl Jun 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@justlevine just to clarify, "type-narrowing" in this case is referring to PHP/PHPStan types and not GraphQL Types? The intent of this PR is all about PHP Types, so that's my assumption but wanted to make sure I'm not missing something in regards to GraphQL Types here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, following your linked code in InstrumentSchema, I'm following what you're saying. We were already doing type checks during execution so the Type declaration is safe to add as anything that would break now would have already been broken. 👌

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha yes PHP type namrrowing.

@justlevine justlevine marked this pull request as ready for review May 20, 2025 16:59
@justlevine justlevine requested a review from jasonbahl May 20, 2025 17:00
@justlevine justlevine added status: in review Awaiting review before merging or closing needs: reviewer response This needs the attention of a codeowner or maintainer type: chore Maintenance tasks, refactoring, and other non-functional changes scope: code quality Refactoring, linting, and enforcing coding standards labels May 20, 2025
@jasonbahl jasonbahl merged commit 5e2ed16 into wp-graphql:develop Jun 2, 2025
39 of 40 checks passed
@justlevine justlevine deleted the chore/type-registry-types branch June 2, 2025 20:53
justlevine pushed a commit to justlevine/wp-graphql that referenced this pull request Jun 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs: reviewer response This needs the attention of a codeowner or maintainer scope: code quality Refactoring, linting, and enforcing coding standards status: in review Awaiting review before merging or closing type: chore Maintenance tasks, refactoring, and other non-functional changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants