Executor
Sometimes we want to invoke resolver methods directly instead of initiating a full GraphQL query. In such cases, we can use the resolver().toExecutor()
method to create an executor.
Basic Example
Context Injection
Both contexts created via the createContext
method and memoized contexts created via the createMemoization
method can have different values injected when creating an executor.
Unit Testing
Executors are well-suited for unit testing. Here's a simple unit test example:
Non-GraphQL Entry Points
In large-scale backend applications, there are often multiple entry points to invoke application logic. Besides GraphQL, common ones include message queues, gRPC, and scheduled tasks.
We can use executors at these other entry points to invoke application logic.
Here's an example of using an executor in a scheduled task: