Frequently Asked Questions

Federation Approaches & Concepts

What is GraphQL Mesh and how does it work?

GraphQL Mesh is a framework that allows you to build an executable GraphQL schema from multiple data sources, including REST APIs, databases, gRPC, and other GraphQL services. It aggregates data seamlessly, enabling you to create a cohesive schema without tightly coupling your services. Mesh provides flexibility through resolvers, transformations, and plugins, allowing you to customize and extend your schema as needed. Source

What is Apollo Federation and what are its benefits?

Apollo Federation is a framework for composing a federated schema by combining independent, self-contained GraphQL services (subgraphs). It enables decentralized architecture, allowing each service to have its own schema and be developed and deployed independently. This approach fosters team autonomy, accelerates development cycles, and allows for scalable, maintainable GraphQL architectures. Source

What is Content Federation and how does Hygraph implement it?

Content Federation is the ability to bring data together from multiple sources and backends via API into a centralized data structure or API without migrating the data or duplicating it. Hygraph enables teams to define federated schemas, configure services, and use a built-in Gateway to route queries and aggregate results. This allows editors to enrich and utilize data from diverse systems without developer involvement. Source

How do GraphQL Mesh, Apollo Federation, and Content Federation compare?

All three approaches compose independent services into a federated schema. GraphQL Mesh and Content Federation support various data sources and APIs, while Apollo Federation focuses on GraphQL APIs. Hygraph (Content Federation) offers flexibility in remote sources development and deployment, and provides a built-in Gateway. Apollo Federation requires a centralized gateway, and GraphQL Mesh can operate without one. Source

What are the core concepts of GraphQL Mesh, Apollo Federation, and Content Federation?

The core concepts include schema modularization, efficient data aggregation, and flexible customization to meet specific project needs. Each approach enables you to unite diverse APIs and services into a single, queryable graph. Source

What is the implementation process for Content Federation with Hygraph?

To implement Content Federation with Hygraph, you define federated schemas for each service, configure custom content types and relationships, and use Hygraph's built-in Gateway to route queries and aggregate results. You can add remote sources, create GraphQL remote fields, and test queries to fetch and enrich data from multiple sources. Source

What are the scalability considerations for each federation approach?

GraphQL Mesh can handle scalability and performance considerations by aggregating multiple sources. Apollo Federation provides scalability through independent services, and Content Federation (Hygraph) offers scalability through independent sources and a centralized Gateway. Source

What is the learning curve for GraphQL Mesh, Apollo Federation, and Content Federation?

GraphQL Mesh and Content Federation have a moderate learning curve, while Apollo Federation's learning curve is moderate to high due to its decentralized architecture and gateway setup. Source

How does Hygraph's Gateway function in Content Federation?

Hygraph provides a built-in Gateway that routes queries to the appropriate services and aggregates results into a single response. This enables seamless integration of multiple remote sources and simplifies the process for developers and editors. Source

Can you provide a practical example of Content Federation with Hygraph?

Yes. For example, you can combine an external Cocktail API into a Hygraph project, add remote sources, create GraphQL remote fields, and query for data such as the author's best cocktail, ingredients, and instructions. This demonstrates how Hygraph aggregates and enriches data from multiple sources. Source

What documentation is available for implementing remote sources in Hygraph?

Hygraph provides extensive documentation on remote sources and guides for combining multiple GraphQL queries and sources. You can find more details at Hygraph Remote Sources Documentation and How to run multiple GraphQL queries and combine multiple sources.

What factors should I consider when choosing a federation approach?

Consider your project's requirements, data sources, scalability needs, extensibility, and team expertise. Each approach—GraphQL Mesh, Apollo Federation, and Content Federation—offers different strengths in terms of flexibility, independence, and integration capabilities. Source

Where can I find more information about GraphQL Mesh?

You can find more details about GraphQL Mesh in its official documentation at The Guild GraphQL Mesh Documentation and in the Hygraph blog post GraphQL Mesh vs. Apollo Federation vs. Content Federation.

