{"id":14976124,"url":"https://github.com/kdby-io/graphql-typescript","last_synced_at":"2025-10-27T18:30:18.355Z","repository":{"id":143930039,"uuid":"120110148","full_name":"kdby-io/graphql-typescript","owner":"kdby-io","description":"Define and build GraphQL Schemas using typed classes","archived":false,"fork":false,"pushed_at":"2019-01-21T13:15:01.000Z","size":115,"stargazers_count":67,"open_issues_count":0,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-10-10T10:03:13.783Z","etag":null,"topics":["annotations","decorators","graphql","graphql-schema","graphql-typescript","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/kdby-io.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":"2018-02-03T16:49:24.000Z","updated_at":"2023-10-10T12:49:30.000Z","dependencies_parsed_at":null,"dependency_job_id":"026bb7ae-8f2d-4205-9a6b-3f48ba164dda","html_url":"https://github.com/kdby-io/graphql-typescript","commit_stats":{"total_commits":35,"total_committers":2,"mean_commits":17.5,"dds":0.02857142857142858,"last_synced_commit":"92020a634408e8d7768d90d62476d646887916c1"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/kdby-io/graphql-typescript","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kdby-io%2Fgraphql-typescript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kdby-io%2Fgraphql-typescript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kdby-io%2Fgraphql-typescript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kdby-io%2Fgraphql-typescript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kdby-io","download_url":"https://codeload.github.com/kdby-io/graphql-typescript/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kdby-io%2Fgraphql-typescript/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281319618,"owners_count":26481035,"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","status":"online","status_checked_at":"2025-10-27T02:00:05.855Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["annotations","decorators","graphql","graphql-schema","graphql-typescript","typescript"],"created_at":"2024-09-24T13:53:21.271Z","updated_at":"2025-10-27T18:30:18.059Z","avatar_url":"https://github.com/kdby-io.png","language":"TypeScript","readme":"# graphql-typescript [![npm](https://img.shields.io/npm/v/graphql-typescript.svg?style=flat-square)](https://www.npmjs.com/package/graphql-typescript) [![npm](https://img.shields.io/npm/dt/graphql-typescript.svg?style=flat-square)](https://www.npmjs.com/package/graphql-typescript) [![CircleCI token](https://img.shields.io/circleci/token/13928c03d7e040db692e4a58e8a387a856d12fd7/project/github/pueue/graphql-typescript/master.svg?style=flat-square)](https://circleci.com/gh/pueue/graphql-typescript/tree/master) [![Coveralls github](https://img.shields.io/coveralls/github/pueue/graphql-typescript/master.svg?style=flat-square)](https://coveralls.io/github/pueue/graphql-typescript?branch=master) [![dependencies Status](https://david-dm.org/pueue/graphql-typescript/status.svg?style=flat-square)](https://david-dm.org/pueue/graphql-typescript)\n\nDefine and build GraphQL Schemas using typed classes\n\n- [Type definition](#type-definition)\n  + [`@Type`](#@type)\n  + [`@Field`](#@field)\n  + [`@Mutation`](#@mutation)\n  + [`@Nullable`](#@nullable)\n  + [`@Input`](#@input)\n  + [Scalar types](#scalar-types)\n- [Arguments](#arguments)\n- [Generating GraphQL Schema](#generating-graphql-schema)\n\n\n```ts\nimport { Type, Field, Nullable, Mutation, String, Boolean, Int, makeSchema } from 'graphql-typescript'\n\n@Type class Query {\n  @Field(() =\u003e Box) box: Box\n}\n\nclass UnboxArguments {\n  @Field(() =\u003e [String]) tools: string[]\n}\n\n@Type class Box {\n  @Field(() =\u003e Size)\n  size: Size\n\n  @Nullable\n  @Field(() =\u003e String)\n  content: string\n\n  @Mutation(() =\u003e Boolean)\n  unbox(box: BoxModel, args: UnboxArguments, context: any) { ... }\n}\n\n@Type class Size {\n  @Field(() =\u003e Int) height: number\n  @Field(() =\u003e Int) width: number\n  @Field(() =\u003e Int) length: number\n}\n\n\nconst schema = makeSchema(Query, {\n  types: [Size, Box]\n})\n```\n\n```graphql\ntype Query {\n  box: Box!\n}\n\ntype Mutation {\n  unbox(tools: [String]!): Boolean!\n}\n\ntype Box {\n  size: Size!\n  content: String\n}\n\ntype Size {\n  height: Int!\n  width: Int!\n  length: Int!\n}\n```\n\n\n### Prerequisites\n\nSet decorator flags in your `tsconfig.json`\n\n```json\n\"experimentalDecorators\": true,\n\"emitDecoratorMetadata\": true\n```\n\n\n### Installing\n\n```\nnpm install -S graphql\nnpm install -S graphql-typescript\n```\n\n\n## Type Definition\n\n### `@Type`\n\nAdding `@Type` to a class definition defines [GraphQL object type](http://graphql.org/learn/schema/#object-types-and-fields).\n\n```ts\n@Type class Character {\n  @Field(() =\u003e String) name: string\n  @Field(() =\u003e [Episode]) appearsIn: Episode[]\n}\n```\n\n```graphql\ntype Character {\n  name: String!\n  appearsIn: [Episode]!\n}\n```\n\n\n### `@Field`\n\nAdding `@Field` to properties or methods of a `@Type` decorated class defines what fields it has.\n\n```ts\n@Type\nclass Hello {\n  @Field(() =\u003e String)\n  a: string\n\n  @Field(() =\u003e [String])\n  b: string[]\n\n  @Field(() =\u003e String)\n  c(_:any, _args: any, context: any) { ... }\n}\n```\n\n```graphql\ntype Hello {\n  a: String!\n  b: [String]!\n  c: String!\n}\n```\n\n\n### `@Mutation`\n\nAdding `@Mutation` to methods of a `@Type` decorated class defines a mutation. No matter which class it is in, it will come under [mutation type](http://graphql.org/learn/schema/#the-query-and-mutation-types).\n\n```ts\nclass Argument {\n  @Field(() =\u003e [Int]) world: number[]\n}\n\n@Type\nclass Hello {\n  @Mutation(() =\u003e String)\n  a(_: any, _args: any, context: any) { ... }\n\n  @Mutation(() =\u003e [String])\n  b(_: any, _args: any, context: any) { ... }\n\n  @Mutation(() =\u003e String)\n  c(_: any, args: Argument, context: any) { ... }\n}\n```\n\n```graphql\ntype Mutation {\n  ...\n  a: String!\n  b: [String]!\n  c(world: [Int]!): String!\n}\n```\n\n\n### `@Nullable`\n\nAll fields and mutations are Non-null type by default.\nAdding `@Nullable to fields or mutations properties make it nullable.\n\n```ts\n@Type\nclass Hello {\n  @Nullable\n  @Field(() =\u003e String)\n  hello: string\n}\n```\n\n```graphql\ntype Hello {\n  hello: String\n}\n```\n\n\n### `@Input`\n\nAdding `@Input` to a class definition defines [a input type](http://graphql.org/learn/schema/#input-types)\nAn input class can only have `@Field` properties.\n\n```ts\n@Input class AddCharacterInput {\n  @Field(() =\u003e String) name: string\n  @Field(() =\u003e Int) age: number\n}\n```\n\n```graphql\ninput AddCharacterInput {\n  name: String!\n  age: Int!\n}\n```\n\n\n### Scalar types\n\nTo use [GraphQL default scalar types](http://graphql.org/learn/schema/#scalar-types), import it from 'graphql-typescript'\n\n```ts\nimport { String, Boolean, Int, Float, ID } from 'graphql-typescript'\n```\n\n## Arguments\n\nAll fields of GraphQL objects type can have arguments. Methods with `@Field` or `@Mutation` get request query arguments from second parameter.\nIt needs to define a argument class. Because a purpose of this class is only typing arguments, there is no class decorator and it can have only `@Field` properties.\n\n```ts\nclass UnboxArguments {\n  @Field(() =\u003e [String]) tools: string[]\n}\n\n@Type class Box {\n  @Mutation(() =\u003e Boolean) unbox(box: BoxModel, args: UnboxArguments) { ... }\n}\n```\n\n```graphql\ntype Mutation{\n  unbox(tools: [String]!): Boolean\n}\n```\n\nTo use input type in argument, do like below.\n\n```ts\n@Input class UnboxInput {\n  @Field(() =\u003e [String]) tools: string[]\n}\nclass UnboxArguments {\n  @Field(() =\u003e UnboxInput) inputs: UnboxInput\n}\n\n@Type class Box {\n  @Mutation(() =\u003e Boolean) unbox(box: BoxModel, args: UnboxArguments) { ... }\n}\n```\n\n```graphql\ninput UnboxInput {\n  tools: [String]!\n}\n\ntype Mutation{\n  unbox(inputs: UnboxInput!): Boolean\n}\n```\n\n\n## Generating GraphQL Schema\n\n```ts\nimport { makeSchema } from 'graphql-typescript'\nimport { Query } from './Query'\nimport { Box } from './Box'\nimport { Character } from './Character'\n\nconst schema = makeSchema(Query, {\n  models: [ Box, Character ]\n})\n```\n\n### `makeSchema`\n\n```ts\nmakeSchema(rootType, {\n  types: [ ... ]\n})\n```\n\n- `rootType`: A root type of schema\n- `types`: Rest of types except a root type\n","funding_links":[],"categories":["\u003ca name=\"TypeScript\"\u003e\u003c/a\u003eTypeScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkdby-io%2Fgraphql-typescript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkdby-io%2Fgraphql-typescript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkdby-io%2Fgraphql-typescript/lists"}