├── .circleci └── config.yml ├── .editorconfig ├── .eslintignore ├── .eslintrc.js ├── .gitattributes ├── .github ├── CONTRIBUTING.md ├── FAQ.md ├── ISSUE_TEMPLATE.md ├── ISSUE_TEMPLATE │ ├── BUG.md │ ├── DOCS.md │ ├── FEATURE.md │ ├── MODIFICATION.md │ └── SUPPORT.md ├── PULL_REQUEST_TEMPLATE.md ├── labels.json ├── screen.png └── workflows │ └── node-windows.yml ├── .gitignore ├── .nvmrc ├── LICENSE ├── README.md ├── codecov.yml ├── commitlint.config.js ├── package.json ├── pnpm-lock.yaml ├── src └── index.ts ├── test ├── helpers │ ├── resolvers.ts │ ├── setup.ts │ └── typedefs.ts ├── snapshots │ ├── test.ts.md │ └── test.ts.snap ├── test.ts └── tsconfig.json ├── tsconfig.base.json ├── tsconfig.eslint.json └── tsconfig.json /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | jobs: 3 | node-v14-latest: 4 | docker: 5 | - image: rollupcabal/circleci-node-v14:latest 6 | steps: 7 | - checkout 8 | - run: 9 | name: Node Info 10 | command: node --version && npm --version 11 | - run: 12 | name: Install pnpm 13 | command: npm install pnpm -g 14 | - run: 15 | name: Install Dependencies 16 | command: pnpm install --ignore-scripts 17 | - run: 18 | name: Run unit tests. 19 | command: pnpm ci:coverage 20 | - run: 21 | name: Submit coverage data to codecov. 22 | command: bash <(curl -s https://codecov.io/bash) 23 | when: on_success 24 | analysis: 25 | docker: 26 | - image: rollupcabal/circleci-node-base:latest 27 | steps: 28 | - checkout 29 | - run: 30 | name: Install pnpm 31 | command: npm install pnpm -g 32 | - run: 33 | name: Install Dependencies 34 | command: pnpm install --ignore-scripts 35 | - run: 36 | name: Run linting. 37 | command: pnpm lint 38 | - run: 39 | name: Audit Dependencies 40 | command: pnpm security 41 | workflows: 42 | version: 2 43 | validate: 44 | jobs: 45 | - analysis: 46 | filters: 47 | tags: 48 | only: /.*/ 49 | - node-v14-latest: 50 | requires: 51 | - analysis 52 | filters: 53 | tags: 54 | only: /.*/ 55 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | end_of_line = lf 9 | insert_final_newline = true 10 | trim_trailing_whitespace = true 11 | 12 | [*.md] 13 | insert_final_newline = true 14 | trim_trailing_whitespace = false -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | dist 3 | *.snap 4 | output.js 5 | *-wps-hmr.* 6 | *.hot-update.js 7 | test/**/output 8 | .eslintrc.js 9 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | extends: ["shellscape", "plugin:import/typescript"], 3 | parser: "@typescript-eslint/parser", 4 | parserOptions: { 5 | project: ["./tsconfig.eslint.json", "./src/*/tsconfig.json"], 6 | tsconfigRootDir: __dirname, 7 | }, 8 | plugins: ["@typescript-eslint"], 9 | rules: { 10 | "@typescript-eslint/consistent-type-assertions": "error", 11 | "@typescript-eslint/consistent-type-definitions": "error", 12 | "@typescript-eslint/member-ordering": "error", 13 | "@typescript-eslint/no-inferrable-types": "error", 14 | "@typescript-eslint/no-redeclare": "error", 15 | "@typescript-eslint/no-unnecessary-type-assertion": "error", 16 | "@typescript-eslint/no-unused-vars": [ 17 | "error", 18 | { 19 | vars: "local", 20 | args: "after-used", 21 | ignoreRestSiblings: true, 22 | }, 23 | ], 24 | "import/extensions": [ 25 | "error", 26 | "always", 27 | { 28 | js: "never", 29 | jsx: "never", 30 | ts: "never", 31 | tsx: "never", 32 | }, 33 | ], 34 | "import/no-extraneous-dependencies": [ 35 | "error", 36 | { devDependencies: ["**/test/**/*.ts"] }, 37 | ], 38 | "import/no-namespace": "off", 39 | "import/no-named-export": "off", 40 | "import/prefer-default-export": "off", 41 | "no-redeclare": "off", 42 | "no-unused-expressions": [2, { allowShortCircuit: true }], 43 | "no-unused-vars": "off", 44 | "no-void": "off", 45 | "spaced-comment": "off", 46 | "prettier/prettier": [ 47 | "error", 48 | { 49 | arrowParens: "always", 50 | printWidth: 100, 51 | singleQuote: true, 52 | trailingComma: "none", 53 | plugins: ["prettier-plugin-package"], 54 | }, 55 | ], 56 | }, 57 | overrides: [ 58 | { 59 | files: ["**/*.ts"], 60 | rules: { 61 | "no-undef": "off", 62 | }, 63 | }, 64 | ], 65 | }; 66 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | package-lock.json -diff 2 | * text=auto 3 | bin/* eol=lf -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Contributing in apollo-log 2 | 3 | We 💛 contributions! The rules for contributing to this org are few: 4 | 5 | 1. Don't be a jerk 6 | 1. Search issues before opening a new one 7 | 1. Lint and run tests locally before submitting a PR 8 | 1. Adhere to the code style the org has chosen 9 | 10 | ## Required Tools 11 | 12 | This project uses [`pnpm`](https://pnpm.js.org/) for a package manager. Run `pnpm install` at the repository root. Please read the documentation for working with `pnpm` further. 13 | 14 | ## Before Committing 15 | 16 | 1. Use at least Node.js v14.0.0 or higher. [NVM](https://github.com/creationix/nvm) can be handy for switching between Node versions. 17 | 1. Lint your changes via `pnpm lint`. Fix any errors and warnings before committing. 18 | 1. Test your changes via `pnpm test`. Only Pull Requests with passing tests will be accepted. 19 | -------------------------------------------------------------------------------- /.github/FAQ.md: -------------------------------------------------------------------------------- 1 | ## Frequently Asked Questions 2 | 3 | 4 | 5 | - [What does _evergreen_ mean?](#what-does-evergreen-mean) 6 | - [What are "vote" issues?](#what-are-vote-issues) 7 | 8 | 9 | 10 | 11 | ### What does _evergreen_ mean? 12 | 13 | The concept behind an _evergreen_ project is derived from https://www.w3.org/2001/tag/doc/evergreen-web/. As such, this plugin only actively supports the [Active LTS](https://github.com/nodejs/Release#release-schedule) version of Node.js. As quoted from the W3C document, this decision was made: 14 | 15 | > 1. Intentionally: to simplify their implementation, reduce resource requirements or meet environmental constraints 16 | 17 | Additionally, this decision was made to leverage speed, stability, and platform enhancements (namely in `http`) in the latest Active LTS Node version(s). 18 | 19 | Some users will not be able to leverage this plugin either because they cannot upgrade, because they won't upgrade, or because another dependency prevents an upgrade. The author and maintainers of this plugin understand that, and feel that the benefits of supporting only the Active LTS version of Node.js outweigh the detriments. 20 | 21 | _**Please Note:** This is not currently a topic for debate or discussion on this repository. Issues which raise the topic will be closed, but will remain unlocked._ 22 | 23 | ### What are "vote" issues? 24 | 25 | "Vote" issues give the community and user base the opportunity to voice their opinion about the usefulness of a proposed feature or modification request that the maintainers have chosen not to implement. Maintainers typically have good reason for not accepting such requests, but in the event that enough users deem something useful, it's prudent to take another look. That's where voting comes into play. Vote thresholds for a particular issue are determined by using a number that is roughly 10% of the NPM downloads for the given month that a request is made. If a feature isn't deemed acceptable or widely useful initially, it should meet the criteria of being useful to at least 10% of the user base. Thresholds are never raised, but they can be lowered. 26 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 14 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/BUG.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 🐞 Bug Report 3 | about: Something went awry and you'd like to tell us about it. 4 | 5 | --- 6 | 7 | 16 | 17 | - apollo-server Version: 18 | - Operating System (or Browser): 19 | - Node Version: 20 | - apollo-log Version: 21 | 22 | ### How Do We Reproduce? 23 | 24 | 29 | 30 | 31 | ### Expected Behavior 32 | 33 | 34 | ### Actual Behavior 35 | 36 | 39 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/DOCS.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 📚 Documentation 3 | about: Are the docs lacking or missing something? Do they need some new 🔥 hotness? Tell us here. 4 | 5 | --- 6 | 7 | 16 | 17 | Documentation Is: 18 | 19 | 20 | 21 | - [ ] Missing 22 | - [ ] Needed 23 | - [ ] Confusing 24 | - [ ] Not Sure? 25 | 26 | ### Please Explain in Detail... 27 | 28 | 29 | ### Your Proposal for Changes 30 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/FEATURE.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: ✨ Feature Request 3 | about: Suggest an idea for this project 4 | 5 | --- 6 | 7 | 16 | 17 | ### Feature Use Case 18 | 19 | 20 | ### Feature Proposal 21 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/MODIFICATION.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 🔧 Modification Request 3 | about: Would you like something work differently? Have an alternative approach? This is the template for you. 4 | 5 | --- 6 | 7 | 16 | 17 | 18 | ### Expected Behavior / Situation 19 | 20 | 21 | ### Actual Behavior / Situation 22 | 23 | 24 | ### Modification Proposal 25 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/SUPPORT.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 🆘 Support, Help, and Advice 3 | about: 👉🏽 If you want to ask how to do a thing with this project, this is the place for you. 4 | 5 | --- 6 | 7 | If you arrived here because you think this project's documentation is unclear, insufficient, or wrong, please consider creating an issue for the documentation instead. 8 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 14 | 15 | This PR contains: 16 | 17 | - [ ] bugfix 18 | - [ ] feature 19 | - [ ] refactor 20 | - [ ] tests 21 | - [ ] documentation 22 | - [ ] metadata 23 | 24 | ### Breaking Changes? 25 | 26 | - [ ] yes 27 | - [ ] no 28 | 29 | If yes, please describe the breakage. 30 | 31 | ### Please Describe Your Changes 32 | 33 | 38 | -------------------------------------------------------------------------------- /.github/labels.json: -------------------------------------------------------------------------------- 1 | [ 2 | { "name": "💩 template incomplete", "color": "#4E342E" }, 3 | { "name": "💩 template removed", "color": "#4E342E" }, 4 | 5 | { "name": "c¹ ⋅ discussion", "color": "#1976D2" }, 6 | { "name": "c² ⋅ feedback wanted", "color": "#F9A825" }, 7 | { "name": "c³ ⋅ PR welcome", "color": "#1B5E20" }, 8 | { "name": "c⁴ ⋅ need more info", "color": "#6A1B9A" }, 9 | { "name": "c⁵ ⋅ question", "color": "#C2185B" }, 10 | { "name": "c⁶ ⋅ request for comments", "color": "#BBDEFB" }, 11 | 12 | { "name": "p¹ ⋅ electron", "color": "#B2DFDB" }, 13 | { "name": "p² ⋅ linux", "color": "#B2DFDB" }, 14 | { "name": "p³ ⋅ mac", "color": "#B2DFDB" }, 15 | { "name": "p⁴ ⋅ windows", "color": "#B2DFDB" }, 16 | 17 | { "name": "pr¹ 🔧 chore", "color": "#D7CCC8" }, 18 | { "name": "pr² 🔧 docs", "color": "#D7CCC8" }, 19 | { "name": "pr³ 🔧 feature", "color": "#D7CCC8" }, 20 | { "name": "pr⁴ 🔧 fix", "color": "#D7CCC8" }, 21 | { "name": "pr⁵ 🔧 performance", "color": "#D7CCC8" }, 22 | { "name": "pr⁶ 🔧 refactor", "color": "#D7CCC8" }, 23 | { "name": "pr⁷ 🔧 style", "color": "#D7CCC8" }, 24 | { "name": "pr⁸ 🔧 test", "color": "#D7CCC8" }, 25 | 26 | { "name": "s¹ 🔥🔥🔥 critical", "color": "#E53935" }, 27 | { "name": "s² 🔥🔥 important", "color": "#FB8C00" }, 28 | { "name": "s³ 🔥 nice to have", "color": "#FDD835" }, 29 | { "name": "s⁴ 💧 low", "color": "#039BE5" }, 30 | { "name": "s⁵ 💧💧 inconvenient", "color": "#c0e0f7" }, 31 | 32 | { "name": "t¹ 🐞 bug", "color": "#F44336" }, 33 | { "name": "t² 📚 documentation", "color": "#FDD835" }, 34 | { "name": "t³ ✨ enhancement", "color": "#03a9f4" }, 35 | { "name": "t⁴ ✨ feature", "color": "#8bc34A" }, 36 | { "name": "t⁵ ⋅ regression", "color": "#0052cc" }, 37 | { "name": "t⁶ ⋅ todo", "color": "#311B92" }, 38 | { "name": "t⁷ ⋅ waiting on upstream", "color": "#0D47A1" }, 39 | 40 | { "name": "v¹ ⋅ alpha", "color": "#CDDC39" }, 41 | { "name": "v² ⋅ beta", "color": "#FFEB3B" }, 42 | { "name": "v³ ⋅ major", "color": "#FF9800" }, 43 | { "name": "v⁴ ⋅ minor", "color": "#FFC107" }, 44 | { "name": "v⁵ ⋅ next", "color": "#CDDC39" }, 45 | 46 | { "name": "x¹ ⋅ abandoned", "color": "#CFD8DC" }, 47 | { "name": "x² ⋅ could not reproduce", "color": "#CFD8DC" }, 48 | { "name": "x³ ⋅ duplicate", "color": "#CFD8DC" }, 49 | { "name": "x⁴ ⋅ hold", "color": "#CFD8DC" }, 50 | { "name": "x⁵ ⋅ in progress", "color": "#4CAF50" }, 51 | { "name": "x⁶ ⋅ invalid", "color": "#CFD8DC" }, 52 | { "name": "x⁷ ⋅ wontfix", "color": "#CFD8DC" } 53 | ] 54 | -------------------------------------------------------------------------------- /.github/screen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shellscape/apollo-log/0b33bcd29f17ca8d321586b4770fe1c779ff96cb/.github/screen.png -------------------------------------------------------------------------------- /.github/workflows/node-windows.yml: -------------------------------------------------------------------------------- 1 | name: Node 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: windows-2019 9 | 10 | strategy: 11 | matrix: 12 | node: [ '14' ] 13 | 14 | name: ${{ matrix.node }} (Windows) 15 | steps: 16 | - name: Configure git line-breaks 17 | run: git config --global core.autocrlf false 18 | - name: Checkout Commit 19 | uses: actions/checkout@v1 20 | - name: Setup Node 21 | uses: actions/setup-node@v1 22 | with: 23 | node-version: ${{ matrix.node }} 24 | - name: Install pnpm 25 | run: npm install pnpm -g 26 | - name: checkout master 27 | run: git branch -f master origin/master 28 | - name: pnpm install 29 | run: pnpm install --ignore-scripts 30 | - name: run tests 31 | run: pnpm test 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | npm-debug.log 3 | coverage 4 | node_modules 5 | .eslintcache 6 | .nyc_output 7 | coverage.lcov 8 | dist 9 | -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | 14 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Mozilla Public License Version 2.0 2 | ================================== 3 | 4 | 1. Definitions 5 | -------------- 6 | 7 | 1.1. "Contributor" 8 | means each individual or legal entity that creates, contributes to 9 | the creation of, or owns Covered Software. 10 | 11 | 1.2. "Contributor Version" 12 | means the combination of the Contributions of others (if any) used 13 | by a Contributor and that particular Contributor's Contribution. 14 | 15 | 1.3. "Contribution" 16 | means Covered Software of a particular Contributor. 17 | 18 | 1.4. "Covered Software" 19 | means Source Code Form to which the initial Contributor has attached 20 | the notice in Exhibit A, the Executable Form of such Source Code 21 | Form, and Modifications of such Source Code Form, in each case 22 | including portions thereof. 23 | 24 | 1.5. "Incompatible With Secondary Licenses" 25 | means 26 | 27 | (a) that the initial Contributor has attached the notice described 28 | in Exhibit B to the Covered Software; or 29 | 30 | (b) that the Covered Software was made available under the terms of 31 | version 1.1 or earlier of the License, but not also under the 32 | terms of a Secondary License. 33 | 34 | 1.6. "Executable Form" 35 | means any form of the work other than Source Code Form. 36 | 37 | 1.7. "Larger Work" 38 | means a work that combines Covered Software with other material, in 39 | a separate file or files, that is not Covered Software. 40 | 41 | 1.8. "License" 42 | means this document. 43 | 44 | 1.9. "Licensable" 45 | means having the right to grant, to the maximum extent possible, 46 | whether at the time of the initial grant or subsequently, any and 47 | all of the rights conveyed by this License. 48 | 49 | 1.10. "Modifications" 50 | means any of the following: 51 | 52 | (a) any file in Source Code Form that results from an addition to, 53 | deletion from, or modification of the contents of Covered 54 | Software; or 55 | 56 | (b) any new file in Source Code Form that contains any Covered 57 | Software. 58 | 59 | 1.11. "Patent Claims" of a Contributor 60 | means any patent claim(s), including without limitation, method, 61 | process, and apparatus claims, in any patent Licensable by such 62 | Contributor that would be infringed, but for the grant of the 63 | License, by the making, using, selling, offering for sale, having 64 | made, import, or transfer of either its Contributions or its 65 | Contributor Version. 66 | 67 | 1.12. "Secondary License" 68 | means either the GNU General Public License, Version 2.0, the GNU 69 | Lesser General Public License, Version 2.1, the GNU Affero General 70 | Public License, Version 3.0, or any later versions of those 71 | licenses. 72 | 73 | 1.13. "Source Code Form" 74 | means the form of the work preferred for making modifications. 75 | 76 | 1.14. "You" (or "Your") 77 | means an individual or a legal entity exercising rights under this 78 | License. For legal entities, "You" includes any entity that 79 | controls, is controlled by, or is under common control with You. For 80 | purposes of this definition, "control" means (a) the power, direct 81 | or indirect, to cause the direction or management of such entity, 82 | whether by contract or otherwise, or (b) ownership of more than 83 | fifty percent (50%) of the outstanding shares or beneficial 84 | ownership of such entity. 85 | 86 | 2. License Grants and Conditions 87 | -------------------------------- 88 | 89 | 2.1. Grants 90 | 91 | Each Contributor hereby grants You a world-wide, royalty-free, 92 | non-exclusive license: 93 | 94 | (a) under intellectual property rights (other than patent or trademark) 95 | Licensable by such Contributor to use, reproduce, make available, 96 | modify, display, perform, distribute, and otherwise exploit its 97 | Contributions, either on an unmodified basis, with Modifications, or 98 | as part of a Larger Work; and 99 | 100 | (b) under Patent Claims of such Contributor to make, use, sell, offer 101 | for sale, have made, import, and otherwise transfer either its 102 | Contributions or its Contributor Version. 103 | 104 | 2.2. Effective Date 105 | 106 | The licenses granted in Section 2.1 with respect to any Contribution 107 | become effective for each Contribution on the date the Contributor first 108 | distributes such Contribution. 109 | 110 | 2.3. Limitations on Grant Scope 111 | 112 | The licenses granted in this Section 2 are the only rights granted under 113 | this License. No additional rights or licenses will be implied from the 114 | distribution or licensing of Covered Software under this License. 115 | Notwithstanding Section 2.1(b) above, no patent license is granted by a 116 | Contributor: 117 | 118 | (a) for any code that a Contributor has removed from Covered Software; 119 | or 120 | 121 | (b) for infringements caused by: (i) Your and any other third party's 122 | modifications of Covered Software, or (ii) the combination of its 123 | Contributions with other software (except as part of its Contributor 124 | Version); or 125 | 126 | (c) under Patent Claims infringed by Covered Software in the absence of 127 | its Contributions. 128 | 129 | This License does not grant any rights in the trademarks, service marks, 130 | or logos of any Contributor (except as may be necessary to comply with 131 | the notice requirements in Section 3.4). 132 | 133 | 2.4. Subsequent Licenses 134 | 135 | No Contributor makes additional grants as a result of Your choice to 136 | distribute the Covered Software under a subsequent version of this 137 | License (see Section 10.2) or under the terms of a Secondary License (if 138 | permitted under the terms of Section 3.3). 139 | 140 | 2.5. Representation 141 | 142 | Each Contributor represents that the Contributor believes its 143 | Contributions are its original creation(s) or it has sufficient rights 144 | to grant the rights to its Contributions conveyed by this License. 145 | 146 | 2.6. Fair Use 147 | 148 | This License is not intended to limit any rights You have under 149 | applicable copyright doctrines of fair use, fair dealing, or other 150 | equivalents. 151 | 152 | 2.7. Conditions 153 | 154 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted 155 | in Section 2.1. 156 | 157 | 3. Responsibilities 158 | ------------------- 159 | 160 | 3.1. Distribution of Source Form 161 | 162 | All distribution of Covered Software in Source Code Form, including any 163 | Modifications that You create or to which You contribute, must be under 164 | the terms of this License. You must inform recipients that the Source 165 | Code Form of the Covered Software is governed by the terms of this 166 | License, and how they can obtain a copy of this License. You may not 167 | attempt to alter or restrict the recipients' rights in the Source Code 168 | Form. 169 | 170 | 3.2. Distribution of Executable Form 171 | 172 | If You distribute Covered Software in Executable Form then: 173 | 174 | (a) such Covered Software must also be made available in Source Code 175 | Form, as described in Section 3.1, and You must inform recipients of 176 | the Executable Form how they can obtain a copy of such Source Code 177 | Form by reasonable means in a timely manner, at a charge no more 178 | than the cost of distribution to the recipient; and 179 | 180 | (b) You may distribute such Executable Form under the terms of this 181 | License, or sublicense it under different terms, provided that the 182 | license for the Executable Form does not attempt to limit or alter 183 | the recipients' rights in the Source Code Form under this License. 184 | 185 | 3.3. Distribution of a Larger Work 186 | 187 | You may create and distribute a Larger Work under terms of Your choice, 188 | provided that You also comply with the requirements of this License for 189 | the Covered Software. If the Larger Work is a combination of Covered 190 | Software with a work governed by one or more Secondary Licenses, and the 191 | Covered Software is not Incompatible With Secondary Licenses, this 192 | License permits You to additionally distribute such Covered Software 193 | under the terms of such Secondary License(s), so that the recipient of 194 | the Larger Work may, at their option, further distribute the Covered 195 | Software under the terms of either this License or such Secondary 196 | License(s). 197 | 198 | 3.4. Notices 199 | 200 | You may not remove or alter the substance of any license notices 201 | (including copyright notices, patent notices, disclaimers of warranty, 202 | or limitations of liability) contained within the Source Code Form of 203 | the Covered Software, except that You may alter any license notices to 204 | the extent required to remedy known factual inaccuracies. 205 | 206 | 3.5. Application of Additional Terms 207 | 208 | You may choose to offer, and to charge a fee for, warranty, support, 209 | indemnity or liability obligations to one or more recipients of Covered 210 | Software. However, You may do so only on Your own behalf, and not on 211 | behalf of any Contributor. You must make it absolutely clear that any 212 | such warranty, support, indemnity, or liability obligation is offered by 213 | You alone, and You hereby agree to indemnify every Contributor for any 214 | liability incurred by such Contributor as a result of warranty, support, 215 | indemnity or liability terms You offer. You may include additional 216 | disclaimers of warranty and limitations of liability specific to any 217 | jurisdiction. 218 | 219 | 4. Inability to Comply Due to Statute or Regulation 220 | --------------------------------------------------- 221 | 222 | If it is impossible for You to comply with any of the terms of this 223 | License with respect to some or all of the Covered Software due to 224 | statute, judicial order, or regulation then You must: (a) comply with 225 | the terms of this License to the maximum extent possible; and (b) 226 | describe the limitations and the code they affect. Such description must 227 | be placed in a text file included with all distributions of the Covered 228 | Software under this License. Except to the extent prohibited by statute 229 | or regulation, such description must be sufficiently detailed for a 230 | recipient of ordinary skill to be able to understand it. 231 | 232 | 5. Termination 233 | -------------- 234 | 235 | 5.1. The rights granted under this License will terminate automatically 236 | if You fail to comply with any of its terms. However, if You become 237 | compliant, then the rights granted under this License from a particular 238 | Contributor are reinstated (a) provisionally, unless and until such 239 | Contributor explicitly and finally terminates Your grants, and (b) on an 240 | ongoing basis, if such Contributor fails to notify You of the 241 | non-compliance by some reasonable means prior to 60 days after You have 242 | come back into compliance. Moreover, Your grants from a particular 243 | Contributor are reinstated on an ongoing basis if such Contributor 244 | notifies You of the non-compliance by some reasonable means, this is the 245 | first time You have received notice of non-compliance with this License 246 | from such Contributor, and You become compliant prior to 30 days after 247 | Your receipt of the notice. 248 | 249 | 5.2. If You initiate litigation against any entity by asserting a patent 250 | infringement claim (excluding declaratory judgment actions, 251 | counter-claims, and cross-claims) alleging that a Contributor Version 252 | directly or indirectly infringes any patent, then the rights granted to 253 | You by any and all Contributors for the Covered Software under Section 254 | 2.1 of this License shall terminate. 255 | 256 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all 257 | end user license agreements (excluding distributors and resellers) which 258 | have been validly granted by You or Your distributors under this License 259 | prior to termination shall survive termination. 260 | 261 | ************************************************************************ 262 | * * 263 | * 6. Disclaimer of Warranty * 264 | * ------------------------- * 265 | * * 266 | * Covered Software is provided under this License on an "as is" * 267 | * basis, without warranty of any kind, either expressed, implied, or * 268 | * statutory, including, without limitation, warranties that the * 269 | * Covered Software is free of defects, merchantable, fit for a * 270 | * particular purpose or non-infringing. The entire risk as to the * 271 | * quality and performance of the Covered Software is with You. * 272 | * Should any Covered Software prove defective in any respect, You * 273 | * (not any Contributor) assume the cost of any necessary servicing, * 274 | * repair, or correction. This disclaimer of warranty constitutes an * 275 | * essential part of this License. No use of any Covered Software is * 276 | * authorized under this License except under this disclaimer. * 277 | * * 278 | ************************************************************************ 279 | 280 | ************************************************************************ 281 | * * 282 | * 7. Limitation of Liability * 283 | * -------------------------- * 284 | * * 285 | * Under no circumstances and under no legal theory, whether tort * 286 | * (including negligence), contract, or otherwise, shall any * 287 | * Contributor, or anyone who distributes Covered Software as * 288 | * permitted above, be liable to You for any direct, indirect, * 289 | * special, incidental, or consequential damages of any character * 290 | * including, without limitation, damages for lost profits, loss of * 291 | * goodwill, work stoppage, computer failure or malfunction, or any * 292 | * and all other commercial damages or losses, even if such party * 293 | * shall have been informed of the possibility of such damages. This * 294 | * limitation of liability shall not apply to liability for death or * 295 | * personal injury resulting from such party's negligence to the * 296 | * extent applicable law prohibits such limitation. Some * 297 | * jurisdictions do not allow the exclusion or limitation of * 298 | * incidental or consequential damages, so this exclusion and * 299 | * limitation may not apply to You. * 300 | * * 301 | ************************************************************************ 302 | 303 | 8. Litigation 304 | ------------- 305 | 306 | Any litigation relating to this License may be brought only in the 307 | courts of a jurisdiction where the defendant maintains its principal 308 | place of business and such litigation shall be governed by laws of that 309 | jurisdiction, without reference to its conflict-of-law provisions. 310 | Nothing in this Section shall prevent a party's ability to bring 311 | cross-claims or counter-claims. 312 | 313 | 9. Miscellaneous 314 | ---------------- 315 | 316 | This License represents the complete agreement concerning the subject 317 | matter hereof. If any provision of this License is held to be 318 | unenforceable, such provision shall be reformed only to the extent 319 | necessary to make it enforceable. Any law or regulation which provides 320 | that the language of a contract shall be construed against the drafter 321 | shall not be used to construe this License against a Contributor. 322 | 323 | 10. Versions of the License 324 | --------------------------- 325 | 326 | 10.1. New Versions 327 | 328 | Mozilla Foundation is the license steward. Except as provided in Section 329 | 10.3, no one other than the license steward has the right to modify or 330 | publish new versions of this License. Each version will be given a 331 | distinguishing version number. 332 | 333 | 10.2. Effect of New Versions 334 | 335 | You may distribute the Covered Software under the terms of the version 336 | of the License under which You originally received the Covered Software, 337 | or under the terms of any subsequent version published by the license 338 | steward. 339 | 340 | 10.3. Modified Versions 341 | 342 | If you create software not governed by this License, and you want to 343 | create a new license for such software, you may create and use a 344 | modified version of this License if you rename the license and remove 345 | any references to the name of the license steward (except to note that 346 | such modified license differs from this License). 347 | 348 | 10.4. Distributing Source Code Form that is Incompatible With Secondary 349 | Licenses 350 | 351 | If You choose to distribute Source Code Form that is Incompatible With 352 | Secondary Licenses under the terms of this version of the License, the 353 | notice described in Exhibit B of this License must be attached. 354 | 355 | Exhibit A - Source Code Form License Notice 356 | ------------------------------------------- 357 | 358 | This Source Code Form is subject to the terms of the Mozilla Public 359 | License, v. 2.0. If a copy of the MPL was not distributed with this 360 | file, You can obtain one at http://mozilla.org/MPL/2.0/. 361 | 362 | If it is not possible or desirable to put the notice in a particular 363 | file, then You may include the notice in a location (such as a LICENSE 364 | file in a relevant directory) where a recipient would be likely to look 365 | for such a notice. 366 | 367 | You may add additional accurate notices of copyright ownership. 368 | 369 | Exhibit B - "Incompatible With Secondary Licenses" Notice 370 | --------------------------------------------------------- 371 | 372 | This Source Code Form is "Incompatible With Secondary Licenses", as 373 | defined by the Mozilla Public License, v. 2.0. 374 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [tests]: https://img.shields.io/circleci/project/github/shellscape/apollo-log.svg 2 | [tests-url]: https://circleci.com/gh/shellscape/apollo-log 3 | [cover]: https://codecov.io/gh/shellscape/apollo-log/branch/master/graph/badge.svg 4 | [cover-url]: https://codecov.io/gh/shellscape/apollo-log 5 | [size]: https://packagephobia.now.sh/badge?p=apollo-log 6 | [size-url]: https://packagephobia.now.sh/result?p=apollo-log 7 | 8 |
9 | Apollo Server

10 |
11 | 12 | [![tests][tests]][tests-url] 13 | [![cover][cover]][cover-url] 14 | [![size][size]][size-url] 15 | 16 | # apollo-log 17 | 18 | A logging plugin for Apollo GraphQL Server 19 | 20 | :heart: Please consider [Sponsoring my work](https://github.com/sponsors/shellscape) 21 | 22 | `apollo-server` doesn't ship with any comprehensive logging, and instead offloads that responsiblity to the users and the resolvers or context handler This module provides uniform logging for the entire GraphQL request lifecycle, as provided by plugin hooks in `apollo-server`. The console/terminal result of which will resemble the image below: 23 | 24 | 25 | 26 | ## Requirements 27 | 28 | `apollo-log` is an [evergreen 🌲](./.github/FAQ.md#what-does-evergreen-mean) module. 29 | 30 | This module requires an [Active LTS](https://github.com/nodejs/Release) Node version (v10.23.1+). 31 | 32 | ## Install 33 | 34 | Using npm: 35 | 36 | ```console 37 | npm install apollo-log 38 | ``` 39 | 40 | ## Usage 41 | 42 | Setting up `apollo-log` is straight-forward. Import and call the plugin function, passing any desired options, and pass the plugin in an array to `apollo-server`. 43 | 44 | ```js 45 | import { ApolloLogPlugin } from 'apollo-log'; 46 | import { ApolloServer } from 'apollo-server'; 47 | 48 | const options = { ... }; 49 | const plugins = [ApolloLogPlugin(options)]; 50 | const apollo = new ApolloServer({ 51 | plugins, 52 | ... 53 | }); 54 | ``` 55 | 56 | Please see the [Apollo Plugins](https://www.apollographql.com/docs/apollo-server/integrations/plugins/#installing-a-plugin) documentation for more information. 57 | 58 | ## Options 59 | 60 | ### `events` 61 | 62 | Type: `Record`
63 | Default: 64 | ```js 65 | { 66 | didEncounterErrors: true, 67 | didResolveOperation: false, 68 | executionDidStart: false, 69 | parsingDidStart: false, 70 | responseForOperation: false, 71 | validationDidStart: false, 72 | willSendResponse: true 73 | } 74 | 75 | ``` 76 | 77 | Specifies which [Apollo lifecycle events](https://www.apollographql.com/docs/apollo-server/integrations/plugins/#apollo-server-event-reference) will be logged. The `requestDidStart` event is always logged, and by default `didEncounterErrors` and `willSendResponse` are logged. 78 | 79 | ### `mutate` 80 | Type: `Function` 81 | Default: `(data: Record) => Record` 82 | 83 | If specified, allows inspecting and mutating the data logged to the console for each message. 84 | 85 | #### `prefix` 86 | Type: `String`
87 | Default: `apollo` 88 | 89 | Specifies a prefix, colored by level, prepended to each log message. 90 | 91 | #### `timestamp` 92 | Type: `Boolean` 93 | 94 | If `true`, will prepend a timestamp in the `HH:mm:ss` format to each log message. 95 | 96 | ## Meta 97 | 98 | [CONTRIBUTING](./.github/CONTRIBUTING.md) 99 | 100 | [LICENSE (Mozilla Public License)](./LICENSE) 101 | ``` 102 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | codecov: 2 | branch: master 3 | coverage: 4 | precision: 2 5 | round: down 6 | range: 70...100 7 | status: 8 | project: "no" 9 | patch: "yes" 10 | comment: "off" 11 | -------------------------------------------------------------------------------- /commitlint.config.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable */ 2 | const Configuration = { 3 | extends: ['@commitlint/config-conventional'], 4 | 5 | rules: { 6 | 'body-leading-blank': [1, 'always'], 7 | 'footer-leading-blank': [1, 'always'], 8 | 'header-max-length': [2, 'always', 72], 9 | 'scope-case': [2, 'always', 'lower-case'], 10 | 'subject-case': [2, 'never', ['sentence-case', 'start-case', 'pascal-case', 'upper-case']], 11 | 'subject-empty': [2, 'never'], 12 | 'subject-full-stop': [2, 'never', '.'], 13 | 'type-case': [2, 'always', 'lower-case'], 14 | 'type-empty': [2, 'never'], 15 | 'type-enum': [2, 'always', [ 16 | 'build', 17 | 'chore', 18 | 'ci', 19 | 'docs', 20 | 'feat', 21 | 'fix', 22 | 'perf', 23 | 'refactor', 24 | 'revert', 25 | 'style', 26 | 'test', 27 | ], 28 | ], 29 | }, 30 | }; 31 | 32 | module.exports = Configuration; -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "apollo-log", 3 | "version": "1.1.0", 4 | "description": "A logging plugin for Apollo GraphQL Server", 5 | "license": "MPL-2.0", 6 | "repository": "shellscape/apollo-log", 7 | "author": "Andrew Powell ", 8 | "homepage": "https://github.com/shellscape/apollo-log", 9 | "bugs": "https://github.com/shellscape/apollo-log/issues", 10 | "main": "dist/index.js", 11 | "engines": { 12 | "node": ">= 10.23.1" 13 | }, 14 | "scripts": { 15 | "build": "tsc --project tsconfig.json", 16 | "ci:coverage": "nyc pnpm ci:test && nyc report --reporter=text-lcov > coverage.lcov", 17 | "ci:lint": "pnpmlint && pnpm security", 18 | "ci:test": "pnpm test -- --verbose", 19 | "lint": "pnpm lint:docs && pnpm lint:json && pnpm lint:package && pnpm lint:js", 20 | "lint-staged": "lint-staged", 21 | "lint:docs": "prettier --single-quote --arrow-parens avoid --trailing-comma none --write README.md", 22 | "lint:js": "eslint --fix --cache src test", 23 | "lint:json": "prettier --write codecov.yml .circleci/config.yml .eslintrc.js", 24 | "lint:package": "prettier --write package.json --plugin=prettier-plugin-package", 25 | "prepublishOnly": "pnpm lint && pnpm build", 26 | "pretest": "pnpm build", 27 | "security": "pnpm audit --audit-level=high --prod", 28 | "test": "ava" 29 | }, 30 | "files": [ 31 | "dist/", 32 | "README.md", 33 | "LICENSE" 34 | ], 35 | "keywords": [ 36 | "apollo", 37 | "apollo extension", 38 | "apollo plugin", 39 | "apollo-server", 40 | "extension", 41 | "graphql", 42 | "log", 43 | "logger", 44 | "plugin", 45 | "server" 46 | ], 47 | "dependencies": { 48 | "apollo-server-plugin-base": "^0.10.4", 49 | "chalk": "^4.1.0", 50 | "fast-safe-stringify": "^2.0.7", 51 | "loglevelnext": "^4.0.1", 52 | "nanoid": "^3.1.20" 53 | }, 54 | "devDependencies": { 55 | "@commitlint/cli": "^11.0.0", 56 | "@commitlint/config-conventional": "^11.0.0", 57 | "@types/sinon": "^9.0.10", 58 | "@typescript-eslint/eslint-plugin": "^4.14.0", 59 | "@typescript-eslint/parser": "^4.14.0", 60 | "apollo-boost": "^0.4.9", 61 | "apollo-server": "^2.19.2", 62 | "ava": "^3.15.0", 63 | "eslint": "^7.18.0", 64 | "eslint-config-shellscape": "^3.0.0", 65 | "eslint-plugin-prettier": "^3.3.1", 66 | "isomorphic-unfetch": "^3.1.0", 67 | "lint-staged": "^10.5.3", 68 | "nyc": "^15.1.0", 69 | "pre-commit": "^1.2.2", 70 | "prettier": "^2.2.1", 71 | "prettier-plugin-package": "^1.3.0", 72 | "sinon": "^9.2.4", 73 | "ts-node": "^9.1.1", 74 | "tslib": "^2.1.0", 75 | "typescript": "^4.1.3" 76 | }, 77 | "ava": { 78 | "extensions": [ 79 | "ts" 80 | ], 81 | "files": [ 82 | "!**/fixtures/**", 83 | "!**/helpers/**" 84 | ], 85 | "require": [ 86 | "ts-node/register" 87 | ] 88 | }, 89 | "jest": { 90 | "testEnvironment": "node", 91 | "coverageDirectory": "./coverage/", 92 | "collectCoverage": true 93 | }, 94 | "lint-staged": { 95 | "*.js": [ 96 | "eslint --fix" 97 | ] 98 | }, 99 | "nyc": { 100 | "include": [ 101 | "src/*.ts" 102 | ], 103 | "exclude": [ 104 | "test/" 105 | ] 106 | }, 107 | "pre-commit": "lint-staged" 108 | } 109 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright © 20219 Andrew Powell 3 | 4 | This Source Code Form is subject to the terms of the Mozilla Public 5 | License, v. 2.0. If a copy of the MPL was not distributed with this 6 | file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 | 8 | The above copyright notice and this permission notice shall be 9 | included in all copies or substantial portions of this Source Code Form. 10 | */ 11 | import { ApolloServerPlugin, GraphQLRequestListener, GraphQLRequestContext } from 'apollo-server-plugin-base'; 12 | import chalk from 'chalk'; 13 | import stringify from 'fast-safe-stringify'; 14 | import loglevel from 'loglevelnext'; 15 | import { customAlphabet } from 'nanoid'; 16 | 17 | export type LogMutateData = Record & { context: GraphQLRequestContext }; 18 | 19 | export interface LogOptions { 20 | events: { [name: string]: boolean }; 21 | mutate: (data: LogMutateData) => LogMutateData; 22 | prefix: string; 23 | timestamp: boolean; 24 | } 25 | 26 | const defaults: LogOptions = { 27 | events: { 28 | didEncounterErrors: true, 29 | didResolveOperation: false, 30 | executionDidStart: false, 31 | parsingDidStart: false, 32 | responseForOperation: false, 33 | validationDidStart: false, 34 | willSendResponse: true 35 | }, 36 | mutate: (data: LogMutateData) => data, 37 | prefix: 'apollo', 38 | timestamp: false 39 | }; 40 | const nanoid = customAlphabet('1234567890abcdef', 6); 41 | const ignoredOps = ['IntrospectionQuery']; 42 | 43 | const getLog = (options: LogOptions) => { 44 | const template = `${options.timestamp ? '[{{time}}] ' : ''}{{level}} `; 45 | const prefix = { 46 | level: ({ level }: { level: string }) => 47 | chalk[level === 'info' ? 'blue' : 'red'](chalk`{inverse ${options.prefix}}`), 48 | template, 49 | time: () => new Date().toTimeString().split(' ')[0] 50 | }; 51 | const log = loglevel.create({ level: 'info', name: 'apollo-log', prefix }); 52 | 53 | return (id: string, data: unknown) => { 54 | const mutated = options.mutate?.(data as LogMutateData); 55 | log[(data as any).errors ? 'error' : 'info'](chalk`{dim ${id}}`, stringify(mutated)); 56 | }; 57 | }; 58 | 59 | export const ApolloLogPlugin = (opts?: Partial): ApolloServerPlugin => { 60 | const options: LogOptions = Object.assign({}, defaults, opts); 61 | const log = getLog(options); 62 | 63 | return { 64 | requestDidStart(context) { 65 | const operationId = nanoid(); 66 | const ignore = ignoredOps.includes(context.operationName || ''); 67 | 68 | if (!ignore) { 69 | const query = context.request.query?.replace(/\n/g, ''); 70 | const variables = Object.keys(context.request.variables || {}); 71 | log(operationId, { 72 | event: 'request', 73 | operationName: context.operationName, 74 | query, 75 | variables, 76 | context 77 | }); 78 | } 79 | 80 | const { events } = options; 81 | const handlers: GraphQLRequestListener = { 82 | didEncounterErrors({ errors }) { 83 | events.didEncounterErrors && log(operationId, { event: 'errors', errors, context }); 84 | }, 85 | 86 | didResolveOperation({ metrics, operationName }) { 87 | events.didResolveOperation && 88 | log(operationId, { event: 'didResolveOperation', metrics, operationName, context }); 89 | }, 90 | 91 | executionDidStart({ metrics }) { 92 | events.executionDidStart && log(operationId, { event: 'executionDidStart', metrics, context }); 93 | }, 94 | 95 | parsingDidStart({ metrics }) { 96 | events.parsingDidStart && log(operationId, { event: 'parsingDidStart', metrics, context }); 97 | }, 98 | 99 | responseForOperation({ metrics, operationName }) { 100 | events.responseForOperation && 101 | log(operationId, { event: 'responseForOperation', metrics, operationName, context }); 102 | return null; 103 | }, 104 | 105 | validationDidStart({ metrics }) { 106 | events.validationDidStart && log(operationId, { event: '', metrics, context }); 107 | }, 108 | 109 | willSendResponse({ metrics }) { 110 | options.events.willSendResponse && log(operationId, { event: 'response', metrics, context }); 111 | } 112 | }; 113 | 114 | return handlers; 115 | } 116 | }; 117 | }; 118 | -------------------------------------------------------------------------------- /test/helpers/resolvers.ts: -------------------------------------------------------------------------------- 1 | export const resolvers = { 2 | Query: { 3 | batman: () => 'nanananana' 4 | } 5 | }; 6 | -------------------------------------------------------------------------------- /test/helpers/setup.ts: -------------------------------------------------------------------------------- 1 | import { ApolloServer } from 'apollo-server'; 2 | 3 | import { ApolloLogPlugin, LogOptions } from '../../src'; 4 | 5 | import { typeDefs } from './typedefs'; 6 | import { resolvers } from './resolvers'; 7 | 8 | const port = 55555; 9 | 10 | export const run = async (options: Partial) => { 11 | const plugins = [() => ApolloLogPlugin(options as LogOptions)]; 12 | const apollo = new ApolloServer({ 13 | plugins, 14 | resolvers, 15 | typeDefs 16 | }); 17 | 18 | await apollo.listen({ port }); 19 | 20 | return apollo; 21 | }; 22 | -------------------------------------------------------------------------------- /test/helpers/typedefs.ts: -------------------------------------------------------------------------------- 1 | import { gql } from 'apollo-server'; 2 | 3 | export const typeDefs = gql` 4 | type Query { 5 | batman: String 6 | } 7 | `; 8 | -------------------------------------------------------------------------------- /test/snapshots/test.ts.md: -------------------------------------------------------------------------------- 1 | # Snapshot report for `test/test.ts` 2 | 3 | The actual snapshot is saved in `test.ts.snap`. 4 | 5 | Generated by [AVA](https://avajs.dev). 6 | 7 | ## logging 8 | 9 | > Snapshot 1 10 | 11 | { 12 | data: { 13 | batman: 'nanananana', 14 | }, 15 | loading: false, 16 | networkStatus: 7, 17 | stale: false, 18 | } 19 | 20 | > Snapshot 2 21 | 22 | 2 23 | 24 | > Snapshot 3 25 | 26 | [ 27 | [ 28 | 'apollo ', 29 | '{"event":"request","query":"{ batman}","variables":[],"context":{"logger":{"name":"apollo-server","levels":{"TRACE":0,"DEBUG":1,"INFO":2,"WARN":3,"ERROR":4,"SILENT":5}},"schema":{"__validationErrors":[],"extensionASTNodes":[],"_queryType":"Query","_directives":["@cacheControl","@include","@skip","@deprecated","@specifiedBy"],"_typeMap":{"Query":"Query","String":"String","CacheControlScope":"CacheControlScope","Upload":"Upload","Int":"Int","Boolean":"Boolean","__Schema":"__Schema","__Type":"__Type","__TypeKind":"__TypeKind","__Field":"__Field","__InputValue":"__InputValue","__EnumValue":"__EnumValue","__Directive":"__Directive","__DirectiveLocation":"__DirectiveLocation"},"_subTypeMap":{},"_implementationsMap":{},"_extensionsEnabled":true},"schemaHash":"a7ebabd7104f50771da12fe9b0a1cf9bc4c4ce9e81d6cbc336183077cadbc1dc49d0efb0c7ad6dd36cd2b1b5d64b6d8519946e35417e5941060279df3cad83fc","request":{"query":"{\\n batman\\n}\\n","operationName":null,"variables":{},"http":{"size":0,"timeout":0,"follow":20,"compress":true,"counter":0}},"response":{"http":{"headers":{}}},"context":{"_extensionStack":{"extensions":[]}},"cache":{"store":{}},"debug":false,"metrics":{}}}', 30 | ], 31 | [ 32 | 'apollo ', 33 | '{"event":"response","metrics":{"persistedQueryHit":false,"persistedQueryRegister":false},"context":{"logger":{"name":"apollo-server","levels":{"TRACE":0,"DEBUG":1,"INFO":2,"WARN":3,"ERROR":4,"SILENT":5}},"schema":{"__validationErrors":[],"extensionASTNodes":[],"_queryType":"Query","_directives":["@cacheControl","@include","@skip","@deprecated","@specifiedBy"],"_typeMap":{"Query":"Query","String":"String","CacheControlScope":"CacheControlScope","Upload":"Upload","Int":"Int","Boolean":"Boolean","__Schema":"__Schema","__Type":"__Type","__TypeKind":"__TypeKind","__Field":"__Field","__InputValue":"__InputValue","__EnumValue":"__EnumValue","__Directive":"__Directive","__DirectiveLocation":"__DirectiveLocation"},"_subTypeMap":{},"_implementationsMap":{},"_extensionsEnabled":true},"schemaHash":"a7ebabd7104f50771da12fe9b0a1cf9bc4c4ce9e81d6cbc336183077cadbc1dc49d0efb0c7ad6dd36cd2b1b5d64b6d8519946e35417e5941060279df3cad83fc","request":{"query":"{\\n batman\\n}\\n","operationName":null,"variables":{},"http":{"size":0,"timeout":0,"follow":20,"compress":true,"counter":0}},"response":{"http":{"headers":{}},"data":{"batman":"nanananana"}},"context":{"_extensionStack":{"extensions":[]}},"cache":{"store":{}},"debug":false,"metrics":{"persistedQueryHit":false,"persistedQueryRegister":false},"queryHash":"e794051cc4323f8f85f7f8af0b1a4f81c81ba8a57ecbe561f86b9027c087369f","source":"{\\n batman\\n}\\n","document":{"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","variableDefinitions":[],"directives":[],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"batman","loc":{"start":4,"end":10}},"arguments":[],"directives":[],"loc":{"start":4,"end":10}}],"loc":{"start":0,"end":12}},"loc":{"start":0,"end":12}}],"loc":{"start":0,"end":13}},"operation":{"kind":"OperationDefinition","operation":"query","variableDefinitions":[],"directives":[],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"batman","loc":{"start":4,"end":10}},"arguments":[],"directives":[],"loc":{"start":4,"end":10}}],"loc":{"start":0,"end":12}},"loc":{"start":0,"end":12}},"operationName":null}}', 34 | ], 35 | ] 36 | 37 | ## events 38 | 39 | > Snapshot 1 40 | 41 | { 42 | data: { 43 | batman: 'nanananana', 44 | }, 45 | loading: false, 46 | networkStatus: 7, 47 | stale: false, 48 | } 49 | 50 | > Snapshot 2 51 | 52 | [ 53 | [ 54 | 'apollo ', 55 | '{"event":"request","query":"{ batman}","variables":[],"context":{"logger":{"name":"apollo-server","levels":{"TRACE":0,"DEBUG":1,"INFO":2,"WARN":3,"ERROR":4,"SILENT":5}},"schema":{"__validationErrors":[],"extensionASTNodes":[],"_queryType":"Query","_directives":["@cacheControl","@include","@skip","@deprecated","@specifiedBy"],"_typeMap":{"Query":"Query","String":"String","CacheControlScope":"CacheControlScope","Upload":"Upload","Int":"Int","Boolean":"Boolean","__Schema":"__Schema","__Type":"__Type","__TypeKind":"__TypeKind","__Field":"__Field","__InputValue":"__InputValue","__EnumValue":"__EnumValue","__Directive":"__Directive","__DirectiveLocation":"__DirectiveLocation"},"_subTypeMap":{},"_implementationsMap":{},"_extensionsEnabled":true},"schemaHash":"a7ebabd7104f50771da12fe9b0a1cf9bc4c4ce9e81d6cbc336183077cadbc1dc49d0efb0c7ad6dd36cd2b1b5d64b6d8519946e35417e5941060279df3cad83fc","request":{"query":"{\\n batman\\n}\\n","operationName":null,"variables":{},"http":{"size":0,"timeout":0,"follow":20,"compress":true,"counter":0}},"response":{"http":{"headers":{}}},"context":{"_extensionStack":{"extensions":[]}},"cache":{"store":{}},"debug":false,"metrics":{}}}', 56 | ], 57 | [ 58 | 'apollo ', 59 | '{"event":"parsingDidStart","metrics":{"persistedQueryHit":false,"persistedQueryRegister":false},"context":{"logger":{"name":"apollo-server","levels":{"TRACE":0,"DEBUG":1,"INFO":2,"WARN":3,"ERROR":4,"SILENT":5}},"schema":{"__validationErrors":[],"extensionASTNodes":[],"_queryType":"Query","_directives":["@cacheControl","@include","@skip","@deprecated","@specifiedBy"],"_typeMap":{"Query":"Query","String":"String","CacheControlScope":"CacheControlScope","Upload":"Upload","Int":"Int","Boolean":"Boolean","__Schema":"__Schema","__Type":"__Type","__TypeKind":"__TypeKind","__Field":"__Field","__InputValue":"__InputValue","__EnumValue":"__EnumValue","__Directive":"__Directive","__DirectiveLocation":"__DirectiveLocation"},"_subTypeMap":{},"_implementationsMap":{},"_extensionsEnabled":true},"schemaHash":"a7ebabd7104f50771da12fe9b0a1cf9bc4c4ce9e81d6cbc336183077cadbc1dc49d0efb0c7ad6dd36cd2b1b5d64b6d8519946e35417e5941060279df3cad83fc","request":{"query":"{\\n batman\\n}\\n","operationName":null,"variables":{},"http":{"size":0,"timeout":0,"follow":20,"compress":true,"counter":0}},"response":{"http":{"headers":{}}},"context":{"_extensionStack":{"extensions":[]}},"cache":{"store":{}},"debug":false,"metrics":{"persistedQueryHit":false,"persistedQueryRegister":false},"queryHash":"e794051cc4323f8f85f7f8af0b1a4f81c81ba8a57ecbe561f86b9027c087369f","source":"{\\n batman\\n}\\n"}}', 60 | ], 61 | ] 62 | 63 | ## mutate 64 | 65 | > Snapshot 1 66 | 67 | { 68 | data: { 69 | batman: 'nanananana', 70 | }, 71 | loading: false, 72 | networkStatus: 7, 73 | stale: false, 74 | } 75 | 76 | > Snapshot 2 77 | 78 | [ 79 | [ 80 | 'apollo ', 81 | '{"event":"request","query":"{ batman}","variables":[],"context":{"logger":{"name":"apollo-server","levels":{"TRACE":0,"DEBUG":1,"INFO":2,"WARN":3,"ERROR":4,"SILENT":5}},"schema":{"__validationErrors":[],"extensionASTNodes":[],"_queryType":"Query","_directives":["@cacheControl","@include","@skip","@deprecated","@specifiedBy"],"_typeMap":{"Query":"Query","String":"String","CacheControlScope":"CacheControlScope","Upload":"Upload","Int":"Int","Boolean":"Boolean","__Schema":"__Schema","__Type":"__Type","__TypeKind":"__TypeKind","__Field":"__Field","__InputValue":"__InputValue","__EnumValue":"__EnumValue","__Directive":"__Directive","__DirectiveLocation":"__DirectiveLocation"},"_subTypeMap":{},"_implementationsMap":{},"_extensionsEnabled":true},"schemaHash":"a7ebabd7104f50771da12fe9b0a1cf9bc4c4ce9e81d6cbc336183077cadbc1dc49d0efb0c7ad6dd36cd2b1b5d64b6d8519946e35417e5941060279df3cad83fc","request":{"query":"{\\n batman\\n}\\n","operationName":null,"variables":{},"http":{"size":0,"timeout":0,"follow":20,"compress":true,"counter":0}},"response":{"http":{"headers":{}}},"context":{"_extensionStack":{"extensions":[]}},"cache":{"store":{}},"debug":false,"metrics":{}},"batman":"joker"}', 82 | ], 83 | [ 84 | 'apollo ', 85 | '{"event":"response","metrics":{"persistedQueryHit":false,"persistedQueryRegister":false},"context":{"logger":{"name":"apollo-server","levels":{"TRACE":0,"DEBUG":1,"INFO":2,"WARN":3,"ERROR":4,"SILENT":5}},"schema":{"__validationErrors":[],"extensionASTNodes":[],"_queryType":"Query","_directives":["@cacheControl","@include","@skip","@deprecated","@specifiedBy"],"_typeMap":{"Query":"Query","String":"String","CacheControlScope":"CacheControlScope","Upload":"Upload","Int":"Int","Boolean":"Boolean","__Schema":"__Schema","__Type":"__Type","__TypeKind":"__TypeKind","__Field":"__Field","__InputValue":"__InputValue","__EnumValue":"__EnumValue","__Directive":"__Directive","__DirectiveLocation":"__DirectiveLocation"},"_subTypeMap":{},"_implementationsMap":{},"_extensionsEnabled":true},"schemaHash":"a7ebabd7104f50771da12fe9b0a1cf9bc4c4ce9e81d6cbc336183077cadbc1dc49d0efb0c7ad6dd36cd2b1b5d64b6d8519946e35417e5941060279df3cad83fc","request":{"query":"{\\n batman\\n}\\n","operationName":null,"variables":{},"http":{"size":0,"timeout":0,"follow":20,"compress":true,"counter":0}},"response":{"http":{"headers":{}},"data":{"batman":"nanananana"}},"context":{"_extensionStack":{"extensions":[]}},"cache":{"store":{}},"debug":false,"metrics":{"persistedQueryHit":false,"persistedQueryRegister":false},"queryHash":"e794051cc4323f8f85f7f8af0b1a4f81c81ba8a57ecbe561f86b9027c087369f","source":"{\\n batman\\n}\\n","document":{"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","variableDefinitions":[],"directives":[],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"batman","loc":{"start":4,"end":10}},"arguments":[],"directives":[],"loc":{"start":4,"end":10}}],"loc":{"start":0,"end":12}},"loc":{"start":0,"end":12}}],"loc":{"start":0,"end":13}},"operation":{"kind":"OperationDefinition","operation":"query","variableDefinitions":[],"directives":[],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"batman","loc":{"start":4,"end":10}},"arguments":[],"directives":[],"loc":{"start":4,"end":10}}],"loc":{"start":0,"end":12}},"loc":{"start":0,"end":12}},"operationName":null},"batman":"joker"}', 86 | ], 87 | ] 88 | 89 | ## errors 90 | 91 | > Snapshot 1 92 | 93 | [ 94 | [ 95 | 'apollo ', 96 | '{"event":"errors","errors":[{"message":"Cannot query field \\"batmannnnnananana\\" on type \\"Query\\".","locations":[{"line":2,"column":3}]}],"context":{"logger":{"name":"apollo-server","levels":{"TRACE":0,"DEBUG":1,"INFO":2,"WARN":3,"ERROR":4,"SILENT":5}},"schema":{"__validationErrors":[],"extensionASTNodes":[],"_queryType":"Query","_directives":["@cacheControl","@include","@skip","@deprecated","@specifiedBy"],"_typeMap":{"Query":"Query","String":"String","CacheControlScope":"CacheControlScope","Upload":"Upload","Int":"Int","Boolean":"Boolean","__Schema":"__Schema","__Type":"__Type","__TypeKind":"__TypeKind","__Field":"__Field","__InputValue":"__InputValue","__EnumValue":"__EnumValue","__Directive":"__Directive","__DirectiveLocation":"__DirectiveLocation"},"_subTypeMap":{},"_implementationsMap":{},"_extensionsEnabled":true},"schemaHash":"a7ebabd7104f50771da12fe9b0a1cf9bc4c4ce9e81d6cbc336183077cadbc1dc49d0efb0c7ad6dd36cd2b1b5d64b6d8519946e35417e5941060279df3cad83fc","request":{"query":"{\\n batmannnnnananana\\n}\\n","operationName":null,"variables":{},"http":{"size":0,"timeout":0,"follow":20,"compress":true,"counter":0}},"response":{"http":{"headers":{}}},"context":{"_extensionStack":{"extensions":[]}},"cache":{"store":{}},"debug":false,"metrics":{"persistedQueryHit":false,"persistedQueryRegister":false},"queryHash":"e1fe2b14319c95642df1d6f65be7ea80a28bb6416decd7b0a59a4acd0b9514ee","source":"{\\n batmannnnnananana\\n}\\n","document":{"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","variableDefinitions":[],"directives":[],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"batmannnnnananana","loc":{"start":4,"end":21}},"arguments":[],"directives":[],"loc":{"start":4,"end":21}}],"loc":{"start":0,"end":23}},"loc":{"start":0,"end":23}}],"loc":{"start":0,"end":24}},"errors":[{"message":"Cannot query field \\"batmannnnnananana\\" on type \\"Query\\".","locations":[{"line":2,"column":3}]}]}}', 97 | ], 98 | ] 99 | -------------------------------------------------------------------------------- /test/snapshots/test.ts.snap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shellscape/apollo-log/0b33bcd29f17ca8d321586b4770fe1c779ff96cb/test/snapshots/test.ts.snap -------------------------------------------------------------------------------- /test/test.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable import/first */ 2 | require('isomorphic-unfetch'); 3 | 4 | import ApolloClient from 'apollo-boost'; 5 | import { gql } from 'apollo-server'; 6 | import test from 'ava'; 7 | import * as sinon from 'sinon'; 8 | 9 | import { LogMutateData } from '../src'; 10 | 11 | import { run } from './helpers/setup'; 12 | 13 | interface TestSpy { 14 | error?: sinon.SinonSpy; 15 | info?: sinon.SinonSpy; 16 | } 17 | type LogMethod = 'info' | 'error'; 18 | 19 | const methods: LogMethod[] = ['info', 'error']; 20 | const sandbox = sinon.createSandbox(); 21 | const rLine = /apollo [0-9a-z]{0,6}/; 22 | 23 | const spies: TestSpy = {}; 24 | const uri = 'http://localhost:55555/'; 25 | const query = gql` 26 | { 27 | batman 28 | } 29 | `; 30 | 31 | test.serial.before(() => { 32 | for (const method of methods) { 33 | spies[method] = sandbox.spy(console, method); 34 | } 35 | }); 36 | 37 | test.serial.beforeEach(() => { 38 | for (const method of methods) { 39 | spies[method]?.resetHistory(); 40 | } 41 | }); 42 | 43 | test.serial.after(() => { 44 | sandbox.restore(); 45 | }); 46 | 47 | test.serial('logging', async (t) => { 48 | const server = await run({}); 49 | const client = new ApolloClient({ uri }); 50 | const result = await client.query({ query }); 51 | t.snapshot(result); 52 | t.snapshot(spies.info?.callCount); 53 | 54 | const calls = spies.info?.getCalls().map((c) => { 55 | const [prefix, body] = c.args; 56 | t.truthy(rLine.test(prefix)); 57 | return [prefix.replace(rLine, 'apollo '), body]; 58 | }); 59 | t.snapshot(calls); 60 | 61 | await server.stop(); 62 | }); 63 | 64 | test.serial('events', async (t) => { 65 | const server = await run({ 66 | events: { 67 | didEncounterErrors: false, 68 | didResolveOperation: false, 69 | executionDidStart: false, 70 | parsingDidStart: true, 71 | responseForOperation: false, 72 | validationDidStart: false, 73 | willSendResponse: false 74 | } 75 | }); 76 | const client = new ApolloClient({ uri }); 77 | const result = await client.query({ query }); 78 | t.snapshot(result); 79 | t.is(spies.info?.callCount, 2); 80 | 81 | const calls = spies.info?.getCalls().map((c) => { 82 | const [prefix, body] = c.args; 83 | t.truthy(rLine.test(prefix)); 84 | return [prefix.replace(rLine, 'apollo '), body]; 85 | }); 86 | t.snapshot(calls); 87 | await server.stop(); 88 | }); 89 | 90 | test.serial('mutate', async (t) => { 91 | const server = await run({ 92 | mutate: (data: LogMutateData) => Object.assign(data, { batman: 'joker' }) 93 | }); 94 | const client = new ApolloClient({ uri }); 95 | const result = await client.query({ query }); 96 | t.snapshot(result); 97 | t.is(spies.info?.callCount, 2); 98 | 99 | const calls = spies.info?.getCalls().map((c) => { 100 | const [prefix, body] = c.args; 101 | t.truthy(rLine.test(prefix)); 102 | return [prefix.replace(rLine, 'apollo '), body]; 103 | }); 104 | t.snapshot(calls); 105 | await server.stop(); 106 | }); 107 | 108 | test.serial('errors', async (t) => { 109 | const server = await run({}); 110 | const client = new ApolloClient({ uri }); 111 | try { 112 | await client.query({ 113 | query: gql` 114 | { 115 | batmannnnnananana 116 | } 117 | ` 118 | }); 119 | } catch (e) { 120 | // noop 121 | } 122 | 123 | t.is(spies.info?.callCount, 2); 124 | t.is(spies.error?.callCount, 1); 125 | 126 | const calls = spies.error?.getCalls().map((c) => { 127 | const [prefix, body] = c.args; 128 | t.truthy(rLine.test(prefix)); 129 | return [prefix.replace(rLine, 'apollo '), body]; 130 | }); 131 | t.snapshot(calls); 132 | await server.stop(); 133 | }); 134 | -------------------------------------------------------------------------------- /test/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "include": ["./"] 4 | } 5 | -------------------------------------------------------------------------------- /tsconfig.base.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "allowSyntheticDefaultImports": true, 4 | "declaration": true, 5 | "emitDecoratorMetadata": true, 6 | "esModuleInterop": true, 7 | "experimentalDecorators": true, 8 | "lib": ["ES2018", "ES2020", "esnext.asynciterable", "dom"], 9 | "module": "commonjs", 10 | "moduleResolution": "node", 11 | "noEmitOnError": false, 12 | "noUnusedLocals": true, 13 | "noUnusedParameters": true, 14 | "outDir": "dist", 15 | "pretty": true, 16 | "removeComments": true, 17 | "resolveJsonModule": true, 18 | "skipLibCheck": true, 19 | "sourceMap": true, 20 | "strict": true, 21 | "target": "es2019" 22 | }, 23 | "exclude": ["dist", "node_modules", "test/types"] 24 | } 25 | -------------------------------------------------------------------------------- /tsconfig.eslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.base.json", 3 | "include": ["src", "test/**/*"] 4 | } 5 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.base.json", 3 | "include": ["src"] 4 | } 5 | --------------------------------------------------------------------------------