{"id":25000191,"url":"https://github.com/thinkmill/graphql-ts","last_synced_at":"2025-03-17T16:12:04.343Z","repository":{"id":40628433,"uuid":"374822417","full_name":"Thinkmill/graphql-ts","owner":"Thinkmill","description":"Type-safety for constructing GraphQL schemas in TypeScript","archived":false,"fork":false,"pushed_at":"2025-03-14T00:33:31.000Z","size":1231,"stargazers_count":18,"open_issues_count":1,"forks_count":1,"subscribers_count":11,"default_branch":"main","last_synced_at":"2025-03-14T00:36:23.177Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://docsmill.dev/npm/@graphql-ts/schema","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/Thinkmill.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-06-07T23:09:11.000Z","updated_at":"2025-03-14T00:32:53.000Z","dependencies_parsed_at":"2025-03-07T00:25:06.533Z","dependency_job_id":"e27bf57d-d258-4d42-9b82-a6401a0a679c","html_url":"https://github.com/Thinkmill/graphql-ts","commit_stats":null,"previous_names":[],"tags_count":35,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Thinkmill%2Fgraphql-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Thinkmill%2Fgraphql-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Thinkmill%2Fgraphql-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Thinkmill%2Fgraphql-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Thinkmill","download_url":"https://codeload.github.com/Thinkmill/graphql-ts/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244066189,"owners_count":20392406,"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":"2025-02-04T19:31:54.551Z","updated_at":"2025-03-17T16:12:04.334Z","avatar_url":"https://github.com/Thinkmill.png","language":"TypeScript","readme":"# @graphql-ts/schema\n\n`@graphql-ts/schema` is a thin wrapper around\n[GraphQL.js](https://github.com/graphql/graphql-js) providing type-safety for\nconstructing GraphQL Schemas while avoiding type-generation, [declaration merging](https://www.typescriptlang.org/docs/handbook/declaration-merging.html)\nand [decorators](https://www.typescriptlang.org/docs/handbook/decorators.html).\n\n```ts\nimport { gWithContext } from \"@graphql-ts/schema\";\nimport { GraphQLSchema, graphql } from \"graphql\";\n\ntype Context = {\n  loadPerson: (id: string) =\u003e Person | undefined;\n  loadFriends: (id: string) =\u003e Person[];\n};\nconst g = gWithContext\u003cContext\u003e();\ntype g\u003cT\u003e = gWithContext.infer\u003cT\u003e;\n\ntype Person = {\n  id: string;\n  name: string;\n};\n\nconst Person: g\u003ctypeof g.object\u003cPerson\u003e\u003e = g.object\u003cPerson\u003e()({\n  name: \"Person\",\n  fields: () =\u003e ({\n    id: g.field({ type: g.nonNull(g.ID) }),\n    name: g.field({ type: g.nonNull(g.String) }),\n    friends: g.field({\n      type: g.list(g.nonNull(Person)),\n      resolve(source, _, context) {\n        return context.loadFriends(source.id);\n      },\n    }),\n  }),\n});\n\nconst Query = g.object()({\n  name: \"Query\",\n  fields: {\n    person: g.field({\n      type: Person,\n      args: {\n        id: g.arg({ type: g.nonNull(g.ID) }),\n      },\n      resolve(_, args, context) {\n        return context.loadPerson(args.id);\n      },\n    }),\n  },\n});\n\nconst schema = new GraphQLSchema({\n  query: Query,\n});\n\n{\n  const people = new Map\u003cstring, Person\u003e([\n    [\"1\", { id: \"1\", name: \"Alice\" }],\n    [\"2\", { id: \"2\", name: \"Bob\" }],\n  ]);\n  const friends = new Map\u003cstring, string[]\u003e([\n    [\"1\", [\"2\"]],\n    [\"2\", [\"1\"]],\n  ]);\n  const contextValue: Context = {\n    loadPerson: (id) =\u003e people.get(id),\n    loadFriends: (id) =\u003e {\n      return (friends.get(id) ?? [])\n        .map((id) =\u003e people.get(id))\n        .filter((person) =\u003e person !== undefined) as Person[];\n    },\n  };\n  graphql({\n    source: `\n      query {\n        person(id: \"1\") {\n          id\n          name\n          friends {\n            id\n            name\n          }\n        }\n      }\n    `,\n    schema,\n    contextValue,\n  }).then((result) =\u003e {\n    console.log(result);\n  });\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthinkmill%2Fgraphql-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthinkmill%2Fgraphql-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthinkmill%2Fgraphql-ts/lists"}