Where can I read the full comparison of federation approaches?

The full comparison of GraphQL Mesh, Apollo Federation, and Content Federation is available in the Hygraph blog post GraphQL Mesh vs. Apollo Federation vs. Content Federation.

What is the role of schema modularization in federation?

Schema modularization allows you to break down a monolithic GraphQL schema into smaller, manageable services or modules. This enhances maintainability, scalability, and enables independent development and deployment of services. Source

How does Hygraph support content editors in a federated architecture?

Hygraph enables content editors to utilize and enrich data from multiple sources without developer involvement. Its user-friendly interface and content federation capabilities allow editors to aggregate, transform, and manage content efficiently. Source

What are the benefits of using federation in GraphQL architectures?

Federation enables scalable, flexible, and maintainable GraphQL architectures by dividing schemas into smaller, interconnected services. It allows for independent development, easier integration of diverse data sources, and improved system performance. Source

How does Hygraph's Content Federation differ from Apollo Federation?

Hygraph's Content Federation supports various data sources and APIs, offers flexibility in remote sources development, and provides a built-in Gateway. Apollo Federation focuses on GraphQL APIs and requires a centralized gateway for composing subgraphs into a supergraph. Source

What is the significance of the Gateway in federation architectures?

The Gateway routes queries to the appropriate services and aggregates results, enabling seamless integration of multiple sources. In Hygraph, the built-in Gateway simplifies the process for developers and editors, while Apollo Federation requires a centralized gateway for composing subgraphs. Source

How does Hygraph enable querying across multiple remote sources?

Hygraph allows you to add remote sources, create GraphQL remote fields, and aggregate data from multiple APIs and backends. You can query for enriched data across all sources using a single GraphQL query. Source

Features & Capabilities

What are the key capabilities and benefits of Hygraph?

Hygraph offers operational efficiency by eliminating developer dependency, streamlining workflows, and enabling content federation. Financial benefits include reduced operational costs and accelerated speed-to-market. Technical advantages include a GraphQL-native architecture, robust APIs, and enterprise-grade security. Unique features include Smart Edge Cache, custom roles, rich text management, and project backups. Source

How does Hygraph address operational inefficiencies?

Hygraph eliminates dependency on developers for content updates, modernizes legacy tech stacks, and provides a user-friendly interface for content creation and management. It streamlines workflows and ensures content consistency across global teams. Source

What performance features does Hygraph offer?

Hygraph provides Smart Edge Cache for enhanced performance and faster content delivery, high-performance endpoints for reliability and speed, and practical advice for optimizing GraphQL API usage. Source

What security and compliance certifications does Hygraph have?

Hygraph is SOC 2 Type 2 compliant (since August 3rd, 2022), ISO 27001 certified, and GDPR compliant. These certifications ensure enhanced security and compliance standards for enterprise customers. Source

What security features are included in Hygraph?

Hygraph offers granular permissions, SSO integrations, audit logs, encryption at rest and in transit, regular backups, and a process for reporting security issues. Source

How does Hygraph support compliance with regulations?

Hygraph supports compliance with GDPR and CCPA, provides enterprise-grade features like dedicated hosting and custom SLAs, and offers a security and compliance report for certified infrastructure. Source

What feedback have customers given about Hygraph's ease of use?

Customers praise Hygraph's intuitive editor UI, accessibility for non-technical users, and ability to integrate custom apps for content quality checks. Hygraph was recognized for "Best Usability" in Summer 2023. Source

What is the implementation timeline for Hygraph?

Implementation time varies by project. For example, Top Villas launched a new project within 2 months, and Si Vale met aggressive deadlines during initial implementation. Hygraph offers a free API playground, free developer account, structured onboarding, and extensive documentation for quick adoption. Source

What training and support resources does Hygraph provide?

Hygraph offers webinars, live streams, how-to videos, and detailed documentation to support onboarding and ongoing usage. Source

Use Cases & Benefits

Who is the target audience for Hygraph?

