Skip to content

Implement AmpFutureAdapter for integration with AMPHP v3 #1900

Merged
spawnia merged 15 commits into
webonyx:masterfrom
bpteam:ampv3-promise-adapter-implementation
Apr 20, 2026
Merged

Implement AmpFutureAdapter for integration with AMPHP v3 #1900
spawnia merged 15 commits into
webonyx:masterfrom
bpteam:ampv3-promise-adapter-implementation

Conversation

@bpteam

@bpteam bpteam commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

This pull request adds first-class support for AMPHP v3's fiber-based async execution in the GraphQL PHP library, while maintaining compatibility with AMPHP v2. The main change is the introduction of the new AmpFutureAdapter, which allows using Amp\Future for async resolvers. The PR also includes new documentation and examples for AMPHP v3, updates to testing and composer configuration, and ensures smooth migration and compatibility.

Key changes:

AMPHP v3 Support and Async Adapter:

  • Added new AmpFutureAdapter in src/Executor/Promise/Adapter/AmpFutureAdapter.php to enable async execution using AMPHP v3's fiber-based Amp\Future, including full implementation of the required promise adapter interface.
  • Updated Promise class to support Amp\Future as a valid adopted promise type. [1] [2]

Documentation and Examples:

  • Added new AMPHP v3 usage and migration documentation (examples/04-async-php/amphp-v3/event-loop/README.md) and an example schema and HTTP server implementation for AMPHP v3 (examples/04-async-php/amphp-v3/schema.php, examples/04-async-php/amphp-v3/event-loop/graphql.php, examples/04-async-php/amphp-v3/http-server/README.md, examples/04-async-php/amphp-v3/http-server/graphql.php). [1] [2] [3] [4] [5]

Composer and Dependency Management:

  • Updated composer.json to allow installation of both AMPHP v2 and v3 for development, and improved the suggest section to clarify async resolving options. [1] [2]

Testing and QA:

  • Added a comprehensive test suite for AmpFutureAdapter (tests/Executor/Promise/AmpFutureAdapterTest.php) and improved test skipping logic for both AMPHP v2 and v3 adapters. [1] [2]
  • Updated phpstan.neon.dist to ignore errors for missing AMPHP v2 packages in relevant test and example files.

These changes collectively provide robust, documented, and tested support for async GraphQL resolvers using AMPHP v3, while preserving backward compatibility and developer guidance for both versions.

@spawnia spawnia left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Quite solid overall.

Comment thread examples/04-async-php/amphp-v3/event-loop/README.md Outdated
Comment thread examples/04-async-php/amphp-v3/event-loop/README.md Outdated
Comment thread examples/04-async-php/amphp-v3/http-server/graphql.php Outdated
Comment thread examples/04-async-php/amphp-v3/http-server/README.md Outdated
Comment thread examples/04-async-php/amphp-v3/schema.php Outdated
Comment thread tests/Executor/Promise/AmpFutureAdapterTest.php Outdated
Comment thread tests/Executor/Promise/AmpFutureAdapterTest.php Outdated
Comment thread tests/Executor/Promise/AmpPromiseAdapterTest.php Outdated
Comment thread CHANGELOG.md
Comment thread composer.json Outdated
autofix-ci Bot and others added 10 commits April 16, 2026 08:55
Co-authored-by: Benedikt Franke <benedikt@franke.tech>
Co-authored-by: Benedikt Franke <benedikt@franke.tech>
Co-authored-by: Benedikt Franke <benedikt@franke.tech>
Co-authored-by: Benedikt Franke <benedikt@franke.tech>
Co-authored-by: Benedikt Franke <benedikt@franke.tech>
Co-authored-by: Benedikt Franke <benedikt@franke.tech>
Co-authored-by: Benedikt Franke <benedikt@franke.tech>
Co-authored-by: Benedikt Franke <benedikt@franke.tech>
@bpteam bpteam requested a review from spawnia April 16, 2026 14:40
@spawnia

spawnia commented Apr 17, 2026

Copy link
Copy Markdown
Collaborator

Almost there, just some static analysis configuration issue left to fix. Looking good.

@bpteam

bpteam commented Apr 18, 2026

Copy link
Copy Markdown
Contributor Author

Almost there, just some static analysis configuration issue left to fix. Looking good.

Fixed with commit de3f42e

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds AMPHP v3 (fiber-based) async execution support to the GraphQL PHP promise layer via a new adapter, while keeping AMPHP v2 compatibility and documenting v3 usage.

Changes:

  • Introduces AmpFutureAdapter to adapt Amp\Future (AMPHP v3) to the library’s PromiseAdapter interface.
  • Extends promise typing/support to include Amp\Future, adds tests for the new adapter, and adjusts test skipping for v2/v3 environments.
  • Adds AMPHP v3 examples/docs and updates tooling config (Composer + PHPStan) to accommodate optional AMPHP versions.

Reviewed changes

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

Show a summary per file
File Description
tests/Executor/Promise/AmpPromiseAdapterTest.php Skip logic added for missing AMPHP v2 at runtime.
tests/Executor/Promise/AmpFutureAdapterTest.php New test suite validating AmpFutureAdapter behavior under AMPHP v3.
src/Executor/Promise/Promise.php Broadens adopted promise typing to include Amp\Future.
src/Executor/Promise/Adapter/AmpFutureAdapter.php New AMPHP v3 adapter implementation for Amp\Future.
phpstan.neon.dist Adds ignore rules for optional/missing AMPHP types across environments.
examples/04-async-php/amphp-v3/schema.php New v3 example schema using Amp\async() and Amp\Future.
examples/04-async-php/amphp-v3/event-loop/graphql.php New v3 “event-loop” example endpoint wiring.
examples/04-async-php/amphp-v3/event-loop/README.md v3 usage + migration notes from v2 adapter to v3 adapter.
examples/04-async-php/amphp-v3/http-server/graphql.php New v3 HTTP server example integrating AmpFutureAdapter.
examples/04-async-php/amphp-v3/http-server/README.md README for the v3 HTTP server example.
composer.json Allows dev installs with AMPHP v2 or v3; clarifies async suggestions.
CHANGELOG.md Notes addition of AmpFutureAdapter in Unreleased.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/Executor/Promise/AmpPromiseAdapterTest.php Outdated
Comment thread tests/Executor/Promise/AmpFutureAdapterTest.php Outdated
Comment thread examples/04-async-php/amphp-v3/event-loop/graphql.php Outdated
Comment thread phpstan.neon.dist
spawnia and others added 3 commits April 19, 2026 10:58
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@spawnia spawnia merged commit 266ec4b into webonyx:master Apr 20, 2026
21 of 22 checks passed
@spawnia

spawnia commented Apr 20, 2026

Copy link
Copy Markdown
Collaborator

Thanks @bpteam for your contribution! This has been released as part of v15.32.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants