Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce StandardTypeRegistry #1426

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Commits on Aug 14, 2023

  1. Introduce StandardTypeRegistry

    Currently, types are referenced and cached statically. This is problematic when using multiple
    schema's that have different standard types that share the same memory. For example, when running
    them in un-isolated unit tests or when there is a long running PHP process that serves GraphQL
    requests.
    
    To solve this problem, we introduce a `StandardTypeRegistry` interface with a `DefaultTypeRegistry`
    implementation. People are allowed to create their own registries by implementing the interface.
    Every Schema should be constructed with a `typeRegistry` that is an instance of
    `StandardTypeRegistry`. From there on, all types are queried from the registry. The registry will
    be responsible for caching the types to make sure subsequent calls to the same type will return the
    same instance.
    
    Internally, all static calls to the standard types (Type::string(), Type::int(), Type::float(),
    Type::boolean(), Type::id()) have been replaced with dynamic calls on the type registry. Also calls
    to the introspection objects and internal directives are using the type registry now.
    
    As most people probably have only one schema, we keep the static methods on the Type call. These now
    forward to `DefaultTypeRegistry::getInstance()`. This way, we don't break existing installations.
    
    The reason for creating a `StandardTypeRegistry` interface as opposed to just a non-final
    implementation is that it allows people to use composition instead of inheritance to extend the
    functionality of the registry. For example, in my project I'd like to have a registry that holds
    all types and that allows me to query any type by their name (instead of FQCN). I can then delegate
    the interface methods to the decorated `StandardTypeRegistry`.
    
    Resolves webonyx#1424
    ruudk committed Aug 14, 2023
    Configuration menu
    Copy the full SHA
    47530c7 View commit details
    Browse the repository at this point in the history
  2. Apply feedback

    ruudk committed Aug 14, 2023
    Configuration menu
    Copy the full SHA
    287e1e9 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    0d3ff24 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    fb12480 View commit details
    Browse the repository at this point in the history
  5. Apply php-cs-fixer changes

    ruudk authored and github-actions[bot] committed Aug 14, 2023
    Configuration menu
    Copy the full SHA
    1494762 View commit details
    Browse the repository at this point in the history

Commits on Aug 15, 2023

  1. Fix type

    ruudk committed Aug 15, 2023
    Configuration menu
    Copy the full SHA
    193a8ef View commit details
    Browse the repository at this point in the history
  2. Prettify docs

    ruudk authored and actions-user committed Aug 15, 2023
    Configuration menu
    Copy the full SHA
    12252ac View commit details
    Browse the repository at this point in the history
  3. Remove Introspection from StandardTypeRegistry

    We now store this separately.
    ruudk committed Aug 15, 2023
    Configuration menu
    Copy the full SHA
    432cc04 View commit details
    Browse the repository at this point in the history
  4. Prettify docs

    ruudk authored and actions-user committed Aug 15, 2023
    Configuration menu
    Copy the full SHA
    9d7d6e0 View commit details
    Browse the repository at this point in the history