Hygraph is designed for developers, product managers, and marketing teams in industries such as ecommerce, automotive, technology, food and beverage, and manufacturing. It is ideal for organizations modernizing legacy tech stacks and global enterprises requiring localization and content federation. Source

What problems does Hygraph solve for businesses?

Hygraph solves operational inefficiencies, financial challenges, and technical issues such as developer dependency, high costs, slow speed-to-market, schema evolution complexity, integration difficulties, cache issues, and localization challenges. Source

How does Hygraph help with content federation and data silos?

Hygraph's content federation integrates multiple data sources without duplication, solving data silos and enabling consistent content delivery across platforms and regions. Source

Can you share customer success stories with Hygraph?

Yes. Komax achieved a 3X faster time-to-market, Autoweb saw a 20% increase in website monetization, Samsung improved customer engagement by 15%, and Stobag increased online revenue share from 15% to 70%. More stories are available at Hygraph Customer Stories.

What KPIs and metrics are associated with Hygraph's solutions?

Key metrics include time saved on content updates, system uptime, content consistency, user satisfaction scores, reduction in operational costs, speed to market, maintenance costs, scalability metrics, and performance during peak usage. More details are available in the CMS KPIs blog.

How does Hygraph differentiate itself in solving pain points?

Hygraph stands out with its user-friendly interface, GraphQL-native architecture, content federation, cost efficiency, accelerated speed-to-market, robust APIs, Smart Edge Cache, and enhanced localization and asset management. It is the first GraphQL-native Headless CMS, offering flexibility and scalability for modern businesses. Source

What is the primary purpose of Hygraph?

Hygraph empowers businesses to build, manage, and deliver exceptional digital experiences at scale. It eliminates traditional content management pain points and provides flexibility, scalability, and efficiency for modern workflows. Source

What is Hygraph's vision and mission?

Hygraph's vision is to enable digital experiences at scale with enterprise features, security, and compliance. Its mission is rooted in values like trust, collaboration, ownership, customer focus, continuous learning, transparency, and action-first. Source

How does Hygraph contribute to achieving its vision?

Hygraph contributes to its vision by providing a GraphQL-native architecture, content federation, Smart Edge Cache, enterprise-grade features, ease of use, and integration capabilities, enabling businesses to scale digital operations efficiently. Source

How does Hygraph handle value objections?

Hygraph addresses value objections by understanding customer needs, highlighting unique features, demonstrating ROI through reduced costs and accelerated speed-to-market, and sharing success stories such as Samsung's improved engagement. Source

Competition & Comparison

How does Hygraph compare to Apollo Federation and GraphQL Mesh?

Hygraph (Content Federation) and GraphQL Mesh both support various data sources and APIs, while Apollo Federation focuses on GraphQL APIs. Hygraph offers flexibility in remote sources development and deployment, and provides a built-in Gateway. Apollo Federation requires a centralized gateway, and GraphQL Mesh can operate without one. Source

What are the strengths of Hygraph compared to other headless CMS platforms?

Hygraph stands out as the first GraphQL-native Headless CMS, offering content federation, user-friendly tools, enterprise-grade security, and integration capabilities. It is best suited for businesses needing flexibility, scalability, and composability. Source

Introducing Click to Edit

GraphQL Mesh vs. Apollo Federation vs. Content Federation

Let's learn about three popular federation approaches: GraphQL Mesh, Apollo Federation, and Content Federation.
Joel Olawanle

Written by Joel 

Aug 14, 2023
GraphQL Mesh vs. Apollo Federation vs. Content Federation

GraphQL has become a popular choice for building APIs due to its flexibility and efficiency in data fetching. But as projects grow in size and complexity, managing a monolithic GraphQL schema can quickly become overwhelming. Adopting a microservices architecture helps decentralize and handle complexity through modularization. However, ensuring efficient communication and coordination between services remains challenging. This is where federation comes into play.

Federation allows you to divide your schema into smaller, interconnected services, making it easier to develop, deploy, and scale your GraphQL architecture.

