Learn WunderGraph
TypeScript Operations
In the previous section, we've used GraphQL to join data across two APIs. Let's see how we can use TypeScript Operations to achieve the same result and go beyond what's possible with pure GraphQL.
Let's start by defining two GraphQL Operations first, so we can fetch a city and weather data.
And the second one for fetching the weather data:
Note that both Operations use the @internalOperation
directive. That's because we don't want to expose them to the public API, but only use them internally.
Last step, we need to define a TypeScript Operation to glue it all together:
TypeScript Operations follow more or less the same structure as GraphQL Operations, the flow is just a bit different. We don't derive a JSON Schema from the GraphQL Variables, but instead use the zod
library to define the input schema.
We're then free to put whatever code we want into the handler
function. In this case, we're using the operations
object passed to the handler to execute the two GraphQL Operations we've defined before.
Let's call our operation:
And we get the following response, it's freezingly cold in Berlin right now: