{"id":26471165,"url":"https://github.com/seppevs/graphql-scanner","last_synced_at":"2026-06-29T11:31:41.048Z","repository":{"id":48789689,"uuid":"178407643","full_name":"seppevs/graphql-scanner","owner":"seppevs","description":"Define your GraphQL types in separate files","archived":false,"fork":false,"pushed_at":"2021-07-12T04:28:30.000Z","size":675,"stargazers_count":0,"open_issues_count":10,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-10T16:47:37.406Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/seppevs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-03-29T13:10:30.000Z","updated_at":"2023-04-16T21:22:00.000Z","dependencies_parsed_at":"2022-08-31T05:13:47.017Z","dependency_job_id":null,"html_url":"https://github.com/seppevs/graphql-scanner","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/seppevs/graphql-scanner","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seppevs%2Fgraphql-scanner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seppevs%2Fgraphql-scanner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seppevs%2Fgraphql-scanner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seppevs%2Fgraphql-scanner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/seppevs","download_url":"https://codeload.github.com/seppevs/graphql-scanner/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/seppevs%2Fgraphql-scanner/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34925718,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-29T02:00:05.398Z","response_time":58,"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":"2025-03-19T20:53:34.308Z","updated_at":"2026-06-29T11:31:41.027Z","avatar_url":"https://github.com/seppevs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GraphQL Scanner\nDefine your GraphQL types in separate files\n\n✨ [![Build Status](http://img.shields.io/travis/seppevs/graphql-scanner.svg?style=flat)](https://travis-ci.org/seppevs/graphql-scanner) [![Coverage Status](https://coveralls.io/repos/github/seppevs/graphql-scanner/badge.svg?branch=master)](https://coveralls.io/r/seppevs/graphql-scanner) [![NPM](http://img.shields.io/npm/v/graphql-scanner.svg?style=flat)](https://www.npmjs.org/package/graphql-scanner) [![Downloads](http://img.shields.io/npm/dm/graphql-scanner.svg?style=flat)](https://www.npmjs.org/package/graphql-scanner) [![Dependencies](https://david-dm.org/seppevs/graphql-scanner.svg)](https://david-dm.org/seppevs/graphql-scanner) [![Known Vulnerabilities](https://snyk.io/test/github/seppevs/graphql-scanner/badge.svg)](https://snyk.io/test/github/seppevs/graphql-scanner) ✨\n\n## Introduction\nA GraphQL server generally needs two things: a `typeDefs` string and a `resolvers` object.\n\n* The `typeDefs` string contains the schema definitions, \n* `resolvers` object describes how to _resolve_ certain attributes of a type.\n\nThe problem is, both the `typeDefs` and `resolvers` can get huge and/or impractical to use.\n\nEnter GraphQL Scanner! A tiny util that allows you to define each type (and their matching resolver) in a separate file.\n\nTested with [Apollo Server](https://www.apollographql.com/docs/apollo-server/), but should also work with [GraphQL.js](https://graphql.org/graphql-js/) and \n[express-graphql](https://graphql.org/graphql-js/running-an-express-graphql-server/)\n\n## Quickstart\n\n### Install the dependency\n```bash\n$ npm install graphql-scanner --save\n```\n\n### Create a types directory\nCreate a 'types' directory in your project, and use it to store your GraphQL types.\n\nFor example:\n```\n├── types\n|   ├── Query.js\n|   └── TodoList.js\n|   └── User.js\n├── app.js\n```\n\n### Define your types\nEach type MUST expose an object containing two attributes:\n* `typeDef` (String, required): the GraphQL schema definition of your type\n* `resolver` (Object, optional): an object to resolve certain attributes of the type you've defined\n\nFor example:\n\n#### types/Query.js\n```javascript\nmodule.exports = {\n  typeDef: `\n      type Query {\n        currentUser: User\n      }\n    `,\n  resolver: {\n    currentUser(_, args, ctx) {\n      const { apikey } = ctx;\n      return {\n        firstName: \"John\",\n        lastName: \"Do\",\n        apikey\n      };\n    }\n  }\n};\n```\n\n#### types/User.js\n```javascript\nmodule.exports = {\n  typeDef: `\n      type User {\n        firstName: String!\n        lastName: String\n        apikey: String\n        todoLists: [TodoList]\n      }\n    `,\n  resolver: {\n    todoLists(user, args, ctx) {\n      return Promise.resolve([\n        {\n          subject: 'Holidays',\n        }\n      ]);\n    }\n  }\n};\n\n```\n\n#### types/TodoList.js\n```javascript\nmodule.exports = {\n  typeDef: `\n      type TodoList {\n        subject: String!\n        tasks: [String]\n      }\n    `,\n  resolver: {\n    tasks(todoList, arg, ctx)  {\n      return Promise.resolve(['Fix a cab', 'Book a flight']);\n    }\n  }\n};\n\n```\n\n### Use the GraphQL Scanner\n\nYou need to pass the path to your directory that contain your types.\n\nFor example:\n\n### app.js:\n```javascript\nconst path = require('path');\nconst graphqlScanner = require('graphql-scanner');\n\n// ...\n\nconst dir = path.join(__dirname, './types');\nconst { typeDefs, resolvers } = graphqlScanner(dir);\nconst server = new GraphQLServer({ typeDefs, resolvers });\n\n```\n\nThe `graphqlScanner(dir)` expression scans your types and returns an object containing `typeDefs` and `resolvers`.\n\nYou can then pass these `typeDefs` and `resolvers` to your favourite GraphQL server library.\n\n## How does it work?\n[Check the code](https://github.com/seppevs/graphql-scanner/blob/master/src/graphql-scanner.js), it's less than 20 lines!\n\nIt uses [require-all](https://www.npmjs.com/package/require-all) to load all modules in the `dir` you've passed as an argument\n\nThen, it will iterate over all loaded modules and \n* append each individual `typeDef` string to a `typeDefs` variable.\n* add each individual `resolver` to a `resolvers` object as an attribute. The key of each attribute is the file name (minus extension) of the type\n\nFinally, it will return an object: `{ typeDefs, resolvers }`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseppevs%2Fgraphql-scanner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fseppevs%2Fgraphql-scanner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fseppevs%2Fgraphql-scanner/lists"}