In this article, you will learn about three popular federation approaches: GraphQL Mesh, Apollo Federation, and Content Federation. You will learn their core concepts, benefits, and code implementations. By the end of this read, you'll have a crystal-clear understanding of each approach to select the perfect federation strategy for your project's success.

#What is GraphQL Mesh?

The GraphQL Mesh framework is used to shape and build an executable GraphQL schema from multiple data sources. In combination with Hive Gateway iIt allows you to use GraphQL query language to access data in remote APIs that don't run GraphQL (and those that run GraphQL).

The key benefit of using GraphQL Mesh is the ability to aggregate data from multiple sources seamlessly. Whether you need to merge data from OpenAPI/Swagger, gRPC, REST APIs, databases, or other GraphQL services, GraphQL Mesh allows you to create a cohesive schema without tightly coupling your services. This modularity enhances maintainability and enables you to introduce new data sources effortlessly.

Diagram of GraphQL Mesh merging REST API, gRPC, and OpenAPI sources into a unified GraphQL Schema

GraphQL Mesh also provides flexibility and customization options. You can modify and extend the merged schema using resolvers, transformations, and directives. This allows you to tailor the schema to your needs, implement business logic, and transform data as it flows through the federation.

Implementation of GraphQL Mesh

To get started with GraphQL Mesh, you'll need to set up a project and then install the necessary dependencies (including Hive Gateway to serve data):

npm i graphql @graphql-hive/gateway @graphql-mesh/compose-cli @omnigraph/openapi

In the project root directory, create a file named mesh.config.ts, which will serve as the configuration file for GraphQL Mesh. Open the file in your text editor and define the data sources you want to federate.

Here's an example of the mesh.config.ts configuration file that includes a REST API and a GraphQL endpoint:

import {
defineConfig,
loadGraphQLHTTPSubgraph,
} from "@graphql-mesh/compose-cli";
import { loadOpenAPISubgraph } from "@omnigraph/openapi";
export const composeConfig = defineConfig({
subgraphs: [
{
sourceHandler: loadOpenAPISubgraph("my-rest-api", {
source: "https://api.example.com/rest/swagger.json",
}),
},
{
sourceHandler: loadGraphQLHTTPSubgraph("my-graphql-api", {
endpoint: "https://api.example.com/graphql",
}),
},
],
});

You can then add a run script to your package.json file:

