{"id":19566379,"url":"https://github.com/juliendargelos/deno-graphql-api","last_synced_at":"2025-08-01T10:04:14.283Z","repository":{"id":89723181,"uuid":"350078152","full_name":"juliendargelos/deno-graphql-api","owner":"juliendargelos","description":"Template for a deno modular GraphQL api.","archived":false,"fork":false,"pushed_at":"2021-03-21T18:09:47.000Z","size":47,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-26T09:45:20.315Z","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/juliendargelos.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":"2021-03-21T18:02:10.000Z","updated_at":"2021-03-22T00:30:38.000Z","dependencies_parsed_at":null,"dependency_job_id":"ec28584d-8751-4a4f-9408-c6b0da819b18","html_url":"https://github.com/juliendargelos/deno-graphql-api","commit_stats":null,"previous_names":[],"tags_count":0,"template":true,"template_full_name":null,"purl":"pkg:github/juliendargelos/deno-graphql-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juliendargelos%2Fdeno-graphql-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juliendargelos%2Fdeno-graphql-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juliendargelos%2Fdeno-graphql-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juliendargelos%2Fdeno-graphql-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/juliendargelos","download_url":"https://codeload.github.com/juliendargelos/deno-graphql-api/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/juliendargelos%2Fdeno-graphql-api/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268205718,"owners_count":24212999,"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-08-01T02:00:08.611Z","response_time":67,"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":[],"created_at":"2024-11-11T05:31:32.453Z","updated_at":"2025-08-01T10:04:14.206Z","avatar_url":"https://github.com/juliendargelos.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# deno-graphql-api\n\nTemplate for a deno modular GraphQL api.\n\n### Modules\n\nThe API is splitted in several modules located in the `modules` folder. To add a module, create a file `modules/mymodule/mod.ts`. A module can export a set of models, resolvers and GraphQL types thath will be passed to [cotton](https://github.com/rahmanfadhil/cotton) and [oak_graphql](https://github.com/aaronwlee/oak-graphql)\n\n#### CRUD module\n\nThis is the [article crud module example](modules/article):\n\n##### Define types\n\n```graphql\n# modules/articles/types.ts\n\ntype Article {\n  uuid: ID!\n  title: String!\n  content: String!\n}\n\ninput ArticleInput {\n  title: String\n  content: String\n}\n\ninput ArticleFilter {\n  page: Int\n}\n\nextend type Query {\n  article(uuid: ID!): Article!\n  articles(filter: ArticleFilter): [Article!]!\n}\n\nextend type Mutation {\n  createArticle(input: ArticleInput!): Article!\n  updateArticle(uuid: ID!, input: ArticleInput!): Article!\n  deleteArticle(uuid: ID!): Boolean!\n}\n```\n\n##### Define a model\n\n```typescript\n// modules/articles/Article.ts\n\nimport { BaseModel, Model, Column, DataType } from '~/modules/core/Model.ts'\n\n@Model('articles') export class Article extends BaseModel {\n  @Column({ type: DataType.String }) title!: string\n  @Column({ type: DataType.String }) content!: string\n}\n```\n\n##### Define resolvers\n\n```typescript\n// modules/articles/resolvers.ts\n\nimport { Article } from './Article.ts'\n\nexport const Query = {\n  async article(parent: any, { uuid }: any): Promise\u003cArticle\u003e {\n    return Article.find(uuid)\n  },\n\n  async articles(parent: any, { filter }: any): Promise\u003cArticle[]\u003e {\n    return Article.query().limit(10).offset(filter?.page * 10 || 0).all()\n  }\n}\n\nexport const Mutation = {\n  async createArticle(parent: any, { input }: any): Promise\u003cArticle\u003e {\n    return new Article().set(input).save()\n  },\n\n  async updateArticle(parent: any, { uuid, input }: any): Promise\u003cArticle\u003e {\n    const article = await Article.find\u003cArticle\u003e(uuid)\n    return article.set(input).save()\n  },\n\n  async deleteArticle(parent: any, { uuid }: any): Promise\u003cBoolean\u003e {\n    const article = await Article.find(uuid)\n    await article.remove()\n    return true\n  },\n}\n```\n\n##### Export from mod.ts\n\n```typescript\nimport { Article } from './Article.ts'\n\nexport * as resolvers from './resolvers.ts'\n\nexport const types = Deno.readTextFileSync(\n  new URL('types.graphql', import.meta.url)\n)\n\nexport const models = [\n  Article\n]\n```\n\n#### Core module\n\nThe core module contains the logic to autoload all other modules and exports orm tools from cotton to define models as above.\n\n#### User module\n\nBase user model and resolvers.\n\n#### Authentication module\n\nAdds the ability to authenticate users with jwt. It also injects an `authentication` object in the resolvers context.\n\n##### Authenticate\n\n```graphql\nmutation($input: AuthenticationInput!) {\n  createAuthentication(input: $input) {\n    token\n  }\n}\n\n# input:\n# {\n#   \"email\": \"lorem@mail.com\",\n#   \"password\": \"password123\"\n# }\n```\n\nThe `Authorization` header must then be set with the returned token.\n\n##### Get authentication infos\n\n```graphql\n{\n  authentication {\n    token\n    user {\n      name\n      email\n    }\n  }\n}\n```\n\n##### Ensure authentication\n\n```typescript\nimport { Article } from './Article.ts'\n\nexport const Mutation = {\n  async createArticle(parent: any, { input }: any, { authentication }: any) {\n    authentication.require() // Will throw if the user is not authenticated\n\n    return new Article()\n      .set({ ...input, author: authentication.user })\n      .save()\n  }\n}\n```\n\n### Scripts\n\nYou can run the following scripts using [denon](https://github.com/denosaurs/denon):\n\n| Command              | Description |\n|----------------------|-------------|\n| `denon install`      | Caches project dependencies and writes lockfile. Add the `--reload` flag to update the cache. |\n| `denon start`        | Starts the server and watches for changes unless `DENO_ENV` is set to `production`. |\n| `denon cotton migration:create -n NAME` | Creates a new migration. |\n| `denon cotton migration:up` | Runs migrations upward. |\n| `denon cotton migration:down` | Runs migrations downward. |\n| `denon docker:build` | Builds a docker image from project. |\n| `denon docker:start` | Runs `denon start` from the built docker image. |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuliendargelos%2Fdeno-graphql-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjuliendargelos%2Fdeno-graphql-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuliendargelos%2Fdeno-graphql-api/lists"}