Skip to Content

WunderGraph DataSources

What are WunderGraph DataSources?#

Resolving Queries, Mutations and Subscriptions in WunderGraph are based around the concept of DataSources.

If you've got some experience with GraphQL, you might be familiar with the concept of Resolvers. Resolvers are functions that "resolve" one or more fields in a GraphQL Operation. DataSources are similar to Resolvers in that they are also responsible to resolve Data.

However, there's an important difference between them. Resolvers are usually implemented by interpreting a GraphQL Operation. That is, the SelectionSet of a Field or Fragment is evaluated at runtime. This is a simple robust approach, used by most GraphQL implementations.

While being simple, the simplicity of the Resolver-Approach comes at a cost. Just-in-time evaluation of Queries can become quite complex and compute heavy. In Garbage collected languages like for example Node.JS, many small objects have to be created and garbage collected at runtime. Resolving queries efficiently is only possible by using look-ahead techniques. These techniques lead to additional overhead at runtime.

Hyperfast Query Execution#

WunderGraph offers sub-millisecond execution overhead by taking a completely different approach. Instead of doing all this overhead at runtime, WunderGraph solves the problem at compile time.

Thunk-based Resolvers offload CPU- & Memory intensive tasks to an Ahead of Time Compiler.

We've developed a multi step compiler that compiles all GraphQL Operations into thunks at compile time. This technique doesn't just make WunderGraph extremely fast, it also reduces the attack surface as there are no arbitrary Queries allowed at runtime. All Operations must go through the compiler to be allowed at runtime.

Removing all the overhead from the runtime allows WunderGraph to execute most requests with sub-millisecond overhead.

Adding more DataSources#

The underlying engine is open source and can be extended easily. Adding another DataSource is a matter of implementing an interface.

If you'd like a DataSource added, please contact us or meet us on Discord.