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

Better support for lazy fields #6

Open
bwaidelich opened this issue Feb 17, 2024 · 1 comment
Open

Better support for lazy fields #6

bwaidelich opened this issue Feb 17, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@bwaidelich
Copy link
Owner

bwaidelich commented Feb 17, 2024

Currently, the whole object of a query or mutation result is serialized at once and the only way to add lazy evaluated fields is to use custom resolvers.

It would be useful to be able to mark methods as part of the API, for example:

final class Api
{
    #[Query]
    public function someQuery(): SomeObject {
        return new SomeObject('testing');
    }
}

final class SomeObject {
    public function __construct(
        public readonly string $someString,
    ) {}

    #[Field]
    public function someLazyField(): string {
        return 'only evaluated if called';
    }
}
@bwaidelich bwaidelich added the enhancement New feature or request label Feb 17, 2024
@bwaidelich bwaidelich transferred this issue from bwaidelich/Wwwision.GraphQL Feb 17, 2024
@bwaidelich
Copy link
Owner Author

bwaidelich commented Mar 11, 2024

Idea: Add "name" and "lazy" parameter:

final class SomeObject {

   protected string $foo;

    #[Field(name: 'foo')]
    public function getFoo(): string {
    }

   public jsonSerialize(): array {
     return ['foo' => $this->foo];
   }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant