Namespacing for GraphQL: Conflict-Free merging of any number of APIs

Hello Wunderfans! If you enjoy our content, never miss a blog post or a feature update by subscribing to our newsletter or even better, joining our Discord! Hope you enjoy our latest piece and happy coding!

The Problem — How to merge APIs conflict free

To get there, we have to solve a number of problems.

  1. We need to figure out a way to “namespace” our APIs to resolve conflicts
  2. We need a runtime to execute the “namespaced” Operations

GraphQL: The universal API integration language

The first problem to solve is that we need a common language to base our implementation approach on. Without going onto a tangent, let me explain why GraphQL is a great fit for this purpose.

GraphQL and Microservices: Schema Stitching vs. Federation

That said, GraphQL also has a weakness when it comes to API integration. It doesn’t have a concept of namespaces, making it a bit complex to use it for API integration, until now!

One Graph to rule them all, or not!

The number one pattern of Principled GraphQL is about integrity and states:

Your company should have one unified graph, instead of multiple graphs created by each team. By having one graph, you maximize the value of GraphQL:
  • Code, queries, skills, and experience are portable across teams
  • One central catalog of all available data that all graph users can look to
  • Implementation cost is minimized, because graph implementation work isn’t duplicated
  • Central management of the graph — for example, unified access control policies — becomes possible
When teams create their own individual graphs without coordinating their work, it is all but inevitable that their graphs will begin to overlap, adding the same data to the graph in incompatible ways. At best, this is costly to rework; at worst, it creates chaos. This principle should be followed as early in a company’s graph adoption journey as possible.

More data and services can be accessed from a single query

Imagine there was one giant npm package per company with all the dependencies. If you wanted to add axios to your npm package, you’d have to manually copy all the code into your own library and make it “your own” package. This wouldn’t be maintainable.

Code, queries, skills, and experience are portable across teams

It’s right. With just one graph, we can easily share Queries across teams. But is that really a feature? If we split our code into packages and publish them separately, it’s easy for others to pick exactly what they need.

One central catalog of all available data that all graph users can look to

With just one schema, we can have a centralized catalog, true. But keep in mind that this catalog can only represent our own API. What about all the other APIs in the world?

Implementation cost is minimized, because graph implementation work isn’t duplicated

I’d argue that the opposite is true. Especially with Federation, the proposed solution by Apollo to implement a Graph, it becomes a lot more complex to maintain your Graph. If you want to deprecate type definitions across multiple Subgraphs, you have to carefully orchestrate the change across all of them.

Central management of the graph — for example, unified access control policies — becomes possible

It’s interesting what should be possible but isn’t reality. We’re yet to see a centralized access control policy system that add role based access controls for federated graphs. Oh, this is actually one of our features, but let’s not talk about security today.

Why the One Graph principle doesn’t make sense

Building one single Graph sounds like a great idea when your isolated on a tiny isle with no internet. You’re probably not going to consume and integrate any third party APIs.

GraphQL Namespacing: Conflict-free merging of any number of APIs

That leads us to our second problem, naming conflicts.

WunderGraph: A runtime to facilitate namespaced GraphQL

By renaming all types and fields, we’ve actually caused a lot of trouble. Let’s have a look at this Query:

--

--

Building the future of API intergration: wundergraph.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store