{"id":19273990,"url":"https://github.com/rintoj/hypergraph-graphql","last_synced_at":"2025-08-20T11:23:47.101Z","repository":{"id":177192305,"uuid":"660039211","full_name":"rintoj/hypergraph-graphql","owner":"rintoj","description":"GraphQL package based on TypeORM","archived":false,"fork":false,"pushed_at":"2024-01-11T15:25:47.000Z","size":572,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-07-06T14:03:53.788Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rintoj.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":"2023-06-29T05:39:27.000Z","updated_at":"2023-06-29T06:09:10.000Z","dependencies_parsed_at":"2024-01-11T18:19:06.797Z","dependency_job_id":"ab06c366-9141-4136-87ad-c4725589cfca","html_url":"https://github.com/rintoj/hypergraph-graphql","commit_stats":null,"previous_names":["rintoj/hypergraph-graphql"],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/rintoj/hypergraph-graphql","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rintoj%2Fhypergraph-graphql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rintoj%2Fhypergraph-graphql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rintoj%2Fhypergraph-graphql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rintoj%2Fhypergraph-graphql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rintoj","download_url":"https://codeload.github.com/rintoj/hypergraph-graphql/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rintoj%2Fhypergraph-graphql/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263914155,"owners_count":23529075,"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-09T20:44:45.479Z","updated_at":"2025-07-06T14:04:00.466Z","avatar_url":"https://github.com/rintoj.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Hypergraph GraphQL\n\nThis package is published to handle all the graphql based implementations that can accelerate the\napp development using Hypergraph.\n\n## Install\n\nUsing npm:\n\n```sh\nnpm install @hgraph/graphql\n```\n\nUsing yarn:\n\n```sh\nyarn add @hgraph/graphql\n```\n\n## Usage\n\nCreate `src/schema.ts`\n\n```ts\nimport { createGraphqlSchema } from '@hgraph/graphql'\n\nexport async function createSchema() {\n  return await createGraphqlSchema({\n    resolvers: [`${__dirname}/**/*-resolver.ts`],\n  })\n}\n```\n\nAdd api server `src/index.ts`\n\n```ts\nimport 'reflect-metadata'\n\nimport { initializeGraphqlServer } from '@hgraph/graphql'\nimport { bootstrapServer, createMiddleware } from '@hgraph/server'\nimport { createSchema } from './schema'\n\nasync function run() {\n  const schema = await createSchema()\n  const router = initializeGraphqlServer({ schema })\n  await bootstrapServer({\n    port: 4000,\n    apiRoot: '/api',\n    controllers: [`${__dirname}/**/*-controller.{ts,js}`],\n    middlewares: [createMiddleware(router)],\n  })\n}\n```\n\nCreate a user schema by adding `src/schema/user/user-schema.ts`\n\n```ts\nimport { Field, ObjectType } from 'type-graphql'\nimport { Repository } from 'hypergraph-storage'\n\n@ObjectType()\nexport class User {\n  @Field()\n  id!: string\n\n  @Field()\n  name?: string\n}\n```\n\nAdd resolver `src/resolver/user/user-resolver.ts`\n\n```ts\nimport { Query, Resolver } from 'type-graphql'\nimport { User } from '../../schema/user/user'\n\n@Resolver()\nexport class UserResolver {\n  @Query(() =\u003e User, { nullable: true })\n  me() {\n    return null\n  }\n}\n```\n\nNow start the service.\n\n```sh\nnpx ts-node src/index.ts\n```\n\nThis will expose a new endpoint [http://localhost:4000/graphql](http://localhost:4000/graphql)\n\n## Auth Checker\n\nUpdate `src/schema.ts` to add role based auth check\n\n```ts\nimport { createGraphqlSchema, authChecker } from '@hgraph/graphql'\n\nexport async function createSchema() {\n  return await createGraphqlSchema({\n    resolvers: [`${__dirname}/**/*-resolver.{ts,js}`],\n    authChecker,\n  })\n}\n```\n\nYou can now restrict queries and mutations to be accessible to authenticated and authorized users.\n\n```ts\nimport { Authorized, Resolver, UserRole, Query } from 'type-graphql'\nimport { User } from '../../schema/user/user'\n\n@Resolver()\nexport class UserResolver {\n  @Authorized() // any logged in user can access \"me\"\n  @Query(() =\u003e User, { nullable: true })\n  me() {\n    return null\n  }\n\n  @Authorized(UserRole.ADMIN) // only admin user can access \"user\"\n  @Query(() =\u003e User, { nullable: true })\n  user() {\n    return null\n  }\n}\n```\n\nYou can have your own implementation of `authChecker` with the help of the following snippet.\n\n```ts\nimport { GraphQLContext, UserRole, IdSelector } from '@hgraph/graphql'\nimport { intersection } from 'lodash'\nimport { AuthChecker, ResolverData } from 'type-graphql'\n\nexport const authChecker: AuthChecker\u003cGraphQLContext\u003e = async (\n  { context, args, info, root },\n  allowedRolesOrRule: string[] | Array\u003c(data: ResolverData\u003cGraphQLContext\u003e) =\u003e boolean\u003e,\n) =\u003e {\n  // your implementation\n  throw new Error('Unauthorized')\n}\n```\n\n## Sharable Type\n\nStep 1: Configure the service to enable resolution of user references. Utilize the provided code\nsnippet to achieve this setup.\n\n```tsx\n// user-service/src/schema/user/user-schema.ts\nimport { ShareableType } from '@hgraph/graphql'\nimport { Field, ID } from 'type-graphql'\n\n@ShareableType('User')\nexport class UserSchema {\n  @Field(() =\u003e ID)\n  id!: string\n\n  @Field({ nullable: true })\n  name?: string\n}\n\n// user-service/src/schema.ts\nimport { createGraphqlSchema, referenceResolver } from '@hgraph/graphql'\nimport { UserRepository } from './schema/user/user-repository'\n\nexport async function createSchema() {\n  return await createGraphqlSchema({\n    resolvers: [`${__dirname}/**/*-resolver.ts`],\n    referenceResolvers: {\n      User: referenceResolver(UserRepository), // ← ADD THIS\n    },\n  })\n}\n```\n\nStep 2: In the other service, use `createEntityReference` to instruct the user service to resolve a\nuser by its ID.\n\n```tsx\n// src/query/collaborators-query-resolver.ts\nimport { createEntityReference } from '@hgraph/graphql'\n\n@Resolver()\nexport class CollaboratorsQueryResolver {\n  @Authorized()\n  @Query(() =\u003e [UserSchema])\n  async collaborators(@Ctx() context: GraphQLContext, @Arg('projectId') projectId: string) {\n    const collaborators = await collaboratorRepository.findAll(query =\u003e\n      query.whereEqualTo('projectId', projectId),\n    )\n    // ADD THIS LINE\n    return collaborators.map(collaborator =\u003e createEntityReference('User', collaborator.userId))\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frintoj%2Fhypergraph-graphql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frintoj%2Fhypergraph-graphql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frintoj%2Fhypergraph-graphql/lists"}