{"id":28608073,"url":"https://github.com/expediagroup/graphql-component","last_synced_at":"2025-10-03T17:06:30.675Z","repository":{"id":33960330,"uuid":"161377145","full_name":"ExpediaGroup/graphql-component","owner":"ExpediaGroup","description":"Composeable graphql components","archived":false,"fork":false,"pushed_at":"2025-07-17T16:10:12.000Z","size":606,"stargazers_count":54,"open_issues_count":2,"forks_count":21,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-09-22T02:58:59.954Z","etag":null,"topics":["graphql","oss-portal-featured","schema-stitching"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ExpediaGroup.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-12-11T18:34:03.000Z","updated_at":"2025-09-11T10:32:27.000Z","dependencies_parsed_at":"2022-08-07T23:31:00.604Z","dependency_job_id":"295b821d-df55-49e8-a617-da916a03a7bd","html_url":"https://github.com/ExpediaGroup/graphql-component","commit_stats":null,"previous_names":[],"tags_count":45,"template":false,"template_full_name":null,"purl":"pkg:github/ExpediaGroup/graphql-component","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExpediaGroup%2Fgraphql-component","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExpediaGroup%2Fgraphql-component/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExpediaGroup%2Fgraphql-component/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExpediaGroup%2Fgraphql-component/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ExpediaGroup","download_url":"https://codeload.github.com/ExpediaGroup/graphql-component/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExpediaGroup%2Fgraphql-component/sbom","scorecard":{"id":47801,"data":{"date":"2025-08-11","repo":{"name":"github.com/ExpediaGroup/graphql-component","commit":"b751934be591898212a29a3a0fc6fdd30fd0dab3"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":4.6,"checks":[{"name":"Code-Review","score":5,"reason":"Found 2/4 approved changesets -- score normalized to 5","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":3,"reason":"4 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 3","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/nodejs.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/ExpediaGroup/graphql-component/nodejs.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/nodejs.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/ExpediaGroup/graphql-component/nodejs.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npmpublish.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/ExpediaGroup/graphql-component/npmpublish.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npmpublish.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/ExpediaGroup/graphql-component/npmpublish.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npmpublish.yml:26: update your workflow using https://app.stepsecurity.io/secureworkflow/ExpediaGroup/graphql-component/npmpublish.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npmpublish.yml:27: update your workflow using https://app.stepsecurity.io/secureworkflow/ExpediaGroup/graphql-component/npmpublish.yml/master?enable=pin","Warn: npmCommand not pinned by hash: .github/workflows/nodejs.yml:21","Warn: npmCommand not pinned by hash: .github/workflows/npmpublish.yml:19","Warn: npmCommand not pinned by hash: .github/workflows/npmpublish.yml:32","Info:   0 out of   6 GitHub-owned GitHubAction dependencies pinned","Info:   0 out of   3 npmCommand dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/nodejs.yml:1","Warn: no topLevel permission defined: .github/workflows/npmpublish.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE.txt:0","Info: FSF or OSI recognized license: MIT License: LICENSE.txt:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during GetBranch(v1.x): error during branchesHandler.query: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 29 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-14T23:07:56.279Z","repository_id":33960330,"created_at":"2025-08-14T23:07:56.279Z","updated_at":"2025-08-14T23:07:56.279Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278196448,"owners_count":25946326,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-03T02:00:06.070Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["graphql","oss-portal-featured","schema-stitching"],"created_at":"2025-06-11T21:09:45.315Z","updated_at":"2025-10-03T17:06:30.670Z","avatar_url":"https://github.com/ExpediaGroup.png","language":"TypeScript","readme":"# GraphQL Component\n\n![Build Status](https://github.com/ExpediaGroup/graphql-component/workflows/Build/badge.svg)\n\nA library for building modular and composable GraphQL schemas through a component-based architecture.\n\n## Overview\n\n`graphql-component` enables you to build GraphQL schemas progressively through a tree of components. Each component encapsulates its own schema, resolvers, and data sources, making it easier to build and maintain large GraphQL APIs.\n\nRead more about the architecture principles in our [blog post](https://medium.com/expedia-group-tech/graphql-component-architecture-principles-homeaway-ede8a58d6fde).\n\n## Features\n\n- 🔧 **Modular Schema Design**: Build schemas through composable components\n- 🔄 **Schema Stitching**: Merge multiple component schemas seamlessly\n- 🚀 **Apollo Federation Support**: Build federated subgraphs with component architecture\n- 📦 **Data Source Management**: Simplified data source injection and overrides ([guide](./DATASOURCES.md))\n- 🛠️ **Flexible Configuration**: Extensive options for schema customization\n\n## Installation\n\n```bash\nnpm install graphql-component\n```\n\n## Quick Start\n\n```javascript\n// CommonJS\nconst GraphQLComponent = require('graphql-component');\n\n// ES Modules / TypeScript\nimport GraphQLComponent from 'graphql-component';\n\nconst component = new GraphQLComponent({ \n  types,\n  resolvers \n});\n\nconst { schema, context } = component;\n```\n\n## Core Concepts\n\n### Schema Construction\n\nA `GraphQLComponent` instance creates a GraphQL schema in one of two ways:\n\n1. **With Imports**: Creates a gateway/aggregate schema by combining imported component schemas with local types/resolvers\n2. **Without Imports**: Uses `makeExecutableSchema()` to generate a schema from local types/resolvers\n\n### Federation Support\n\nTo create Apollo Federation subgraphs, set `federation: true` in the component options:\n\n```javascript\nconst component = new GraphQLComponent({\n  types,\n  resolvers,\n  federation: true\n});\n```\n\nThis uses `@apollo/federation`'s `buildFederatedSchema()` instead of `makeExecutableSchema()`.\n\n## API Reference\n\n### GraphQLComponent Constructor\n\n```typescript\nnew GraphQLComponent(options: IGraphQLComponentOptions)\n```\n\n#### Options\n\n- `types`: `string | string[]` - GraphQL SDL type definitions\n- `resolvers`: `object` - Resolver map for the schema\n- `imports`: `Array\u003cComponent | ConfigObject\u003e` - Components to import\n- `context`: `{ namespace: string, factory: Function }` - Context configuration\n- `mocks`: `boolean | object` - Enable default or custom mocks\n- `dataSources`: `Array\u003cDataSource\u003e` - Data source instances\n- `dataSourceOverrides`: `Array\u003cDataSource\u003e` - Override default data sources\n- `federation`: `boolean` - Enable Apollo Federation support (default: `false`)\n- `pruneSchema`: `boolean` - Enable schema pruning (default: `false`)\n- `pruneSchemaOptions`: `object` - Schema pruning options\n- `transforms`: `Array\u003cSchemaMapper\u003e` - Schema transformation functions using `@graphql-tools/utils`\n\n### Component Instance Properties\n\n```typescript\ninterface IGraphQLComponent {\n  readonly name: string;\n  readonly schema: GraphQLSchema;\n  readonly context: IContextWrapper;\n  readonly types: TypeSource;\n  readonly resolvers: IResolvers\u003cany, any\u003e;\n  readonly imports?: (IGraphQLComponent | IGraphQLComponentConfigObject)[];\n  readonly dataSources?: IDataSource[];\n  readonly dataSourceOverrides?: IDataSource[];\n  federation?: boolean;\n}\n```\n\n### Component Instance Methods\n\n#### dispose()\n\nCleans up internal references and resources. Call this method when you're done with a component instance to help with garbage collection:\n\n```typescript\ncomponent.dispose();\n```\n\n## Migration from v5.x to v6.x\n\n### delegateToComponent Removal\n\nIn v6.0.0, `delegateToComponent` was removed. Use `@graphql-tools/delegate`'s `delegateToSchema` instead:\n\n```javascript\n// Before (v5.x - removed)\n// return delegateToComponent(targetComponent, { targetRootField: 'fieldName', args, context, info });\n\n// After (v6.x+)\nimport { delegateToSchema } from '@graphql-tools/delegate';\n\nreturn delegateToSchema({\n  schema: targetComponent.schema,\n  fieldName: 'fieldName', \n  args,\n  context,\n  info\n});\n```\n\nFor more complex delegation scenarios, refer to the [`@graphql-tools/delegate` documentation](https://the-guild.dev/graphql/tools/docs/schema-delegation).\n\n## Usage Examples\n\n### Component Extension\n\n```javascript\nclass PropertyComponent extends GraphQLComponent {\n  constructor(options) {\n    super({ \n      types,\n      resolvers,\n      ...options \n    });\n  }\n}\n```\n\n### Schema Aggregation\n\n```javascript\nconst { schema, context } = new GraphQLComponent({\n  imports: [\n    new PropertyComponent(),\n    new ReviewsComponent()\n  ]\n});\n\nconst server = new ApolloServer({ schema, context });\n```\n\n### Data Sources\n\nData sources in `graphql-component` provide automatic context injection and type-safe data access. The library uses a proxy system to seamlessly inject context into your data source methods.\n\n```typescript\nimport GraphQLComponent, { \n  DataSourceDefinition, \n  ComponentContext,\n  IDataSource\n} from 'graphql-component';\n\n// Define your data source\nclass UsersDataSource implements DataSourceDefinition\u003cUsersDataSource\u003e, IDataSource {\n  name = 'users';\n  \n  // Context is automatically injected as first parameter\n  async getUserById(context: ComponentContext, id: string) {\n    // Access context for auth, config, etc.\n    const token = context.auth?.token;\n    return fetchUser(id, token);\n  }\n}\n\n// Use in resolvers - context injection is automatic\nconst resolvers = {\n  Query: {\n    user(_, { id }, context) {\n      // No need to pass context manually - it's injected automatically\n      return context.dataSources.users.getUserById(id);\n    }\n  }\n};\n\n// Add to component\nconst component = new GraphQLComponent({\n  types,\n  resolvers,\n  dataSources: [new UsersDataSource()]\n});\n```\n\n**Key Concepts:**\n- **Two Patterns**: Injected data sources (via context) or private data sources (via `this`)\n- **Implementation**: Context must be the first parameter in injected data source methods\n- **Usage**: Context is automatically injected for injected data sources\n- **Resolver Binding**: Resolvers are bound to component instances, enabling `this` access\n- **Testing**: Use `dataSourceOverrides` for injected sources, class extension for private sources\n- **Type Safety**: TypeScript interfaces ensure correct implementation\n\nFor comprehensive documentation including both patterns, advanced usage, testing strategies, and common gotchas, see the **[Data Sources Guide](./DATASOURCES.md)**.\n\n### Context Middleware\n\nComponents support context middleware that runs before the component's context is built. This is useful for authentication, logging, or transforming context:\n\n```typescript\nconst component = new GraphQLComponent({\n  types,\n  resolvers\n});\n\n// Add authentication middleware\ncomponent.context.use('auth', async (context) =\u003e {\n  const user = await authenticate(context.req?.headers?.authorization);\n  return { ...context, user };\n});\n\n// Add logging middleware  \ncomponent.context.use('logging', async (context) =\u003e {\n  console.log('Building context for request', context.requestId);\n  return context;\n});\n\n// Use the context (middleware runs automatically)\nconst context = await component.context({ req, requestId: '123' });\n// Context now includes user and logs the request\n```\n\nMiddleware runs in the order it's added and each middleware receives the transformed context from the previous middleware.\n\n## Examples\n\nThe repository includes working example implementations demonstrating different use cases:\n\n### Local Schema Composition\n```bash\nnpm run start-composition\n```\nThis example shows how to compose multiple GraphQL components into a single schema using schema stitching.\n\n### Federation Example\n```bash\nnpm run start-federation\n```\nThis example demonstrates building Apollo Federation subgraphs using GraphQL components.\n\nBoth examples are accessible at `http://localhost:4000/graphql` when running.\n\nYou can find the complete example code in the [`examples/`](./examples/) directory.\n\n## Repository Structure\n\n- `src/` - Core library code\n- `examples/`\n  - `composition/` - Schema composition example\n  - `federation/` - Federation implementation example\n\n## Contributing\n\nPlease read our contributing guidelines (link) for details on our code of conduct and development process.\n\n## License\n\nThis project is licensed under the MIT License - see the LICENSE file for details.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexpediagroup%2Fgraphql-component","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fexpediagroup%2Fgraphql-component","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexpediagroup%2Fgraphql-component/lists"}