{"id":19349181,"url":"https://github.com/tk04/genql","last_synced_at":"2026-05-07T14:31:13.229Z","repository":{"id":122478869,"uuid":"583504731","full_name":"tk04/genql","owner":"tk04","description":"Type-safe Prisma \u0026 GraphQL Generator for the Node.js Ecosystem","archived":false,"fork":false,"pushed_at":"2024-03-22T03:36:43.000Z","size":33,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-06T15:18:35.333Z","etag":null,"topics":["go","graphql","prisma","prisma2","typescript"],"latest_commit_sha":null,"homepage":"","language":"Go","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/tk04.png","metadata":{"files":{"readme":"README.md","changelog":null,"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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-30T01:19:01.000Z","updated_at":"2023-01-07T23:54:23.000Z","dependencies_parsed_at":"2024-03-22T04:31:36.418Z","dependency_job_id":"fe243a8e-e6de-4766-98ef-2a9368c4361d","html_url":"https://github.com/tk04/genql","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tk04%2Fgenql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tk04%2Fgenql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tk04%2Fgenql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tk04%2Fgenql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tk04","download_url":"https://codeload.github.com/tk04/genql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240457988,"owners_count":19804489,"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":["go","graphql","prisma","prisma2","typescript"],"created_at":"2024-11-10T04:25:04.648Z","updated_at":"2026-05-07T14:31:08.199Z","avatar_url":"https://github.com/tk04.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# genql\nPrisma \u0026 GraphQL Generator for the Node.js Ecosystem\n\nInspired by generators from \u003ca href=\"https://hexdocs.pm/phoenix/Mix.Tasks.Phx.Gen.html\" target=\"_blank\"\u003eElixir's Phoenix Framework\u003c/a\u003e and \u003ca href=\"https://guides.rubyonrails.org/command_line.html#bin-rails-generate\" target=\"_blank\"\u003eRuby on Rails\u003c/a\u003e\n# Install\nGenql is installable via homebrew if you’re on Mac or Linux. To install, run the following two commands:\n\n```\n$ brew install tk04/tap/genql\n```\n\nBefore using genql, you must have Prisma set up on your project. After that, you can create a model by running:\n\n```\n$ genql model [model name] field:type:default_value/\"unique\" ....\n```\nAny type value that starts with an upper case character will escape type checking and be inserted in the prisma.schema file as is.\n\n# Example Usage\nYou can create as many fields as you want, and even generate one-to-one, one-to-many, and many-to-many relationships between models. The third value in the colon-separated argument is reserved for default values. You can also include the “unique” keyword, which will add the “@unique” attribute to a given field.\n\nFor example, if we wanted to create a model named “User”, with an auto-incrementing id,  name of type string, and an age of type int, you’d run the following command:\n```\n$ genql model User id:id:ai name:string age:int\n```\nThis will add the following code block to your prisma.schema file:\n```prisma\nmodel User {\n\tid Int @id @default(autoincrement())\n\tname String \n\tage Int \n}\n```\nIn `id:id:ai`, “id” is the field name, “id” is the type, and “ai” (stands for auto increment) dictates the type of the id field and the default value. The other viable entry for an id type is `id:id:uuid`, which generates an Id of type “String”, with a default value of a UUID string. \n\nGenql also supports optional values. For example, if you wanted to make the name value from the previously created model optional, you’d do:\n```\n$ genql model User id:id:ai name:\"string?\" age:int\n```\nThis will generate the following code: \n```prisma\nmodel User {\n\tid Int @id @default(autoincrement())\n\tname String? \n\tage Int \n}\n```\n\nLet’s also create a Friend model, with a default UUID id field, a unique string email field, a name field of type string, and establish a one-to-one relationship between the User and the Friend models. Here is the command to do such a task: \n```\n$ genql model Friend id:id:uuid email:string:unique name:string --OneToOne user:User\n```\nThis command will add the following code to your prisma.schema file:\n\n```prisma\nmodel User {\n\tid Int @id\t@default(autoincrement())\n\tname String? \n\tage Int \n\tfriend Friend? \n}\nmodel Friend {\n\tid String @id\t@default(uuid())\n\temail String @unique\n\tname String \n\tuser User @relation(fields: [userId], references: [id])\n\tuserId Int @unique\n}\n```\n\nNotice that the command also adjusted the User model to establish the one-to-one relationship between the models.\n\n# Create GraphQL Resolvers\nOther than the model command, genql also supports a “resolvers” command, which will create GraphQL resolvers for a given Prisma model. This command makes a lot of assumptions about your current code organization and structure, so it’s not for everyone. It assumes that you use Type-GraphQL, and organize your resolvers under appname/src/resolvers/. The command also creates a types.ts file with each resolver that includes input \u0026 output types to be used in the queries and mutations.\n\nTo showcase using it on the Friend model we created previously, run:\n```\n$ genql resolvers Friend\n```\nThis will create 2 files, both under appname/src/resolvers/Friend. The Index.ts file will contain the queries \u0026 mutations, while the types.ts file will contain the types. The “resolvers” command is supposed to be used as a basic entry point to get you started with developing your resolvers. So you’re expected to add error handling and adjust the generated code depending on your needs.\n\nThis is what the generated Index.ts file will look like:\n\n```typescript\nimport { Arg, Ctx, Mutation, Query, Resolver } from \"type-graphql\";\nimport { context } from \"../context\";\nimport { Friend, createFriendInput, updateFriendInput } from \"./types\";\n\n@Resolver()\nexport class FriendResolver {\n  @Mutation(() =\u003e Friend, { nullable: true })\n  deleteFriend(@Ctx() { prisma }: context, @Arg(\"id\") id: string) {\n    return prisma.friend.delete({\n      where: {\n        id: id,\n      },\n    });\n  }\n  @Query(() =\u003e Friend, { nullable: true })\n  getFriend(@Ctx() { prisma }: context, @Arg(\"id\") id: string) {\n    return prisma.friend.findFirst({\n      where: {\n        id: id,\n      },\n    });\n  }\n  @Mutation(() =\u003e Friend)\n  createFriend(\n    @Ctx() { prisma }: context,\n    @Arg(\"input\") input: createFriendInput\n  ) {\n    return prisma.friend.create({\n      data: {\n        ...input,\n      },\n    });\n  }\n  @Mutation(() =\u003e Friend)\n  updateFriend(\n    @Ctx() { prisma }: context,\n    @Arg(\"input\") input: updateFriendInput\n  ) {\n    return prisma.friend.update({\n      where: { id: input.id },\n      data: {\n        ...input,\n      },\n    });\n  }\n}\n```\n\nAnd this is what the generated types.ts file will look like: \n```typescript\nimport { Field, InputType, ObjectType } from \"type-graphql\";\n\n@ObjectType()\nexport class Friend {\n  @Field({ nullable: true })\n  id?: string;\n  @Field()\n  email: string;\n  @Field()\n  name: string;\n  @Field()\n  userId: number;\n}\n@InputType()\nexport class createFriendInput {\n  @Field({ nullable: true })\n  id?: string;\n  @Field()\n  email: string;\n  @Field()\n  name: string;\n  @Field()\n  userId: number;\n}\n@InputType()\nexport class updateFriendInput {\n  @Field()\n  id: string;\n  @Field({ nullable: true })\n  email?: string;\n  @Field({ nullable: true })\n  name?: string;\n  @Field({ nullable: true })\n  userId?: number;\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftk04%2Fgenql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftk04%2Fgenql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftk04%2Fgenql/lists"}