TypeScript Operations Reference
TypeScript Operations Reference
By default, you have to add data sources to your WunderGraph Application using the introspection APIs, which will then allow you to query these using GraphQL.
However, sometimes you want to build something fully custom, or you want to wrap the functionality of an existing API with custom logic. This is what TypeScript Operations are for.
What are TypeScript Operations?
TypeScript Operations behave exactly like GraphQL Operations, except they don't call into the WunderGraph GraphQL Engine, but instead call into your custom TypeScript code.
TypeScript Operations are also defined in the .wundergraph/operations
directory, and they share the same features as GraphQL Operations, like you can configure authentication, authorization, caching, input validation, etc...
TypeScript Operations can also be called exactly the same way as GraphQL Operations. They are being added to the router of your WunderGraph Application, and you can call them from your generated clients the same way as you would call a GraphQL Operation.
How do I use TypeScript Operations?
TypeScript Operations come in three different flavors, similar to GraphQL Operations: Query
, Mutation
and Subscription
.
Here's a typical file structure when using TypeScript Operations:
With this API, we're able to get, create, update, delete and subscribe to users.
Creating TypeScript Read Operations (Query)
Let's define the four operations, starting with the get
operation:
Creating TypeScript Write Operations (Mutation)
Next, let's define the create
operation:
Now, let's implement the update
operation:
Creating TypeScript Subscribe Operations
Finally, let's implement the subscribe
operation:
How do I use TypeScript Operations in my client?
How do I use my TypeScript Operations using plain HTTP, e.g. using curl
Query:
Mutation:
Subscription: