{"id":18508109,"url":"https://github.com/imqueue/type-graphql-dependency","last_synced_at":"2025-10-08T17:52:04.310Z","repository":{"id":95268151,"uuid":"344425895","full_name":"imqueue/type-graphql-dependency","owner":"imqueue","description":"Adoption of @imqueue/graphql-dependency for use with type-graphql","archived":false,"fork":false,"pushed_at":"2024-11-08T14:10:19.000Z","size":736,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-17T02:18:09.732Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/imqueue.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2021-03-04T09:53:52.000Z","updated_at":"2024-11-08T14:10:23.000Z","dependencies_parsed_at":"2023-03-03T23:30:41.191Z","dependency_job_id":null,"html_url":"https://github.com/imqueue/type-graphql-dependency","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imqueue%2Ftype-graphql-dependency","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imqueue%2Ftype-graphql-dependency/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imqueue%2Ftype-graphql-dependency/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imqueue%2Ftype-graphql-dependency/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/imqueue","download_url":"https://codeload.github.com/imqueue/type-graphql-dependency/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254112137,"owners_count":22016699,"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","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":[],"created_at":"2024-11-06T15:13:25.930Z","updated_at":"2025-10-08T17:51:59.274Z","avatar_url":"https://github.com/imqueue.png","language":"TypeScript","readme":"# @imqueue/type-graphql-dependency\n\n[![Build Status](https://img.shields.io/github/actions/workflow/status/imqueue/type-graphql-dependency/build.yml)](https://github.com/imqueue/type-graphql-dependency)\n[![License](https://img.shields.io/badge/license-ISC-blue.svg)](https://rawgit.com/imqueue/type-graphql-dependency/master/LICENSE)\n\nAdoption of @imqueue/graphql-dependency for use with type-graphql.\n\n# Install\n\n~~~bash\nnpm i --save @imqueue/type-graphql-dependency\n~~~\n\n# Usage\n\nThis module allows describing cross-service dependencies and fetch user \nrequested data in an optimal manner in a schemas defined using type-graphql\nlibrary.\n\nExample:\n\n~~~typescript\nimport {\n    Dependency,\n    DependencyFor,\n    schemaHooks,\n} from '@imqueue/type-graphql-dependency';\nimport {  Ctx, Info } from 'type-graphql';\nimport { fieldsMap } from 'graphql-fields-list';\n\n@DependencyFor\u003cPartial\u003cConsumer\u003e\u003e({\n   // this defines dependency relations for Consumer object.\n   // refers to: @imqueue/graphql-dependency:Dependency.require()\n   require: [\n       [() =\u003e ApiKey, [\n           { as: 'apiKeys', filter: { 'consumerId': 'id' } }],\n       ],\n   ],\n   // this defines initializer for Consumer, all dependencies will wait\n   // for initializer to finish before load\n   // refers to: @imqueue/graphql-dependency:Dependency.defineInitializer()\n   async init(\n       context: Context,\n       result: Partial\u003cConsumer\u003e,\n       fields?: FieldsInput,\n   ): Promise\u003cDataInitializerResult\u003e {\n       // ... do initializer stuff here ...\n       return result;\n   },\n   // this defines loader for Consumer entity, which should be used by\n   // other entities, which depend on Consumer\n   // refers to: @imqueue/graphql-dependency:Dependency.defineLoader()\n   async load(\n       context: Context,\n       filter: ConsumerListInput,\n       fields?: FieldsInput,\n   ): Promise\u003cPartial\u003cConsumer\u003e[]\u003e {\n       const { data } = await context.consumer.listConsumer(filter, fields);\n       return toConsumers(data);\n   },\n})\n@ObjectType()\nexport class Consumer {\n    // ... Consumer fields definitions goes here ...\n}\n\n// now within a resolver:\nasync function consumerResolver(\n    @Ctx() context: Context,\n    @Info() info: GraphQLResolveInfo,\n) {\n    // load consumer data from some service or database\n    const data = await loadConsumers(/* ... */);\n    // fill dependent data into loaded data\n    await Dependency(Consumer).load(data, context, fieldsMap(info));\n    return data;\n}\n\n// Now where schema is created using type-graphql:\nconst schema = await buildSchema({\n    // your schema options due to type-graphql docs\n});\n// and\n(schemaHooks || []).forEach(handle =\u003e handle \u0026\u0026 handle(schema));\n// so now all deps initialized within schema\n~~~\n\n## License\n\nThis project is licensed under the GNU General Public License v3.0.\nSee the [LICENSE](LICENSE)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimqueue%2Ftype-graphql-dependency","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimqueue%2Ftype-graphql-dependency","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimqueue%2Ftype-graphql-dependency/lists"}