{"id":13727305,"url":"https://github.com/sikanhe/gqtx","last_synced_at":"2025-05-16T17:05:02.606Z","repository":{"id":40358995,"uuid":"214771811","full_name":"sikanhe/gqtx","owner":"sikanhe","description":"Code-first Typescript GraphQL Server without codegen or metaprogramming","archived":false,"fork":false,"pushed_at":"2024-01-05T22:47:13.000Z","size":56238,"stargazers_count":464,"open_issues_count":14,"forks_count":13,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-05-14T07:13:31.688Z","etag":null,"topics":["graphql","graphql-server","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sikanhe.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-10-13T06:27:34.000Z","updated_at":"2025-04-18T22:38:48.000Z","dependencies_parsed_at":"2024-01-10T21:05:20.950Z","dependency_job_id":null,"html_url":"https://github.com/sikanhe/gqtx","commit_stats":{"total_commits":99,"total_committers":12,"mean_commits":8.25,"dds":0.4949494949494949,"last_synced_commit":"1c709b529fe0b333b906f2b226039f80cfd540d5"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sikanhe%2Fgqtx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sikanhe%2Fgqtx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sikanhe%2Fgqtx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sikanhe%2Fgqtx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sikanhe","download_url":"https://codeload.github.com/sikanhe/gqtx/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254573588,"owners_count":22093731,"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":["graphql","graphql-server","typescript"],"created_at":"2024-08-03T01:03:49.013Z","updated_at":"2025-05-16T17:04:57.596Z","avatar_url":"https://github.com/sikanhe.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"#### [Why another GraphqQL Server?](https://github.com/sikanhe/gqtx/blob/master/WHY.md)\nNote: 0.9.x contains breaking API changes. Go [here](https://github.com/sikanhe/gqtx/blob/1c709b529fe0b333b906f2b226039f80cfd540d5/README.md) for previous readme.\n\n## Getting Started\n\n\u003cp align=\"center\"\u003e\n\u003ccode\u003eyarn add gqtx\u003c/code\u003e\n\u003c/p\u003e\n\n## Type-safety without manual work\n\n`gqtx` is a thin layer on top of `graphql-js` for writing a type-safe GraphQL server in TypeScript. It provides you with a set of helper functions to create an intermediate representation of a GraphQL schema, and then converts that schema to a raw `graphql-js` schema. So you get to use everything from the reference implementation of GraphQL, but with way more type safety.\n\nIf a schema compiles, the following holds:\n\n- The type of a field agrees with the return type of the resolver.\n- The arguments of a field agrees with the accepted arguments of the resolver.\n- The source of a field agrees with the type of the object to which it belongs.\n- The return type of the resolver will not be input types (InputObject)\n- The arguments of a field will not be abstract types (Interface, Union)\n- The context argument for all resolver functions in a schema agree.\n\nMost importantly, we achieve all this _without_ having to:\n\n- Set up code generation tools\n- Write SDL and having your schema partially defined in code and in a DSL file\n- Require special compiler magic such as `reflect-metadata` and decorators\n\n### What does it look like?\n\n```ts\nimport { Gql, buildGraphQLSchema } from 'gqtx';\n\nenum Role {\n  Admin,\n  User,\n}\n\ntype User = {\n  id: string;\n  role: Role;\n  name: string;\n};\n\nconst users: User[] = [\n  { id: '1', role: Role.Admin, name: 'Sikan' },\n  { id: '2', role: Role.User, name: 'Nicole' },\n];\n\n// We can declare the app context type once, and it will\n// be automatically inferred for all our resolvers\ndeclare module \"gqtx\" {\n  interface GqlContext {\n    viewerId: number;\n    users: User[];\n  }\n}\n\nconst RoleEnum = Gql.Enum({\n  name: 'Role',\n  description: 'A user role',\n  values: [\n    { name: 'Admin', value: Role.Admin },\n    { name: 'User', value: Role.User },\n  ],\n});\n\nconst UserType = Gql.Object\u003cUser\u003e({\n  name: 'User',\n  description: 'A User',\n  fields: () =\u003e [\n    Gql.Field({ name: 'id', type: Gql.NonNull(Gql.ID) }),\n    Gql.Field({ name: 'role', type: Gql.NonNull(RoleEnum) }),\n    Gql.Field({ name: 'name', type: Gql.NonNull(Gql.String) }),\n  ],\n});\n\nconst Query = Gql.Query({\n  fields: [\n    Gql.Field({\n      name: 'userById',\n      type: UserType,\n      args: {\n        id: Gql.Arg({ type: Gql.NonNullInput(Gql.ID) }),\n      },\n      resolve: (_, args, ctx) =\u003e {\n        // `args` is automatically inferred as { id: string }\n        // `ctx` (context) is also automatically inferred as { viewerId: number, users: User[] }\n        const user = ctx.users.find((u) =\u003e u.id === args.id);\n        // Also ensures we return an `User | null | undefined` type\n        return user\n      },\n    }),\n  ],\n});\n\nconst schema = buildGraphQLSchema({\n  query: Query,\n});\n```\n\n#### Use your favorite server option to serve the schema!\n\n```ts\nimport express from 'express';\nimport graphqlHTTP from 'express-graphql';\n\nconst app = express();\n\napp.use(\n  '/graphql',\n  graphqlHTTP({\n    schema,\n    graphiql: true,\n  })\n);\n\napp.listen(4000);\n```\n\n## `gqtx` works best with TypeScript `strict` mode\n\nWe recommend using [TypeScript strict mode](https://www.typescriptlang.org/tsconfig#strict) in order to have the best developer experience.\n\n**tsconfig.json**\n\n```diff\n{\n  \"compilerOptions\": {\n+    \"strict\": true\n  }\n}\n```\n\n## To Recap\n\n- We created an intermediate representation of a GraphQL schema via the helper functions exported by this library.\n- Then, we converted the schema to a real graphql-js schema by calling `buildGraphQLSchema` at server startup time.\n- Used existing express middleware `express-graphql` to server our schema with `graphiql` explorer\n- That's it! We get a fully type-safe server with almost zero type annotation needed\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsikanhe%2Fgqtx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsikanhe%2Fgqtx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsikanhe%2Fgqtx/lists"}