{"id":14976269,"url":"https://github.com/oguimbal/inversify-graphql","last_synced_at":"2025-10-27T18:30:58.055Z","repository":{"id":57275517,"uuid":"160571449","full_name":"oguimbal/inversify-graphql","owner":"oguimbal","description":"Build dependency-inverted GraphQL schemas with https://github.com/inversify/InversifyJS","archived":false,"fork":false,"pushed_at":"2021-04-20T20:17:00.000Z","size":88,"stargazers_count":15,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-01T07:41:10.342Z","etag":null,"topics":["apollo","apollo-server","apollo-server-express","dependency-injection","graphql","graphql-server","hacktoberfest","inversify","inversifyjs"],"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/oguimbal.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}},"created_at":"2018-12-05T20:00:16.000Z","updated_at":"2025-01-25T19:47:38.000Z","dependencies_parsed_at":"2022-09-15T19:10:32.501Z","dependency_job_id":null,"html_url":"https://github.com/oguimbal/inversify-graphql","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oguimbal%2Finversify-graphql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oguimbal%2Finversify-graphql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oguimbal%2Finversify-graphql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oguimbal%2Finversify-graphql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oguimbal","download_url":"https://codeload.github.com/oguimbal/inversify-graphql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238536147,"owners_count":19488666,"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":["apollo","apollo-server","apollo-server-express","dependency-injection","graphql","graphql-server","hacktoberfest","inversify","inversifyjs"],"created_at":"2024-09-24T13:53:36.252Z","updated_at":"2025-10-27T18:30:52.574Z","avatar_url":"https://github.com/oguimbal.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# inversify-graphql\n\n![build status](https://travis-ci.org/oguimbal/inversify-graphql.svg?branch=master)\n[![npm version](https://badge.fury.io/js/inversify-graphql.svg)](https://badge.fury.io/js/inversify-graphql)\n[![Dependencies](https://david-dm.org/inversify/InversifyJS.svg)](https://david-dm.org/oguimbal/inversify-graphql#info=dependencies)\n[![img](https://david-dm.org/inversify/InversifyJS/dev-status.svg)](https://david-dm.org/oguimbal/inversify-graphql/#info=devDependencies)\n[![img](https://david-dm.org/inversify/InversifyJS/peer-status.svg)](https://david-dm.org/oguimbal/inversify-graphql/#info=peerDependenciess)\n[![Known Vulnerabilities](https://snyk.io/test/github/oguimbal/inversify-graphql/badge.svg)](https://snyk.io/test/github/oguimbal/inversify-graphql)\n\nBuild dependency-inverted GraphQL schemas with [InversifyJS](https://github.com/inversify/InversifyJS)\n\n# Quickstart\n\nSee:\n- the [sample app](sample/minimal/README.md) for a minimal sample\n- the [complex types app](sample/complex-types/README.md) to dive inito more complex inversified types\n\n\n# Usage\n\nInstall the package\n```\nnpm i inversify reflect-metadata graphql inversify-graphql --save\n```\n\nExample using [express](https://www.npmjs.com/package/express) and [apollo-server](https://www.npmjs.com/package/apollo-server)\n\n```typescript\nimport { inversifySchema } from 'inversify-graphql';\n/* ... initialize express \u0026 inversify container */\nconst srv = new agql.ApolloServer({\n    // build inversified schema\n    context: /* whateverContext */,\n    schema: inversifySchema(myContainer, {\n      query: MyRootQuery,\n  }),\n});\nsrv.applyMiddleware({ app, path: '/graphql'});\n\n\n```\n\n```typescript\n// === MyRootQuery definition ==\nexport class MyRootQuery extends InversifyObjectTypeBuilder\u003cvoid, MyContext\u003e {\n\n    // Injected dependency, usable in our resolve() function\n    @inject(MyDependency) dependency: MyDependency;\n\n    config(): InversifyObjectConfig\u003cvoid, MyContext\u003e {\n        return {\n            name: 'MyRoot',\n            // nb: \"fields\" supports 'partial roots', enabling you to describe one object in multiple separate builders\n            //  fields: [PartialRoot1, PartialRoot2],\n            fields: {\n              // compatible with classic GraphQL objects/types\n              classicField: {\n                  type: GraphQLString,\n                  resolve: () =\u003e 'classic'\n              },\n              // use your \"type builders\" to refernece inversified field types\n              inversifiedField: {\n                type: MyType,\n                resolve: () =\u003e this.dependency.getWhateverEntity()\n              },\n              // use InversifiedList to build a GraphQLList of an inversified type.\n              inversifiedListField: {\n                type: InversifyList(MyType),\n                resolve: () =\u003e this.dependency.getWhateverList()\n              }\n            }\n        }\n    }\n}\n\n```\n```typescript\n// === MyType definition ==\nexport class MyType extends InversifyObjectTypeBuilder\u003cMyEntity, MyContext\u003e {\n\n    // Injected dependency, usable in our resolve() function\n    @inject(MyDependency) dependency: MyDependency;\n\n    config(): InversifyObjectConfig\u003cMyEntity, MyContext\u003e {\n      return {\n        //  ... sub fields, using source, context AND inversified dependencies (injectable in this class)\n      }\n    }\n}\n```\n\n# Simple inline type definition\n\nYou can define sub-types \"inline\" (cleaner syntax)\n\n```typescript\nexport class MyType extends InversifyObjectTypeBuilder\u003cMyEntity, MyContext\u003e {\n\n    // Injected dependency, usable in our resolve() function\n    @inject(MyDependency) dependency: MyDependency;\n\n    config(): InversifyObjectConfig\u003cMyEntity, MyContext\u003e {\n      return {\n        myField: {\n          // resolver\n          resolve: () =\u003e 42,\n          // inline type definition\n          type: {\n            name: 'MyInlineType',\n            fields: {\n              subField: {\n                type: GraphQLString,\n                resolve: x =\u003e x + 'is the answer', // will output \"42 is the answer\"\n              }\n            }\n          }\n        }\n      }\n    }\n}\n```\n\n\n# Handy shortcuts\n\nIf like me, you're annoyed with those very long names like `new GraphQLList(new GraphQLNonNull(GraphQLString)))`, you can use the `inversify-graphql/shortcuts` helpers to turn them into  `GList(NN(GString))`.\n\n**nb:** shortcuts are compatible with inversified types ;)\n\n# Modular schema definiton\n\nSome type definitions can tend to be bloated as your app grows.\nIn these cases, you might want to split the definition of types in several files or parts of your application.\n\nThis is the purpose of \"extensible schema\", which builds on top of inversify-graphql to enable you to define a more modular schema.\n\n```typescript\n\nconst adminSchema = extensibleSchema('RootName', container);\n\n// those two partial roots will be merged in the schema root\nadminSchema.query.merge(PartialRoot1);\nadminSchema.query.merge(PartialRoot2);\nadminSchema.mutation.merge(PartialMutationRoot2);\n\n// extend a type\n// the type 'MyTypeToExtend' will augmented with all the fields defined in MyPartialMap\n// nb: this will work even if 'MyTypeToExtend' has not been defined yet\nadminSchema.get('MyTypeToExtend').merge(MyPartialMap);\n\n// you can concatenate two schemas:\n// this will augment the root of \"adminSchema\" with everything defined in \"userSchma\"\nadminSchema.concat(userSchma);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foguimbal%2Finversify-graphql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foguimbal%2Finversify-graphql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foguimbal%2Finversify-graphql/lists"}