# platformatic/graphql-composer architecture

> Architecture diagram of the GitHub repository platformatic/graphql-composer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/platformatic/graphql-composer
- Repository: https://github.com/platformatic/graphql-composer

## Overview

##### Project Type and Purpose
- The README demonstrates usage with Fastify and Mercurius, indicating that the library is intended to be integrated into backend services.

##### File Structure Insights
- The lib directory contains all core modules (composer.js, entity.js, query-builder.js, etc.) that together provide the core functionality of composing, merging, and resolving GraphQL schemas.
- The examples directory shows usage scenarios (e.g., examples/getting-started.js), which is useful for understanding how the library is intended to be used in an application.
- The tests directory shows a thorough unit testing approach for individual components (e.g., composer, network interactions, query and result processing), confirming that the design is modular and well-isolated.

##### Main Components
◦ Composer Engine (Core):
– Represents the central module (lib/composer.js) which implements the compose() function.
– Generates the final supergraph SDL (via Composer.prototype.toSdl) and holds the resolvers (composer.resolvers).

◦ Entity Merging & Resolution:
– Highlight that resolvers for entities have adapters (see fields like argsAdapter) which prepare input for the actual GraphQL resolver functions.

◦ API Server Integration:
– Represent the API service as a separate component that registers the supergraph’s schema and resolvers, enabling clients to issue queries.

##### Highlighting Architectural Patterns and Technologies
– Note that the design follows a modular architecture. The Composer Engine is a central orchestration module that relies on network abstraction, query building, and validation modules.
– Emphasize the framework-agnostic nature of the library, but include a note on its demonstrated integration with Fastify (for the server) and Mercurius (for GraphQL).
» “Schema Merging / Entity Resolution” for internal Composer processes

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Subgraphs
    subgraph "External Subgraphs"
        Books["Books Subgraph API"]:::external
        Reviews["Reviews Subgraph API"]:::external
    end

    %% Core Composition Logic
    subgraph "Core Composition Logic"
        Network["Schema Network Module"]:::core
        Composer["Composer Engine"]:::core
        Entity["Entity Merging & Resolution"]:::core
        Query["Query Building Module"]:::core
    end

    %% API Server Integration
    ApiServer["API Server (Fastify & Mercurius)"]:::integration

    %% Relationships
    Books -->|"Schema Download"| Network
    Reviews -->|"Schema Download"| Network

    Network -->|"Schema Merging"| Composer

    Composer -->|"Entity Resolution"| Entity
    Composer -->|"Query Building"| Query

    Composer -->|"Supergraph Exposure"| ApiServer

    %% Click Events
    click Composer "https://github.com/platformatic/graphql-composer/blob/main/lib/composer.js"
    click Network "https://github.com/platformatic/graphql-composer/blob/main/lib/network.js"
    click Entity "https://github.com/platformatic/graphql-composer/blob/main/lib/entity.js"
    click Entity "https://github.com/platformatic/graphql-composer/blob/main/lib/validation.js"
    click Query "https://github.com/platformatic/graphql-composer/blob/main/lib/query-builder.js"
    click ApiServer "https://github.com/platformatic/graphql-composer/blob/main/examples/getting-started.js"

    %% Styles
    classDef external fill:#FFC107,stroke:#333,stroke-width:2px;
    classDef core fill:#90CAF9,stroke:#333,stroke-width:2px;
    classDef integration fill:#A5D6A7,stroke:#333,stroke-width:2px;
```
