{"id":22663166,"url":"https://github.com/puti94/gql-utils","last_synced_at":"2025-03-29T09:14:01.489Z","repository":{"id":116083438,"uuid":"280122113","full_name":"puti94/gql-utils","owner":"puti94","description":"grqphql 请求生成工具","archived":false,"fork":false,"pushed_at":"2020-08-02T12:21:32.000Z","size":201,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-18T05:44:05.401Z","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/puti94.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":"2020-07-16T10:16:04.000Z","updated_at":"2021-05-29T08:10:12.000Z","dependencies_parsed_at":"2023-05-21T19:30:35.652Z","dependency_job_id":null,"html_url":"https://github.com/puti94/gql-utils","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/puti94%2Fgql-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/puti94%2Fgql-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/puti94%2Fgql-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/puti94%2Fgql-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/puti94","download_url":"https://codeload.github.com/puti94/gql-utils/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246162153,"owners_count":20733357,"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":"2024-12-09T12:17:33.335Z","updated_at":"2025-03-29T09:14:01.474Z","avatar_url":"https://github.com/puti94.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# graphql 工具，包括生成graphql请求文本，生成graphql-adapter的客户端\n\n## 安装\n```bash\n$ yarn add @puti94/gql-utils // or npm i @puti94/gql-utils --save\n```\n\n## 生成字符串示例\n```js\n  import {generateFieldText} from '@puti94/gql-utils'\n  generateFieldText('query', {\n       fields: {\n         a: {\n           alias: 'alias',\n           args: {a: 'a', b: 1, c: false, d: ['a', 1, true, new Utils.GqlEnum('menu')]},\n           fields: [\"a\"]\n         }\n       }\n     });\n  // 'query{alias:a(a:\"a\",b:1,c:false,d:[\"a\",1,true,menu]){a}}'\n```\n## 创建apiClient示例\n```js\n  import {createApiClient} from '@puti94/gql-utils'\n  import {ApolloClient} from \"@apollo/client\";\n  //元数据可由graphql-adapter 的 _metadataMap 字段获取\n  const metadata = {\n    user:{\n      type:'User',\n      name:'User',\n      createAble:true,\n      pkName:\"uid\",\n      editable:true,\n      removeAble:true,\n      fields:{\n        uid:{\n          type:\"ID\",\n          primaryKey:true\n        },\n        name:{\n          type:\"String\"\n        },\n      }\n    }\n  }\n  const api = createApiClient(metadata, {\n       client: new ApolloClient({...}),\n       useQuery,\n       useMutation\n     });\n   //简单使用\n   api.user.one.query().then(res=\u003econsole.log(res.data.uid))\n   const {data} = api.user.one.useQuery()\n\n   const {mutate} = api.user.create.useMutation()\n\n   mutate({data:{name:\"张三\"}})\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fputi94%2Fgql-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fputi94%2Fgql-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fputi94%2Fgql-utils/lists"}