{"id":18030285,"url":"https://github.com/screamz/apollo-flash","last_synced_at":"2026-05-14T21:01:58.162Z","repository":{"id":48031821,"uuid":"144153930","full_name":"ScreamZ/apollo-flash","owner":"ScreamZ","description":"⚡A smart and efficient toolkit to quickly bootstrap a GraphQL 👨‍🚀apollo-server👩‍🚀 project.","archived":false,"fork":false,"pushed_at":"2022-12-22T08:33:32.000Z","size":65,"stargazers_count":2,"open_issues_count":4,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-09-29T09:19:07.110Z","etag":null,"topics":["apollo","apollo-server","apollo-server-express","apollographql","authentication-flow","graphql","toolkit"],"latest_commit_sha":null,"homepage":"","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/ScreamZ.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-08-09T13:07:26.000Z","updated_at":"2023-03-07T16:57:03.000Z","dependencies_parsed_at":"2023-01-30T06:16:29.002Z","dependency_job_id":null,"html_url":"https://github.com/ScreamZ/apollo-flash","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScreamZ%2Fapollo-flash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScreamZ%2Fapollo-flash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScreamZ%2Fapollo-flash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ScreamZ%2Fapollo-flash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ScreamZ","download_url":"https://codeload.github.com/ScreamZ/apollo-flash/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247249544,"owners_count":20908212,"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":["apollo","apollo-server","apollo-server-express","apollographql","authentication-flow","graphql","toolkit"],"created_at":"2024-10-30T09:13:55.179Z","updated_at":"2026-05-14T21:01:53.115Z","avatar_url":"https://github.com/ScreamZ.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e\n  Apollo Flash\n\u003c/h1\u003e\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"./docs/logo.png\" alt=\"Logo Apollo Flash\" width=\"300\"\u003e\n\u003c/p\u003e\n\u003ch4 align=\"center\"\u003eA smart and efficient toolkit to quickly bootstrap an apollo-server project.\u003c/h4\u003e\n\nIt comes with the following tools:\n\n- **TypeDefs Schema and Resolvers auto-loader**. Remove complexity of schema / resolvers objects management.\n- **`http-only cookie` based authentication with JWT**. Strong stateless authentication that allows horizontal scaling and maximum security.\n- **graphql-auth**. Resolver's middleware function that enable app security checking. Flash also provide context generator accordingly.\n\n# Installation and dependencies\n\nIf you wish to use cookie based auth : you'll need some kind of tool that add a `cookie` property to the request object (`cookie-parser` is fine with express). because apollo-flash will look for a jwt in the cookie object first.\n\nIf you choose to not use cookie implementation, while it is recommanded, apollo-flash will only look for `Authorization: Bearer \u003ctoken\u003e` header.\n\n**In all cases apollo-flash will first try to look for a jwt cookie before looking for the authorizarion header.**\n\nThat's why we suggest to use `apollo-server-express` (or koa equivalent).\n\nThen you just need to:\n\n`npm install apollo-flash --save`\n\n# Core concepts\n\nApollo Flash will automatically load your types definitions and resolvers by parsing your project directories.\nIt is also shipped with a authentication middleware that add user in the app context.\n\n[Learn How to use the authentication middleware](./docs/authentication.md)\n\n```js\nimport ApolloFlash from \"apollo-flash\";\n// ... Some imports of model, etc\n\n// ... Some database instantation\n\n// We need the user model to provide getUserFromId\nconst userModel = new UserModel(DB)\n\nconst Flash = new ApolloFlash({\n  getScopeFromUser: user =\u003e Promise.resolve([]), // An array of string.\n  getUserFromId: userModel.findById.bind(this), // Do not forget to bind or wrap in order to maintain scope.\n  jwtSigningKey: \"yoursigningstring\", // Or file Buffer with public key. Use RS256 algorithm with RSA keys and HS256 with string\n  verifyOpts: { algorithms: [\"RS256\"] }, // Passed to jwt verify function. See types or library `jsonwebtoken`.\n  resolversFolderPath: path.resolve(__dirname, \"resolvers\"),\n  typeDefsFolderPath: path.resolve(__dirname, \"schemas\")\n});\n\nconst server = new ApolloServer({\n  context: async (serverContext) =\u003e ({\n    ...await flash.buildContext(serverContext),\n    CourseModel: new CourseModel(DB),\n    Usermodel: userModel,\n  }),\n  resolvers: Flash.generateRootResolver(),\n  typeDefs: Flash.generateTypeDefs()\n});\n```\n\n## Schema auto-loader\n\nTired of taking care that each type is correctly loaded before being able to use it in your schema definition ? Don't worry this is over.\n\nAll you need to do is create a directory which contain files that export `an array of string` representing your scheme.\n\n```js\n// \u003cproject_root\u003e/schemas/user/index.js`\nconst UserSchema = `\n  \"An user of the application\"\n  type User {\n    _id: ID!\n    lastname: String!\n    firstname: String!\n    email: String!\n    preferences; UserPreferences\n  }\n`;\n\nconst UserPreferencesSchema = `\n  type UserPreferences {\n    displayStartHint: Boolean\n  }\n`;\n\nexport default [UserSchema, UserPreferencesSchema];\n```\n\nSchema types dependencies are auto-solved due to automated flattening imports using `Flash.generateTypeDefs()`.\nFolder structure is up to you and have no impact.\n\n## Resolver auto-loader\n\nResolvers are loaded the same way, **except that file naming count**.\n\nLet's start by creating a folder named `resolvers`.\n\nInside this folder, create a file named `Query.js` and here is an example of content inside this file (You might use an object too, I'm using a class that is auto-instantiated while exporting, this is just a matter of preferences).\n\n**`apollo-flash` only search resolver for one level depth in the given folder, if you are using nested folder for destructuring, please use it as import in your resolvers.**\n\n```js\n// resolvers/Query.js\nclass Query {\n  me = (root, values, context) =\u003e {\n    return context.auth.user || { _id: \"\", email: \"\", friends: [] };\n  };\n\n  getPlaces = async (root, values, context) =\u003e {\n    return await context.PlaceModel.findAll();\n  };\n}\n\nexport default new Query();\n```\n\nWell. We just instantiated the root Query resolver.\n\nNow `me` property is returning an array of string in the `friends` key which are user instance. We are going to transform this to real users instances.\n\n```js\n// resolvers/User.js\nclass User {\n  friends = async (parent, values, context) =\u003e {\n    if (!parent.friends) {\n      return null;\n    }\n\n    // Trigger calls in parallel then wait for all results.\n    return await Promise.all(\n      parent.friends.map(userId =\u003e context.UserModel.findById(userId))\n    );\n  };\n}\n```\n\nSee, combining class is simple as that.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscreamz%2Fapollo-flash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscreamz%2Fapollo-flash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscreamz%2Fapollo-flash/lists"}