Introducing Federated Graphs

Benjamin RabierBenjamin RabierJakub WieczorekJakub WieczorekGraeme CouparGraeme Coupar
Introducing Federated Graphs

Grafbase is excited to announce the introduction of Federated Graphs, a significant enhancement to our GraphQL services. This update marks a pivotal shift from our traditional front-end focus to a broader, more enterprise-scale approach. Here's everything you need to know about this new feature launch.

Federated Graphs allow composing multiple, independently deployed GraphQL APIs into a single schema. This feature significantly enhances the scalability and flexibility of GraphQL architectures.

Federated Graphs

The shift to Federated Graphs addresses the need for scaling GraphQL with larger teams and more complex projects. With Federated Graphs:

  • Each team can work autonomously, developing and deploying their own schemas as needed.
  • Organizations can integrate potentially thousands of microservices as subgraphs, all built on the GraphQL protocol, removing the need for ad-hoc and difficult to maintain gRPC endpoints.

Federation allows each independent subgraph to be stitched together into a unified graph that can be exposed to end users. The Federation gateway determines the most efficient query plan for every query, optimizing for resource use.

Additionally, Grafbase Federated Graphs have:

  • Support for Federation V2 Spec: Aligned with the latest Federation specifications, our Federated Graphs ensure compatibility and performance at the highest level.
  • High-Performance: Crafted in Rust, Federated Graphs offer exceptional performance and reliability, crucial for large-scale applications.
  • Open Source and SDK Integration: Open source availability fosters community engagement and collaboration, while our SDK ensures easy deployment to Grafbase.
  • Advanced Security and Efficiency: Robust authentication and edge caching mechanisms enhance both the security and efficiency of Federated Graphs.
  • Full Stack Deployment on Grafbase: Grafbase supports the deployment of both Federated Graphs and Standalone Subgraphs, providing a comprehensive platform for all GraphQL needs.
  • Scalability: The composition and autonomy offered by Federated Graphs make scaling GraphQL applications more manageable and efficient.
  • Flexibility: Teams gain the flexibility to evolve their subgraphs independently, fostering innovation and rapid development.
  • Simplified Endpoint Management: A single GraphQL endpoint simplifies consumer interactions despite complex architectures.
  • Decentralized Development: Independent evolution of subgraphs eliminates central management needs, reducing bottlenecks.
  • Error Reduction: Schema checks and other safeguards lower the risk of introducing breaking changes, a common issue in traditional methods like REST and gRPC.
  • Improved Developer Experience: By allowing for more autonomous development and combining with the Schema Registry, Federated Graphs enhances the overall developer experience, particularly in large-scale enterprise environments.

To create a federated graph run the following command in a new folder:

npx grafbase@latest init -t federated

This will create the file grafbase.config.ts with the following content:

import { config, graph } from '@grafbase/sdk' export default config({ graph: graph.Federated(), })

Next, install dependencies:

npm install

Now run the following command to start the local development server:

npx grafbase@latest dev

Once the federated graph is up and running on port 4000 it's time to setup and publish a subgraph. To do so, run the following command in a new folder:

npx grafbase@latest init -t openapi-subgraph

This will initialize a new Standalone Graph with an OpenAPI connector configured as a subgraph. Set the SCHEMA_URL environment variable in the .env file to the URL of the OpenAPI spec you want to use, for example the OpenAI OpenAPI spec. Then run the following command to start the local development server after install npm dependencies:

npx grafbase@latest dev --port 4001

Now that the subgraph is up and running on port 4001, it's time to add it to the federated graph. To do so, run the following command in the folder of the subgraph:

npx grafbase@latest publish --dev --name openai --url http://localhost:4001/graphql

Now open Pathfinder at http://localhost:4000 and you should see the generated queries and mutations from the OpenAI subgraph in your federated GraphQL API.

Congratulations, you have successfully created your first federated graph!

Read more about Federated Graphs in our documentation.

The introduction of Federated Graphs represents Grafbase's commitment to evolving alongside the needs of modern, enterprise-level development teams. By offering a more elegant, scalable solution for GraphQL implementation, we're empowering organizations to harness the full potential of their data and services.

Stay tuned for further updates and enhancements as we continue to innovate and support your development journey with Grafbase.