How expediagroup/graphql-component works
Main Components
• GraphQLComponent Core: Represent the central class that manages schema creation, combining type definitions and resolvers. Illustrate its key responsibilities such as handling:
• Schema composition (merging sub-schemas using graphql-tools stitchSchemas or makeExecutableSchema)
• Apollo Federation integration (via buildSubgraphSchema)
• Importing/sub-component management
• Composition Example: Illustrates a plain Apollo Server environment that builds a composite schema from multiple components (like listing, property, or reviews components).
• Federation Example: Illustrates how your GraphQLComponent is used to generate Apollo Federated sub-schemas that are then aggregated by an Apollo Gateway.
• Supporting Modules in the Library (lib):
• Context Management (lib/context): For decorating and transforming the request context.
• Data Source Integration (lib/datasource): For integrating data sources via context injection with a proxy for stateful operations.
• Resolver and Transformation Layers (lib/resolvers and lib/transforms): For processing GraphQL operations.
• “Inputs”: types, resolvers, imports, directives, dataSources, context options.
• “Operations”: using graphql-tools functions – either stitchSchemas() for composition or Apollo Federation’s buildSubgraphSchema() for federated use.
• “Output”: an executable GraphQLSchema object accessible via the ‘schema’ getter.
• The core GraphQLComponent receives configuration options and then builds a schema.
• Data flows from client requests (through something like Apollo Server or Gateway) to the schema, and further to resolvers and, if applicable, data sources.
Architectural Patterns
• Componentization: Break down the schema into discrete, re-usable components that can be composed (via the ‘imports’ option).
• Context and Data Source Injection: Emphasize how the GraphQLComponent injects a global context (with possible middleware transformations), and wraps provided data sources so that their methods get the context parameters seamlessly.
Relevant Technologies and Libraries
• GraphQL.js – as the underlying GraphQLSchema representation.
• graphql-tools – used for schema stitching and schema building.
• Apollo Federation – for federated schema construction when the ‘federation’ flag is true.
• Apollo Server – in the examples, used to serve the resulting schema.
• Debug – used for logging during component construction, which can be noted as part of the operational flow.
Final Touches
• That you cover both the primary library functionality (inside the lib directory) and how it’s used in the examples (composition vs. federation).