{"id":21927937,"url":"https://github.com/giuliano-marinelli/apollo-dynamic-angular","last_synced_at":"2026-05-10T19:39:56.890Z","repository":{"id":224613118,"uuid":"763770992","full_name":"giuliano-marinelli/apollo-dynamic-angular","owner":"giuliano-marinelli","description":"Apollo Angular but Dynamic! It adds the ability to create dynamic selection sets on queries, mutations and subscriptions, based on decorated schema.","archived":false,"fork":false,"pushed_at":"2024-02-27T16:04:57.000Z","size":124,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-27T11:45:46.604Z","etag":null,"topics":["angular","apollo","apollo-angular","apollo-client","apollo-graphql","decorators","dynamic","selection-set","typescript"],"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/giuliano-marinelli.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-26T22:17:40.000Z","updated_at":"2024-02-26T22:20:40.000Z","dependencies_parsed_at":null,"dependency_job_id":"75cb46c3-271b-4922-a15a-776520143f66","html_url":"https://github.com/giuliano-marinelli/apollo-dynamic-angular","commit_stats":null,"previous_names":["giuliano-marinelli/apollo-dynamic-angular"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/giuliano-marinelli%2Fapollo-dynamic-angular","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/giuliano-marinelli%2Fapollo-dynamic-angular/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/giuliano-marinelli%2Fapollo-dynamic-angular/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/giuliano-marinelli%2Fapollo-dynamic-angular/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/giuliano-marinelli","download_url":"https://codeload.github.com/giuliano-marinelli/apollo-dynamic-angular/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244952803,"owners_count":20537474,"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":["angular","apollo","apollo-angular","apollo-client","apollo-graphql","decorators","dynamic","selection-set","typescript"],"created_at":"2024-11-28T22:19:28.445Z","updated_at":"2026-05-10T19:39:51.861Z","avatar_url":"https://github.com/giuliano-marinelli.png","language":"TypeScript","funding_links":[],"categories":["Architecture and Advanced Topics"],"sub_categories":["GraphQL"],"readme":"# Apollo Dynamic Angular [![npm version](https://badge.fury.io/js/apollo-dynamic-angular.svg)](https://badge.fury.io/js/apollo-dynamic-angular)\n\nApollo Dynamic allows to create dynamic selection sets on queries, mutations and subscriptions when using [`@apollo/client`](https://github.com/apollographql/apollo-client) for consult GraphQL resolvers. It works by decorating entity classes with `@SelectionType` and `@SelectionField` which allows to fabric dynamics selections set with a similar syntax as TypeORM repositories (relations).\n\nThis library is a wrapper of [`apollo-dynamic`](https://github.com/giuliano-marinelli/apollo-dynamic) for Angular, it offer the same `@Injectable` classes as [`apollo-angular`](https://github.com/kamilkisiela/apollo-angular): _Query_, _Mutation_ and _Subscription_. But with support for dynamic selection set based on Apollo Dynamic library. Given the new classes: _DynamicQuery_, _DynamicMutation_ and _DynamicSubscription_.\n\n## Installation\n\n```bash\n$ npm install apollo-dynamic-angular\n\n# dependencies\n$ npm install apollo-dynamic apollo-angular @apollo/client graphql\n```\n\n## Usage\n\n### Decorators\n\nWith this library you have to use the `@SelectionType` and `@SelectionField` from [`apollo-dynamic`](https://github.com/giuliano-marinelli/apollo-dynamic) for decorate your entities interfaces and allow the selection set generation:\n\n```typescript\nimport { SelectionType, SelectionField } from 'apollo-dynamic'\n\n@SelectionType('Person')\nexport class Person {\n    @SelectionField()\n    id?: string;\n\n    @SelectionField()\n    firstname?: string;\n\n    @SelectionField()\n    lastname?: string;\n\n    @SelectionField({ include: 'isSuperAgent' })\n    secret?: string;\n\n    @SelectionField(() =\u003e Profile)\n    profile: Profile;\n\n    @SelectionField(() =\u003e Article)\n    articles: Article[];\n}\n\n@SelectionType('Profile')\nexport class Profile {\n    @SelectionField()\n    avatar: string;\n\n    @SelectionField()\n    nickname: string;\n}\n\n@SelectionType('Article',{\n    default: { relations: { artType: true } }\n})\nexport class Article {\n    @SelectionField({ skip: (cond) =\u003e cond.noIDsPlease })\n    id: string,\n\n    @SelectionField()\n    name: string;\n\n    @SelectionField(() =\u003e Person)\n    person: Person;\n\n    @SelectionField(() =\u003e ArticleType)\n    artType: ArticleType;\n}\n\n@SelectionType('ArticleType')\nexport class ArticleType {\n    @SelectionField()\n    category: string;\n\n    @SelectionField()\n    section: string;\n}\n```\n\n### DynamicQuery, DynamicMutation and DynamicSubscription\n\n---\n\nBut you can use this with [`apollo-angular`](https://github.com/kamilkisiela/apollo-angular) mechanisms. For example:\n\n```typescript\nconst GET_PERSONS = gql`\n  query GetPersons {\n    persons {\n      Person\n    }\n  }\n`;\n```\n\n```typescript\nimport { select } from 'apollo-dynamic';\nimport { Apollo } from 'apollo-angular';\n\n@Component({\n  // ...\n})\nexport class ListPersons implements OnInit {\n  // inject angular-apollo\n  constructor(public apollo: Apollo);\n\n  ngOnInit() {\n    // use it with the \"select\" function\n    this.apollo\n      .query({\n        query: select(GET_PERSONS, { relations: { profile: true } })\n      })\n      .subscribe(/*...*/);\n  }\n}\n```\n\n**Or better**, with the new approach of apollo-angular:\n\n```typescript\nimport { gql } from 'apollo-angular';\nimport { DynamicQuery } from 'apollo-dynamic-angular';\n\n// use \"Dynamic\" version of Query, Mutation or Subscription\n@Injectable({ providedIn: 'root' })\nexport class FindPersons extends DynamicQuery\u003c{ persons: Person[] }\u003e {\n  override document = gql`\n    query Persons {\n      persons {\n        Person\n      }\n    }\n  `;\n}\n```\n\n```typescript\nimport { Component, OnInit } from '@angular/core';\nimport { FindPersons, Person } from './person.entity';\n\n@Component({\n  // ...\n})\nexport class ListPersons implements OnInit {\n  persons: Person[];\n\n  // inject it\n  constructor(private findPersons: FindPersons) {}\n\n  ngOnInit() {\n    // use it\n    this.persons = this.findPersons({ relations: { profile: true } })\n      .fetch()\n      .subscribe({\n        next: ({ data }: any) =\u003e {\n          persons = data.persons;\n        },\n        error: (error: any) =\u003e {\n          console.log(error);\n        }\n      });\n  }\n}\n```\n\nSame apply for **Mutations** and **Subscriptions**.\n\n---\n\n### Please consider reading the [`apollo-dynamic`](https://github.com/giuliano-marinelli/apollo-dynamic#readme) and [`apollo-angular`](https://github.com/kamilkisiela/apollo-angular#readme) usage guides for more information.\n\n## Stay in touch\n\n- Author - [Giuliano Marinelli](https://www.linkedin.com/in/giuliano-marinelli/)\n- Website - [https://github.com/giuliano-marinelli](https://github.com/giuliano-marinelli)\n\n## License\n\nThis package is [MIT licensed](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgiuliano-marinelli%2Fapollo-dynamic-angular","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgiuliano-marinelli%2Fapollo-dynamic-angular","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgiuliano-marinelli%2Fapollo-dynamic-angular/lists"}