"scripts": {
"dev": "mesh-compose > supergraph.graphql && hive-gateway supergraph"

When you run npm run dev, GraphQL Mesh will compose a supergraph and start Hive Gateway, where you can query all federated APIs. You can also leverage various GraphQL Mesh and Hive Gateway plugins to add custom resolvers, transformations, and other features to your schema. Both GraphQL Mesh and Hive Gateway provide full support for Apollo Federation, allowing you to work with federated schemas while leveraging their respective features.

#What is Apollo Federation?

Apollo Federation is a framework that enables you to compose a federated schema by combining independent, self-contained GraphQL services (subgraphs). It follows a decentralized architecture, where each service has its schema and can be developed and deployed independently.

In a federated architecture, your individual GraphQL APIs are called subgraphs, and they're composed into a supergraph. Clients can fetch data from all your subgraphs with a single request by querying your supergraph's router.

Apollo Federation diagram showing Apollo Server unifying subgraphs like Auth Service and Planet Service

One major advantage of Apollo Federation is that you can develop and scale services independently. This decentralized approach fosters team autonomy and accelerates development cycles. Each service can focus on its specific domain, and changes can be made without impacting other services.

Implementation of Apollo Federation

To demonstrate how Apollo Federation works, let's consider an example where you have two services: products and reviews. The products service provides information about products, and the reviews service manages customer reviews for those products. You'll create a federated graph that combines these services.

First, set up the product's service. Create a new file called products.js and add the following code:

const { ApolloServer, gql } = require('apollo-server');
const { buildSubgraphSchema } = require('@apollo/subgraph');
const typeDefs = gql`
type Product @key(fields: "id") {
id: ID!
name: String!
}
extend type Query {
products: [Product]
}
`;
const products = [
{ id: '1', name: 'Product 1' },
{ id: '2', name: 'Product 2' },
];
const resolvers = {
Query: {
products: () => products,
},
};
const server = new ApolloServer({
schema: buildSubgraphSchema([{ typeDefs, resolvers }]),
});
server.listen(4001).then(({ url }) => {
console.log(`Products service running at ${url}`);
});

This code defines a GraphQL type Product with an id and name field. You also extend the Query type to include a products field that returns an array of Product objects.

Next, set up the reviews service. Create a new file called reviews.js and add the following code:

const { ApolloServer, gql } = require('apollo-server');
const { buildSubgraphSchema } = require('@apollo/subgraph');
const typeDefs = gql`
type Review @key(fields: "id") {
id: ID!
productId: ID!
rating: Int!
comment: String!
}
extend type Product @key(fields: "id") {
id: ID! @external
reviews: [Review]
}
extend type Query {
reviews: [Review]
}
`;
const reviews = [
{ id: '1', productId: '1', rating: 5, comment: 'Great product!' },
{ id: '2', productId: '2', rating: 4, comment: 'Nice product.' },
];
const resolvers = {
Product: {
reviews: (parent) =>
reviews.filter((review) => review.productId === parent.id),
},
Query: {
reviews: () => reviews,
},
};
const server = new ApolloServer({
schema: buildSubgraphSchema([{ typeDefs, resolvers }]),
});
server.listen(4002).then(({ url }) => {
console.log(`Reviews service running at ${url}`);
});

This code defines a GraphQL type Review with fields id, productId, rating, and comment. You also extend the Product type to include a reviews field, representing the reviews associated with a particular product. The @external directive indicates that the id field is defined in another service. You also extend the Query type to include a reviews field that returns all reviews.

You need to create a gateway combining these services into a federated graph. Create an index.js file and add the following code:

const { ApolloServer } = require('apollo-server');
const { ApolloGateway, IntrospectAndCompose } = require('@apollo/gateway');
const gateway = new ApolloGateway({
supergraphSdl: new IntrospectAndCompose({
subgraphs: [
{ name: 'products', url: 'http://localhost:4001' },
{ name: 'reviews', url: 'http://localhost:4002' },
],
}),
});
const server = new ApolloServer({
gateway,
});
server.listen(4000).then(({ url }) => {
console.log(`Server ready at ${url}`);
});

This code sets up an Apollo gateway using the ApolloGateway class from the @apollo/gateway package. We define the subgraphs and supergraphSdl. Each service entry includes a name and a url indicating the location of the respective service.

To run the example, you add commands for each subgraph and the gateway in your package.json file:

"scripts": {
"server:products": "nodemon products.js",
"server:reviews": "nodemon reviews.js",
"server:graphql": "nodemon index.js"
},

When you run npm run server, the Apollo sandbox will open for you to test the federated GraphQL schemas.

#What is Content Federation?

Content Federation is the ability to bring data together from multiple sources and backends via API into a centralized data structure or API without migrating the data or having multiple versions of it. This allows for a single view (centralized) of the data.

Diagram of Content Federation with Hygraph connecting diverse sources like Salesforce and Shopify to frontend channels

Content Federation is especially useful when you have multiple data sources and want to merge them and allow content editors to utilize and enrich data and content without developer involvement. It allows you to aggregate content from diverse systems, apply transformations, and enrich it with additional data. This approach enables you to create powerful and tailored content APIs that client applications can easily consume.

One major player in the world of content federation is Hygraph — a federated content management platform.

Implementation of Content Federation with Hygraph

Hygraph is a federated content management platform that enables teams to provide content to any channel. If this is your first time exploring Hygraph, create a free-forever developer account via either GitHub or Mail.

Here are the steps you will follow to implement federation with Hygraph:

  1. Define the federated schema: To define the Federated Schema with Hygraph, you must create multiple smaller schemas for each service.

  2. Configure the services: Configure each service with its own schema, data types, and resolvers. With Hygraph, you can create custom content types, fields, and relationships for each service.

  3. Create a gateway: Create a Gateway to route queries to the appropriate services and aggregate the results into a single response. Hygraph provides a built-in Gateway that you can use to route queries to your services.

Once you have done this, you can send queries to your Gateway and receive responses. For this article, let’s combine the Cocktail API (an external API) into an Hygraph project and query for data with a single GraphQL query.

Step 1: Add a remote source

The first step is to add a remote source, specify the type of the API, name and paste the API address:

Step1-remote source.gif

Step 2: Create a GraphQL remote field

Create a field for the data you will use to query for a particular cocktail. For this, I will create two fields, the "Best cocktail" field for you to submit the best cocktail of the author, and a slug field (Cocktail Slug) that will automatically convert the "Best cocktail" data to slug.

Hygraph schema editor showing the 'Best Cocktail' text field and a 'Cocktail Slug' field configured as a unique slug

You can now create the GraphQL remote field to query for a particular cocktail with the slug value.

Step 2-Create a GraphQL remote field.gif

Step 3: Test the remote source

You have created a GraphQL remote field for the cocktail Info. Test it by adding the author's best cocktail, which would generate a slug value, and then you can use it to get the particular cocktail information.

Step 3-test.gif

At this point, you have successfully added and combined multiple remote sources into your Hygraph project. Create a GraphQL query to fetch the author's data, including the author's best cocktail, ingredients, and instructions for making it.

query AuthorsInfo {
authors {
firstName
lastName
bio
bestCocktail
cocktailInfo {
info
ingredients
instructions
}
}
}

This will return all the various values, including the ones from the remote sources, directly into this GraphQL query:

{
"data": {
"authors": [
{
"firstName": "John ",
"lastName": "Doe",
"bio": null,
"bestCocktail": "paloma",
"cocktailInfo": {
"info": "Alcoholic",
"ingredients": "Grape Soda Tequila",
"instructions": "Stir Together And Serve Over Ice."
}
}
]
}
}

You can explore more by reading the remote sources documentation and this article on How to run multiple GraphQL queries and combine multiple sources.

#GraphQL Mesh vs. Apollo Federation vs. Content Federation: comparison and considerations

After exploring GraphQL Mesh, Apollo Federation, and Content Federation, it's important to compare their differences and consider the factors that impact your project.

Factors GraphQL Mesh Apollo Federation Content Federation
Architecture Combines multiple schemas into a federated schema Composes independent services into a federated schema Composes independent services into a federated schema accessible to developers and editors
Data Sources Supports various data sources and APIs Supports GraphQL APIs Supports various data sources and APIs
Flexibility Allows customization using resolvers, transformations, and plugins Offers flexibility in service development and deployment Offers flexibility in remote sources development and deployment
Independence Can operate without the need for a centralized gateway Services can be developed and deployed independently Remote sources can be developed and deployed independently
Gateway Not required Requires a centralized gateway Hygraph is the gateway
Scalability Can handle scalability and performance considerations Provides scalability through independent services Provides scalability through independent sources
Learning Curve Moderate Moderate to high Moderate

#Conclusion

Choosing the right federation approach for your GraphQL architecture significantly impacts your system's scalability, flexibility, and maintainability. In this article, we explored GraphQL Mesh, Apollo Federation, and Content Federation, three popular federation approaches, and discussed their core concepts, benefits, and code implementations.

Before choosing the best approach for your project, consider the specific requirements and constraints, along with factors like data sources, scalability, and extensibility; then, you’ll be able to make a perfect decision.

By leveraging the power of federation, you can build robust and scalable GraphQL architectures that meet the evolving needs of your application.

The GraphQL Report 2024

Statistics and best practices from prominent GraphQL users.

Blog Author

Joel Olawanle

Joel Olawanle

Joel Olawanle is a Frontend Engineer and Technical writer based in Nigeria who is interested in making the web accessible to everyone by always looking for ways to give back to the tech community. He has a love for community building and open source.

Share with others

Sign up for our newsletter!

Be the first to know about releases and industry news and insights.