{"id":13487571,"url":"https://github.com/eggjs/egg-graphql","last_synced_at":"2026-01-23T18:16:17.720Z","repository":{"id":53516454,"uuid":"83153342","full_name":"eggjs/egg-graphql","owner":"eggjs","description":null,"archived":false,"fork":false,"pushed_at":"2020-06-06T18:40:47.000Z","size":73,"stargazers_count":369,"open_issues_count":8,"forks_count":61,"subscribers_count":20,"default_branch":"master","last_synced_at":"2025-10-08T00:34:33.902Z","etag":null,"topics":["egg","egg-plugin","eggjs","graphql","orm"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":false,"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/eggjs.png","metadata":{"files":{"readme":"README.md","changelog":"History.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-25T18:34:24.000Z","updated_at":"2025-04-18T15:09:46.000Z","dependencies_parsed_at":"2022-08-23T19:30:35.675Z","dependency_job_id":null,"html_url":"https://github.com/eggjs/egg-graphql","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/eggjs/egg-graphql","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Fegg-graphql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Fegg-graphql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Fegg-graphql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Fegg-graphql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eggjs","download_url":"https://codeload.github.com/eggjs/egg-graphql/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eggjs%2Fegg-graphql/sbom","scorecard":{"id":368731,"data":{"date":"2025-08-11","repo":{"name":"github.com/eggjs/egg-graphql","commit":"87d20a626a9d8e99598637ef7a8b980653fb0a4f"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.8,"checks":[{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Code-Review","score":2,"reason":"Found 7/25 approved changesets -- score normalized to 2","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 12 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-18T12:29:14.075Z","repository_id":53516454,"created_at":"2025-08-18T12:29:14.075Z","updated_at":"2025-08-18T12:29:14.075Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28697428,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-23T17:25:48.045Z","status":"ssl_error","status_checked_at":"2026-01-23T17:25:47.153Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["egg","egg-plugin","eggjs","graphql","orm"],"created_at":"2024-07-31T18:01:00.729Z","updated_at":"2026-01-23T18:16:17.703Z","avatar_url":"https://github.com/eggjs.png","language":"JavaScript","readme":"# egg-graphql\n---\n\n[GraphQL](http://facebook.github.io/graphql/)使用 Schema 来描述数据，并通过制定和实现 GraphQL 规范定义了支持 Schema 查询的 DSQL （Domain Specific Query Language，领域特定查询语言，由 FACEBOOK 提出。\n\n![graphql](http://upload-images.jianshu.io/upload_images/551828-8d055caea7562605.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)\n\n传统 web 应用通过开发服务给客户端提供接口是很常见的场景。而当需求或数据发生变化时，应用需要修改或者重新创建新的接口。长此以后，会造成服务器代码的不断增长，接口内部逻辑复杂难以维护。而 GraphQL 则通过以下特性解决这个问题：\n\n- 声明式。查询的结果格式由请求方（即客户端）决定而非响应方（即服务器端）决定。你不需要编写很多额外的接口来适配客户端请求\n- 可组合。GraphQL 的查询结构可以自由组合来满足需求。\n- 强类型。每个 GraphQL 查询必须遵循其设定的类型才会被执行。\n\n也就是说，通过以上的三个特性，当需求发生变化，客户端只需要编写能满足新需求的查询结构，如果服务端能提供的数据满足需求，服务端代码几乎不需要做任何的修改。\n\n目前 egg-graphql 已经完全支持在 egg 中使用 GraphQL 查询语法，可直接查看文末参考链接，下文为插件设计。\n\n## 技术选型\n\n我们会使用 [GraphQL Tools](http://dev.apollodata.com/tools/graphql-tools/index.html)配合 eggjs 完成 GraphQL 服务的搭建。 GraphQL Tools 建立了一种 GraphQL-first 的开发哲学，主要体现在以下三个方面：\n\n- 使用官方的 GraphQL schema 进行编程。 GraphQL Tools 提供工具，让你可以书写标准的 GraphQL schema，并完全支持里面的特性。\n- schema 与业务逻辑分离。 GraphQL Tools 建议我们把 GraphQL 逻辑分为四个部分: Schema, Resolvers, Models, 和 Connectors。\n- 为很多特殊场景提供标准解决方案。最大限度标准化 GraphQL 应用。\n\n我们也会使用 [GraphQL Server](http://dev.apollodata.com/tools/graphql-server/index.html) 来完成 GraphQL 查询语言 DSQL 的解析。\n\n同时我们会使用 [dataloader](https://github.com/facebook/dataloader) 来优化数据缓存。(例子可见 `test/fixtures/app/graphql-app` 目录)\n\nGraphQl Tools 新增了对自定义 directive 的支持，通过 directive 我们可以实现一些切面相关的事情：权限、缓存等。(例子可见 `test/fixtures/app/graphql-app/app/graphql/directives` 目录)\n\n这些我们都会集成到 [egg-graphql](https://github.com/eggjs/egg-graphql) 插件中。\n\n### 安装与配置\n\n安装对应的依赖 [egg-graphql] ：\n\n```bash\n$ npm i --save egg-graphql\n```\n\n开启插件：\n\n```js\n// config/plugin.js\nexports.graphql = {\n  enable: true,\n  package: 'egg-graphql',\n};\n```\n\n在 `config/config.${env}.js` 配置提供 graphql 的路由。\n\n```js\n// config/config.${env}.js\nexports.graphql = {\n  router: '/graphql',\n  // 是否加载到 app 上，默认开启\n  app: true,\n  // 是否加载到 agent 上，默认关闭\n  agent: false,\n  // 是否加载开发者工具 graphiql, 默认开启。路由同 router 字段。使用浏览器打开该可见。\n  graphiql: true,\n  //是否设置默认的Query和Mutation, 默认关闭\n  defaultEmptySchema:true,\n  // graphQL 路由前的拦截器\n  onPreGraphQL: function* (ctx) {},\n  // 开发工具 graphiQL 路由前的拦截器，建议用于做权限操作(如只提供开发者使用)\n  onPreGraphiQL: function* (ctx) {},\n  // apollo server的透传参数，参考[文档](https://www.apollographql.com/docs/apollo-server/api/apollo-server/#parameters)\n  apolloServerOptions: {\n    rootValue,\n    formatError,\n    formatResponse,\n    mocks,\n    schemaDirectives,\n    introspection,\n    playground,\n    debug,\n    validationRules,\n    tracing,\n    cacheControl,\n    subscriptions,\n    engine,\n    persistedQueries,\n    cors,\n  }\n};\n\n// 添加中间件拦截请求\nexports.middleware = [ 'graphql' ];\n```\n\n## 使用方式\n\n请将 graphql 相关逻辑放到 app/graphql 下，请参考测试用例，里面有 connector/schema 的目录结构, 以及 dataloader 的使用。\n\n目录结构如下\n\n```\n.\n├── app\n│   ├── graphql\n│   │   ├── common\n│   │   │   └── directive.js  // 自定义directive\n│   │   ├── project\n│   │   │   └── schema.graphql\n│   │   ├── schemaDirectives\n│   │   │   └── schemaDirective.js  // 自定义 SchemaDirective\n│   │   │ \n│   │   ├── user  // 一个graphql模型\n│   │   │   ├── connector.js  \n│   │   │   ├── resolver.js\n│   │   │   └── schema.graphql\n│   │   ├── group //自定义模型组目录\n│   │   │   ├── framework  // 一个graphql模型\n│   │   │   │ \t├── connector.js  \n│   │   │   │ \t├── resolver.js\n│   │   │   │ \t└── schema.graphql\n│   │   │   └── workspace  // 一个graphql模型\n│   │   │    \t├── connector.js  \n│   │   │    \t├── resolver.js\n│   │   │    \t└── schema.graphql\n│   ├── model\n│   │   └── user.js\n│   ├── public\n│   └── router.js\n\n```\n\n## 参考文章\n\n- [graphql官网](http://facebook.github.io/graphql)\n\n- [如何在egg中使用graphql](https://zhuanlan.zhihu.com/p/30604868)\n\n- [项目例子：结合sequelize](https://github.com/freebyron/egg-graphql-boilerplate)\n\n## 协议\n\nMIT\n","funding_links":[],"categories":["仓库","Plugins"],"sub_categories":["插件"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feggjs%2Fegg-graphql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feggjs%2Fegg-graphql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feggjs%2Fegg-graphql/lists"}