├── .browserslistrc ├── .editorconfig ├── .gitignore ├── .vscode ├── extensions.json ├── launch.json └── tasks.json ├── LICENSE ├── README.md ├── angular.json ├── karma.conf.js ├── package-lock.json ├── package.json ├── realm-app ├── MovieCatalog │ ├── auth │ │ ├── custom_user_data.json │ │ └── providers.json │ ├── data_sources │ │ └── mongodb-atlas │ │ │ ├── config.json │ │ │ └── sample_mflix │ │ │ ├── comments │ │ │ ├── relationships.json │ │ │ ├── rules.json │ │ │ └── schema.json │ │ │ └── movies │ │ │ ├── relationships.json │ │ │ ├── rules.json │ │ │ └── schema.json │ ├── environments │ │ ├── development.json │ │ ├── no-environment.json │ │ ├── production.json │ │ ├── qa.json │ │ └── testing.json │ ├── functions │ │ ├── config.json │ │ └── loadCommentsOffset.js │ ├── graphql │ │ ├── config.json │ │ └── custom_resolvers │ │ │ └── query_CommentsOffset.json │ ├── http_endpoints │ │ └── config.json │ ├── realm_config.json │ └── sync │ │ └── config.json └── README.md ├── src ├── app │ ├── app-routing.module.ts │ ├── app.component.html │ ├── app.component.scss │ ├── app.component.ts │ ├── app.module.ts │ ├── comment-form │ │ ├── comment-form.component.html │ │ ├── comment-form.component.scss │ │ └── comment-form.component.ts │ ├── comment.ts │ ├── customers-list │ │ ├── customers-list.component.html │ │ ├── customers-list.component.scss │ │ └── customers-list.component.ts │ ├── graphql.module.ts │ ├── movie-details │ │ ├── movie-details.component.html │ │ ├── movie-details.component.scss │ │ └── movie-details.component.ts │ ├── movie.ts │ └── movies-list │ │ ├── movies-list.component.html │ │ ├── movies-list.component.scss │ │ └── movies-list.component.ts ├── assets │ ├── .gitkeep │ └── no-poster.jpeg ├── environments │ ├── environment.prod.ts │ └── environment.ts ├── favicon.ico ├── index.html ├── main.ts ├── polyfills.ts └── styles.scss ├── tsconfig.app.json ├── tsconfig.json └── tsconfig.spec.json /.browserslistrc: -------------------------------------------------------------------------------- 1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below. 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | 5 | # For the full list of supported browsers by the Angular framework, please see: 6 | # https://angular.io/guide/browser-support 7 | 8 | # You can see what browsers were selected by your queries by running: 9 | # npx browserslist 10 | 11 | last 1 Chrome version 12 | last 1 Firefox version 13 | last 2 Edge major versions 14 | last 2 Safari major versions 15 | last 2 iOS major versions 16 | Firefox ESR 17 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see https://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.ts] 12 | quote_type = single 13 | 14 | [*.md] 15 | max_line_length = off 16 | trim_trailing_whitespace = false 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # Secrets 4 | /src/environments/environment.ts 5 | 6 | # Compiled output 7 | /dist 8 | /tmp 9 | /out-tsc 10 | /bazel-out 11 | 12 | # Node 13 | /node_modules 14 | npm-debug.log 15 | yarn-error.log 16 | 17 | # IDEs and editors 18 | .idea/ 19 | .project 20 | .classpath 21 | .c9/ 22 | *.launch 23 | .settings/ 24 | *.sublime-workspace 25 | 26 | # Visual Studio Code 27 | .vscode/* 28 | !.vscode/settings.json 29 | !.vscode/tasks.json 30 | !.vscode/launch.json 31 | !.vscode/extensions.json 32 | .history/* 33 | 34 | # Miscellaneous 35 | /.angular/cache 36 | .sass-cache/ 37 | /connect.lock 38 | /coverage 39 | /libpeerconnection.log 40 | testem.log 41 | /typings 42 | 43 | # System files 44 | .DS_Store 45 | Thumbs.db 46 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=827846 3 | "recommendations": ["angular.ng-template"] 4 | } 5 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 3 | "version": "0.2.0", 4 | "configurations": [ 5 | { 6 | "name": "ng serve", 7 | "type": "pwa-chrome", 8 | "request": "launch", 9 | "preLaunchTask": "npm: start", 10 | "url": "http://localhost:4200/" 11 | }, 12 | { 13 | "name": "ng test", 14 | "type": "chrome", 15 | "request": "launch", 16 | "preLaunchTask": "npm: test", 17 | "url": "http://localhost:9876/debug.html" 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | { 2 | // For more information, visit: https://go.microsoft.com/fwlink/?LinkId=733558 3 | "version": "2.0.0", 4 | "tasks": [ 5 | { 6 | "type": "npm", 7 | "script": "start", 8 | "isBackground": true, 9 | "problemMatcher": { 10 | "owner": "typescript", 11 | "pattern": "$tsc", 12 | "background": { 13 | "activeOnStart": true, 14 | "beginsPattern": { 15 | "regexp": "(.*?)" 16 | }, 17 | "endsPattern": { 18 | "regexp": "bundle generation complete" 19 | } 20 | } 21 | } 22 | }, 23 | { 24 | "type": "npm", 25 | "script": "test", 26 | "isBackground": true, 27 | "problemMatcher": { 28 | "owner": "typescript", 29 | "pattern": "$tsc", 30 | "background": { 31 | "activeOnStart": true, 32 | "beginsPattern": { 33 | "regexp": "(.*?)" 34 | }, 35 | "endsPattern": { 36 | "regexp": "bundle generation complete" 37 | } 38 | } 39 | } 40 | } 41 | ] 42 | } 43 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | Copyright 2022 MongoDB Inc. 179 | 180 | Licensed under the Apache License, Version 2.0 (the "License"); 181 | you may not use this file except in compliance with the License. 182 | You may obtain a copy of the License at 183 | 184 | http://www.apache.org/licenses/LICENSE-2.0 185 | 186 | Unless required by applicable law or agreed to in writing, software 187 | distributed under the License is distributed on an "AS IS" BASIS, 188 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 189 | See the License for the specific language governing permissions and 190 | limitations under the License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Notice: Repository Deprecation 2 | This repository is deprecated and no longer actively maintained. It contains outdated code examples or practices that do not align with current MongoDB best practices. While the repository remains accessible for reference purposes, we strongly discourage its use in production environments. 3 | Users should be aware that this repository will not receive any further updates, bug fixes, or security patches. This code may expose you to security vulnerabilities, compatibility issues with current MongoDB versions, and potential performance problems. Any implementation based on this repository is at the user's own risk. 4 | For up-to-date resources, please refer to the [MongoDB Developer Center](https://mongodb.com/developer). 5 | 6 | 7 | # Angular and GraphQL API Demo — Movie Catalog 8 | 9 | This is an app that demonstrates how to use Angular and the [Atlas GraphQL API](https://www.mongodb.com/docs/realm/graphql/?utm_campaign=stanimira_vlaeva&utm_source=github&utm_medium=github). 10 | 11 | You can also take a look at the supporting Google Slides presentation: [Practical Introduction to GraphQL](https://bit.ly/mdb-graphql). 12 | 13 | Register for [MongoDB Atlas](https://www.mongodb.com/cloud/atlas/register?utm_campaign=stanimira_vlaeva&utm_source=github&utm_medium=referral) and create a forever-free cluster! 14 | 15 | ## Usage 16 | 17 | Update the `src/environments/environment.ts` file with your own keys: 18 | 19 | ```ts 20 | export const environment = { 21 | production: false, 22 | APP_ID: '', 23 | GRAPHQL_URI: '', 24 | API_KEY: '', 25 | }; 26 | ``` 27 | 28 | Run `ng serve` for a dev server. Navigate to http://localhost:4200/. The application will automatically reload if you change any of the source files. 29 | 30 | ## Disclaimer 31 | 32 | Use at your own risk; not a supported MongoDB product 33 | 34 | -------------------------------------------------------------------------------- /angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "angular-realm-graphql": { 7 | "projectType": "application", 8 | "schematics": { 9 | "@schematics/angular:component": { 10 | "style": "scss" 11 | }, 12 | "@schematics/angular:application": { 13 | "strict": true 14 | } 15 | }, 16 | "root": "", 17 | "sourceRoot": "src", 18 | "prefix": "app", 19 | "architect": { 20 | "build": { 21 | "builder": "@angular-devkit/build-angular:browser", 22 | "options": { 23 | "outputPath": "dist/angular-realm-graphql", 24 | "index": "src/index.html", 25 | "main": "src/main.ts", 26 | "polyfills": "src/polyfills.ts", 27 | "tsConfig": "tsconfig.app.json", 28 | "inlineStyleLanguage": "scss", 29 | "assets": [ 30 | "src/favicon.ico", 31 | "src/assets" 32 | ], 33 | "styles": [ 34 | "src/styles.scss" 35 | ], 36 | "scripts": [] 37 | }, 38 | "configurations": { 39 | "production": { 40 | "budgets": [ 41 | { 42 | "type": "initial", 43 | "maximumWarning": "500kb", 44 | "maximumError": "1mb" 45 | }, 46 | { 47 | "type": "anyComponentStyle", 48 | "maximumWarning": "2kb", 49 | "maximumError": "4kb" 50 | } 51 | ], 52 | "fileReplacements": [ 53 | { 54 | "replace": "src/environments/environment.ts", 55 | "with": "src/environments/environment.prod.ts" 56 | } 57 | ], 58 | "outputHashing": "all" 59 | }, 60 | "development": { 61 | "buildOptimizer": false, 62 | "optimization": false, 63 | "vendorChunk": true, 64 | "extractLicenses": false, 65 | "sourceMap": true, 66 | "namedChunks": true 67 | } 68 | }, 69 | "defaultConfiguration": "production" 70 | }, 71 | "serve": { 72 | "builder": "@angular-devkit/build-angular:dev-server", 73 | "configurations": { 74 | "production": { 75 | "browserTarget": "angular-realm-graphql:build:production" 76 | }, 77 | "development": { 78 | "browserTarget": "angular-realm-graphql:build:development" 79 | } 80 | }, 81 | "defaultConfiguration": "development" 82 | }, 83 | "extract-i18n": { 84 | "builder": "@angular-devkit/build-angular:extract-i18n", 85 | "options": { 86 | "browserTarget": "angular-realm-graphql:build" 87 | } 88 | }, 89 | "test": { 90 | "builder": "@angular-devkit/build-angular:karma", 91 | "options": { 92 | "main": "src/test.ts", 93 | "polyfills": "src/polyfills.ts", 94 | "tsConfig": "tsconfig.spec.json", 95 | "karmaConfig": "karma.conf.js", 96 | "inlineStyleLanguage": "scss", 97 | "assets": [ 98 | "src/favicon.ico", 99 | "src/assets" 100 | ], 101 | "styles": [ 102 | "src/styles.scss" 103 | ], 104 | "scripts": [] 105 | } 106 | } 107 | } 108 | } 109 | }, 110 | "defaultProject": "angular-realm-graphql" 111 | } 112 | -------------------------------------------------------------------------------- /karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | jasmine: { 17 | // you can add configuration options for Jasmine here 18 | // the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html 19 | // for example, you can disable the random execution with `random: false` 20 | // or set a specific seed with `seed: 4321` 21 | }, 22 | clearContext: false // leave Jasmine Spec Runner output visible in browser 23 | }, 24 | jasmineHtmlReporter: { 25 | suppressAll: true // removes the duplicated traces 26 | }, 27 | coverageReporter: { 28 | dir: require('path').join(__dirname, './coverage/angular-realm-graphql'), 29 | subdir: '.', 30 | reporters: [ 31 | { type: 'html' }, 32 | { type: 'text-summary' } 33 | ] 34 | }, 35 | reporters: ['progress', 'kjhtml'], 36 | port: 9876, 37 | colors: true, 38 | logLevel: config.LOG_INFO, 39 | autoWatch: true, 40 | browsers: ['Chrome'], 41 | singleRun: false, 42 | restartOnFileChange: true 43 | }); 44 | }; 45 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular-realm-graphql", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve", 7 | "build": "ng build", 8 | "watch": "ng build --watch --configuration development", 9 | "test": "ng test" 10 | }, 11 | "private": true, 12 | "dependencies": { 13 | "@angular/animations": "~14.2.4", 14 | "@angular/common": "~14.2.4", 15 | "@angular/compiler": "~14.2.4", 16 | "@angular/core": "~14.2.4", 17 | "@angular/forms": "~14.2.4", 18 | "@angular/platform-browser": "~14.2.4", 19 | "@angular/platform-browser-dynamic": "~14.2.4", 20 | "@angular/router": "~14.2.4", 21 | "@apollo/client": "3.6.9", 22 | "apollo-angular": "^4.0.1", 23 | "graphql": "^16", 24 | "realm-web": "^1.7.1", 25 | "rxjs": "~7.5.0", 26 | "tslib": "^2.3.0", 27 | "zone.js": "~0.11.4" 28 | }, 29 | "devDependencies": { 30 | "@angular-devkit/build-angular": "~14.2.4", 31 | "@angular/cli": "~14.2.4", 32 | "@angular/compiler-cli": "~14.2.4", 33 | "@types/node": "^12.11.1", 34 | "typescript": "~4.7.2" 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /realm-app/MovieCatalog/auth/custom_user_data.json: -------------------------------------------------------------------------------- 1 | { 2 | "enabled": false 3 | } 4 | -------------------------------------------------------------------------------- /realm-app/MovieCatalog/auth/providers.json: -------------------------------------------------------------------------------- 1 | { 2 | "api-key": { 3 | "name": "api-key", 4 | "type": "api-key", 5 | "disabled": false 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /realm-app/MovieCatalog/data_sources/mongodb-atlas/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mongodb-atlas", 3 | "type": "mongodb-atlas", 4 | "config": { 5 | "clusterName": "MDBAtlasCluster", 6 | "readPreference": "primary", 7 | "wireProtocolEnabled": false 8 | }, 9 | "version": 1 10 | } 11 | -------------------------------------------------------------------------------- /realm-app/MovieCatalog/data_sources/mongodb-atlas/sample_mflix/comments/relationships.json: -------------------------------------------------------------------------------- 1 | { 2 | "movie_id": { 3 | "ref": "#/relationship/mongodb-atlas/sample_mflix/movies", 4 | "source_key": "movie_id", 5 | "foreign_key": "_id", 6 | "is_list": false 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /realm-app/MovieCatalog/data_sources/mongodb-atlas/sample_mflix/comments/rules.json: -------------------------------------------------------------------------------- 1 | { 2 | "collection": "comments", 3 | "database": "sample_mflix", 4 | "roles": [ 5 | { 6 | "name": "default", 7 | "apply_when": {}, 8 | "write": true, 9 | "insert": true, 10 | "delete": true, 11 | "search": true, 12 | "additional_fields": {} 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /realm-app/MovieCatalog/data_sources/mongodb-atlas/sample_mflix/comments/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "properties": { 3 | "_id": { 4 | "bsonType": "objectId" 5 | }, 6 | "date": { 7 | "bsonType": "date" 8 | }, 9 | "email": { 10 | "bsonType": "string" 11 | }, 12 | "movie_id": { 13 | "bsonType": "objectId" 14 | }, 15 | "name": { 16 | "bsonType": "string" 17 | }, 18 | "text": { 19 | "bsonType": "string" 20 | } 21 | }, 22 | "title": "comment" 23 | } 24 | -------------------------------------------------------------------------------- /realm-app/MovieCatalog/data_sources/mongodb-atlas/sample_mflix/movies/relationships.json: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /realm-app/MovieCatalog/data_sources/mongodb-atlas/sample_mflix/movies/rules.json: -------------------------------------------------------------------------------- 1 | { 2 | "collection": "movies", 3 | "database": "sample_mflix", 4 | "roles": [ 5 | { 6 | "name": "default", 7 | "apply_when": {}, 8 | "write": true, 9 | "insert": true, 10 | "delete": true, 11 | "search": true, 12 | "additional_fields": {} 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /realm-app/MovieCatalog/data_sources/mongodb-atlas/sample_mflix/movies/schema.json: -------------------------------------------------------------------------------- 1 | { 2 | "properties": { 3 | "_id": { 4 | "bsonType": "objectId" 5 | }, 6 | "awards": { 7 | "bsonType": "object", 8 | "properties": { 9 | "nominations": { 10 | "bsonType": "int" 11 | }, 12 | "text": { 13 | "bsonType": "string" 14 | }, 15 | "wins": { 16 | "bsonType": "int" 17 | } 18 | } 19 | }, 20 | "cast": { 21 | "bsonType": "array", 22 | "items": { 23 | "bsonType": "string" 24 | } 25 | }, 26 | "countries": { 27 | "bsonType": "array", 28 | "items": { 29 | "bsonType": "string" 30 | } 31 | }, 32 | "directors": { 33 | "bsonType": "array", 34 | "items": { 35 | "bsonType": "string" 36 | } 37 | }, 38 | "fullplot": { 39 | "bsonType": "string" 40 | }, 41 | "genres": { 42 | "bsonType": "array", 43 | "items": { 44 | "bsonType": "string" 45 | } 46 | }, 47 | "imdb": { 48 | "bsonType": "object", 49 | "properties": { 50 | "id": { 51 | "bsonType": "int" 52 | }, 53 | "rating": { 54 | "bsonType": "double" 55 | }, 56 | "votes": { 57 | "bsonType": "int" 58 | } 59 | } 60 | }, 61 | "languages": { 62 | "bsonType": "array", 63 | "items": { 64 | "bsonType": "string" 65 | } 66 | }, 67 | "lastupdated": { 68 | "bsonType": "string" 69 | }, 70 | "metacritic": { 71 | "bsonType": "int" 72 | }, 73 | "num_mflix_comments": { 74 | "bsonType": "int" 75 | }, 76 | "plot": { 77 | "bsonType": "string" 78 | }, 79 | "poster": { 80 | "bsonType": "string" 81 | }, 82 | "rated": { 83 | "bsonType": "string" 84 | }, 85 | "released": { 86 | "bsonType": "date" 87 | }, 88 | "runtime": { 89 | "bsonType": "int" 90 | }, 91 | "title": { 92 | "bsonType": "string" 93 | }, 94 | "tomatoes": { 95 | "bsonType": "object", 96 | "properties": { 97 | "boxOffice": { 98 | "bsonType": "string" 99 | }, 100 | "consensus": { 101 | "bsonType": "string" 102 | }, 103 | "critic": { 104 | "bsonType": "object", 105 | "properties": { 106 | "meter": { 107 | "bsonType": "int" 108 | }, 109 | "numReviews": { 110 | "bsonType": "int" 111 | }, 112 | "rating": { 113 | "bsonType": "double" 114 | } 115 | } 116 | }, 117 | "dvd": { 118 | "bsonType": "date" 119 | }, 120 | "fresh": { 121 | "bsonType": "int" 122 | }, 123 | "lastUpdated": { 124 | "bsonType": "date" 125 | }, 126 | "production": { 127 | "bsonType": "string" 128 | }, 129 | "rotten": { 130 | "bsonType": "int" 131 | }, 132 | "viewer": { 133 | "bsonType": "object", 134 | "properties": { 135 | "meter": { 136 | "bsonType": "int" 137 | }, 138 | "numReviews": { 139 | "bsonType": "int" 140 | }, 141 | "rating": { 142 | "bsonType": "double" 143 | } 144 | } 145 | }, 146 | "website": { 147 | "bsonType": "string" 148 | } 149 | } 150 | }, 151 | "type": { 152 | "bsonType": "string" 153 | }, 154 | "writers": { 155 | "bsonType": "array", 156 | "items": { 157 | "bsonType": "string" 158 | } 159 | }, 160 | "year": { 161 | "bsonType": "int" 162 | } 163 | }, 164 | "title": "movie" 165 | } 166 | -------------------------------------------------------------------------------- /realm-app/MovieCatalog/environments/development.json: -------------------------------------------------------------------------------- 1 | { 2 | "values": {} 3 | } 4 | -------------------------------------------------------------------------------- /realm-app/MovieCatalog/environments/no-environment.json: -------------------------------------------------------------------------------- 1 | { 2 | "values": {} 3 | } 4 | -------------------------------------------------------------------------------- /realm-app/MovieCatalog/environments/production.json: -------------------------------------------------------------------------------- 1 | { 2 | "values": {} 3 | } 4 | -------------------------------------------------------------------------------- /realm-app/MovieCatalog/environments/qa.json: -------------------------------------------------------------------------------- 1 | { 2 | "values": {} 3 | } 4 | -------------------------------------------------------------------------------- /realm-app/MovieCatalog/environments/testing.json: -------------------------------------------------------------------------------- 1 | { 2 | "values": {} 3 | } 4 | -------------------------------------------------------------------------------- /realm-app/MovieCatalog/functions/config.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "loadCommentsOffset", 4 | "private": false, 5 | "disable_arg_logs": true 6 | } 7 | ] 8 | -------------------------------------------------------------------------------- /realm-app/MovieCatalog/functions/loadCommentsOffset.js: -------------------------------------------------------------------------------- 1 | exports = async function(args) { 2 | const { movie_id, limit, offset, sortBy, sortOrder } = args; 3 | const sortOrderNummerical = sortOrder == "ascending" ? 1 : -1; 4 | 5 | const collection = context.services.get("mongodb-atlas").db("sample_mflix").collection("comments"); 6 | 7 | const comments = await collection.find({ movie_id }) 8 | .sort({ [sortBy]: sortOrderNummerical }) 9 | .skip(offset) 10 | .limit(limit) 11 | .toArray(); 12 | 13 | return comments; 14 | } -------------------------------------------------------------------------------- /realm-app/MovieCatalog/graphql/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "use_natural_pluralization": true 3 | } 4 | -------------------------------------------------------------------------------- /realm-app/MovieCatalog/graphql/custom_resolvers/query_CommentsOffset.json: -------------------------------------------------------------------------------- 1 | { 2 | "field_name": "CommentsOffset", 3 | "function_name": "loadCommentsOffset", 4 | "input_type": { 5 | "properties": { 6 | "limit": { 7 | "bsonType": "int" 8 | }, 9 | "movie_id": { 10 | "bsonType": "objectId" 11 | }, 12 | "offset": { 13 | "bsonType": "int" 14 | }, 15 | "sortBy": { 16 | "bsonType": "string" 17 | }, 18 | "sortOrder": { 19 | "bsonType": "string" 20 | } 21 | }, 22 | "title": "CommentsOffsetInput", 23 | "type": "object" 24 | }, 25 | "input_type_format": "custom", 26 | "on_type": "Query", 27 | "payload_type": "Comment", 28 | "payload_type_format": "generated-list" 29 | } 30 | -------------------------------------------------------------------------------- /realm-app/MovieCatalog/http_endpoints/config.json: -------------------------------------------------------------------------------- 1 | [] 2 | -------------------------------------------------------------------------------- /realm-app/MovieCatalog/realm_config.json: -------------------------------------------------------------------------------- 1 | { 2 | "app_id": "moviecatalog-jglch", 3 | "config_version": 20210101, 4 | "name": "MovieCatalog", 5 | "location": "US-VA", 6 | "deployment_model": "GLOBAL" 7 | } 8 | -------------------------------------------------------------------------------- /realm-app/MovieCatalog/sync/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "development_mode_enabled": false 3 | } 4 | -------------------------------------------------------------------------------- /realm-app/README.md: -------------------------------------------------------------------------------- 1 | # Realm Application 2 | 3 | The [`MovieCatalog`](./MovieCatalog/) directory contains the Realm application configuration, including: 4 | 5 | - the schemas of the [`Movies`](./MovieCatalog/data_sources/mongodb-atlas/sample_mflix/movies/schema.json) and [`Comments`](./MovieCatalog/data_sources/mongodb-atlas/sample_mflix/comments/schema.json) collections; 6 | - the [`loadCommentsOffset.js`](./MovieCatalog/functions/loadCommentsOffset.js) function; 7 | - the [`CommentsOffset`](./MovieCatalog/graphql/custom_resolvers/query_CommentsOffset.json) custom resolver. 8 | 9 | To learn more about the configuration, visit the [Realm Application Configuration documentation](https://www.mongodb.com/docs/realm/manage-apps/configure/config/). 10 | -------------------------------------------------------------------------------- /src/app/app-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { RouterModule, Routes } from '@angular/router'; 3 | import { CustomersListComponent } from './customers-list/customers-list.component'; 4 | import { MovieDetailsComponent } from './movie-details/movie-details.component'; 5 | import { MoviesListComponent } from './movies-list/movies-list.component'; 6 | 7 | const routes: Routes = [ 8 | { path: '', redirectTo: 'movies', pathMatch: 'full' }, 9 | { path: 'customers', component: CustomersListComponent }, 10 | { path: 'movies', component: MoviesListComponent }, 11 | { path: 'movies/:id', component: MovieDetailsComponent }, 12 | ]; 13 | 14 | @NgModule({ 15 | imports: [RouterModule.forRoot(routes)], 16 | exports: [RouterModule] 17 | }) 18 | export class AppRoutingModule { } 19 | -------------------------------------------------------------------------------- /src/app/app.component.html: -------------------------------------------------------------------------------- 1 |
2 | 3 |
4 | -------------------------------------------------------------------------------- /src/app/app.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mongodb-developer/angular-realm-graphql/e14171318f062f605c44284c0ff27a37a0f4f60c/src/app/app.component.scss -------------------------------------------------------------------------------- /src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-root', 5 | templateUrl: './app.component.html', 6 | styleUrls: ['./app.component.scss'] 7 | }) 8 | export class AppComponent { 9 | title = 'angular-realm-graphql'; 10 | } 11 | -------------------------------------------------------------------------------- /src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { BrowserModule } from '@angular/platform-browser'; 3 | 4 | import { AppRoutingModule } from './app-routing.module'; 5 | import { AppComponent } from './app.component'; 6 | import { GraphQLModule } from './graphql.module'; 7 | import { HttpClientModule } from '@angular/common/http'; 8 | import { CustomersListComponent } from './customers-list/customers-list.component'; 9 | import { MoviesListComponent } from './movies-list/movies-list.component'; 10 | import { MovieDetailsComponent } from './movie-details/movie-details.component'; 11 | import { CommonModule } from '@angular/common'; 12 | import { ReactiveFormsModule } from '@angular/forms'; 13 | import { CommentFormComponent } from './comment-form/comment-form.component'; 14 | 15 | @NgModule({ 16 | declarations: [ 17 | AppComponent, 18 | CustomersListComponent, 19 | MoviesListComponent, 20 | MovieDetailsComponent, 21 | CommentFormComponent, 22 | ], 23 | imports: [ 24 | BrowserModule, 25 | AppRoutingModule, 26 | GraphQLModule, 27 | HttpClientModule, 28 | CommonModule, 29 | ReactiveFormsModule, 30 | ], 31 | providers: [], 32 | bootstrap: [AppComponent] 33 | }) 34 | export class AppModule { } 35 | -------------------------------------------------------------------------------- /src/app/comment-form/comment-form.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | 4 | 5 |
6 | 7 |
8 |
9 | The name field is required. 10 |
11 |
12 | 13 |
14 | 15 | 16 |
17 | 18 |
19 | 20 |
21 | The comment field is required. 22 |
23 |
24 | The comment must be at least 5 characters long. 25 |
26 |
27 | 28 | 29 |
-------------------------------------------------------------------------------- /src/app/comment-form/comment-form.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mongodb-developer/angular-realm-graphql/e14171318f062f605c44284c0ff27a37a0f4f60c/src/app/comment-form/comment-form.component.scss -------------------------------------------------------------------------------- /src/app/comment-form/comment-form.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; 2 | import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms'; 3 | import { BehaviorSubject } from 'rxjs'; 4 | 5 | import { Comment } from '../comment'; 6 | 7 | @Component({ 8 | selector: 'app-comment-form', 9 | templateUrl: './comment-form.component.html', 10 | styleUrls: ['./comment-form.component.scss'] 11 | }) 12 | export class CommentFormComponent implements OnInit { 13 | @Input() 14 | initialState: BehaviorSubject> = new BehaviorSubject({}); 15 | 16 | @Output() 17 | formValuesChanged = new EventEmitter(); 18 | 19 | @Output() 20 | formSubmitted = new EventEmitter(); 21 | 22 | commentForm: FormGroup; 23 | 24 | get name() { return this.commentForm.get('name')!; } 25 | get text() { return this.commentForm.get('text')!; } 26 | 27 | constructor(private fb: FormBuilder) { } 28 | 29 | ngOnInit(): void { 30 | this.initialState.subscribe(comment => { 31 | this.commentForm = this.fb.group({ 32 | name: [ comment.name, [Validators.required] ], 33 | text: [ comment.text, [ Validators.required, Validators.minLength(5) ] ], 34 | }); 35 | }); 36 | 37 | this.commentForm.valueChanges.subscribe((val) => { this.formValuesChanged.emit(val); }); 38 | } 39 | 40 | submitForm() { 41 | this.formSubmitted.emit({ 42 | ...this.commentForm.value, 43 | date: new Date() 44 | }); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/app/comment.ts: -------------------------------------------------------------------------------- 1 | export interface Comment { 2 | _id?: string; 3 | movie_id?: string | { link: string }; 4 | name: string; 5 | text: string; 6 | date: string; 7 | } 8 | -------------------------------------------------------------------------------- /src/app/customers-list/customers-list.component.html: -------------------------------------------------------------------------------- 1 |
    2 |
  • 3 | {{ customer.name }} 4 |
  • 5 |
6 | -------------------------------------------------------------------------------- /src/app/customers-list/customers-list.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mongodb-developer/angular-realm-graphql/e14171318f062f605c44284c0ff27a37a0f4f60c/src/app/customers-list/customers-list.component.scss -------------------------------------------------------------------------------- /src/app/customers-list/customers-list.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { Apollo, gql } from 'apollo-angular'; 3 | import { Observable } from 'rxjs'; 4 | import { map } from 'rxjs/operators'; 5 | 6 | const GET_ALL_CUSTOMERS = gql` 7 | query GetAllCustomers { 8 | customers { 9 | name 10 | } 11 | } 12 | `; 13 | 14 | @Component({ 15 | selector: 'app-customers-list', 16 | templateUrl: './customers-list.component.html', 17 | styleUrls: ['./customers-list.component.scss'] 18 | }) 19 | export class CustomersListComponent implements OnInit { 20 | customers: Observable; 21 | 22 | constructor(private apollo: Apollo) {} 23 | 24 | ngOnInit() { 25 | this.customers = this.apollo 26 | .watchQuery({query: GET_ALL_CUSTOMERS}) 27 | .valueChanges.pipe(map((result: any) => result?.data?.customers)); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/app/graphql.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { ApolloModule, APOLLO_OPTIONS } from 'apollo-angular'; 3 | import { ApolloClientOptions, InMemoryCache, ApolloLink } from '@apollo/client/core'; 4 | import { HttpLink } from 'apollo-angular/http'; 5 | import * as Realm from "realm-web"; 6 | import { setContext } from '@apollo/client/link/context'; 7 | import { environment } from './../environments/environment'; 8 | 9 | const { APP_ID, GRAPHQL_URI, API_KEY } = environment; 10 | 11 | const app = new Realm.App(APP_ID); 12 | 13 | // Gets a valid Realm user access token to authenticate requests 14 | async function getValidAccessToken() { 15 | // Guarantee that there's a logged in user with a valid access token 16 | if (!app.currentUser) { 17 | // If no user is logged in, log in an anonymous user. The logged in user will have a valid 18 | // access token. 19 | const credentials = Realm.Credentials.apiKey(API_KEY); 20 | await app.logIn(credentials); 21 | } else { 22 | // An already logged in user's access token might be stale. To guarantee that the token is 23 | // valid, we refresh the user's custom data which also refreshes their access token. 24 | await app.currentUser.refreshCustomData(); 25 | } 26 | return app.currentUser! .accessToken; 27 | } 28 | 29 | export function createApollo(httpLink: HttpLink): ApolloClientOptions { 30 | const http = httpLink.create({ uri: GRAPHQL_URI }); 31 | 32 | // Create a new ApolloLink that appends the access token to the headers of each GraphQL request. 33 | const auth = setContext(async () => { 34 | const token = await getValidAccessToken(); 35 | 36 | return { 37 | headers: { 38 | Authorization: `Bearer ${token}`, 39 | }, 40 | }; 41 | }); 42 | 43 | const link = auth.concat(http); 44 | 45 | return { 46 | link, 47 | cache: new InMemoryCache(), 48 | }; 49 | } 50 | 51 | @NgModule({ 52 | exports: [ApolloModule], 53 | providers: [ 54 | { 55 | provide: APOLLO_OPTIONS, 56 | useFactory: createApollo, 57 | deps: [HttpLink], 58 | }, 59 | ], 60 | }) 61 | export class GraphQLModule { } 62 | -------------------------------------------------------------------------------- /src/app/movie-details/movie-details.component.html: -------------------------------------------------------------------------------- 1 |
2 | Loading the movie... 3 |
4 | 5 | 6 |
7 | 8 |
9 | 10 |
11 |

{{ movie.title }}

12 |
13 |
14 | IMDb Rating 15 | ⭐️   {{ movie.imdb?.rating }}/10 16 |
17 | 18 |
19 | Audience Score 20 | ⭐️   {{ movie.tomatoes?.viewer?.meter }}% 21 |
22 | 23 |
24 | Tomatometer 25 | ⭐️   {{ movie.tomatoes?.critic?.meter }}% 26 |
27 |
28 | 29 |

{{ movie.fullplot }}

30 | {{movie.year}} | {{ movie.rated || 'UNRATED' }} | {{ movie.runtime }} min 31 |
32 |
33 |
34 | 35 |
36 |

Comments

37 |
38 | 39 |
40 | Author: {{ comment.name }} 41 | Date: {{ comment.date | date }} 42 |

{{ comment.text }}

43 |
44 |
45 | 46 | 47 | 48 | 49 | 50 |
Loading comments...
51 | 52 | 53 | No comments yet. 54 | 55 |
56 | 57 |
58 |

Add a comment

59 | 60 |
61 | 62 | 63 |
-------------------------------------------------------------------------------- /src/app/movie-details/movie-details.component.scss: -------------------------------------------------------------------------------- 1 | .movie { 2 | margin: 20px 0; 3 | 4 | .movie-title { 5 | margin-bottom: 30px; 6 | } 7 | 8 | .movie-details { 9 | display: flex; 10 | flex-direction: row; 11 | gap: 30px; 12 | } 13 | 14 | .ratings { 15 | display: flex; 16 | gap: 20px; 17 | } 18 | 19 | .rating-container { 20 | display: flex; 21 | flex-direction: column; 22 | align-items: center; 23 | gap: 5px; 24 | width: 120px; 25 | 26 | .rating-provider { 27 | font-size: 15px; 28 | } 29 | 30 | .rating { 31 | font-size: 20px; 32 | } 33 | } 34 | 35 | .plot { 36 | margin-top: 20px; 37 | } 38 | 39 | .movie-poster { 40 | width: 350px; 41 | max-height: 500px; 42 | } 43 | } 44 | 45 | .add-comment { 46 | margin: 50px 0; 47 | } 48 | 49 | .movie, .comments, .add-comment { 50 | // background-color: #f6f6f5; 51 | padding: 30px 50px; 52 | border: 1px solid rgba(0,0,0,.2); 53 | border-radius: 0.25rem; 54 | } 55 | 56 | .comment { 57 | display: flex; 58 | flex-direction: column; 59 | gap: 10px; 60 | } 61 | -------------------------------------------------------------------------------- /src/app/movie-details/movie-details.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { ActivatedRoute } from '@angular/router'; 3 | import { Apollo, gql } from 'apollo-angular'; 4 | import { Observable } from 'rxjs'; 5 | import { Movie } from '../movie'; 6 | import { Comment } from '../comment'; 7 | 8 | const GET_MOVIE_WITH_COMMENTS = gql` 9 | query GetMovieWithComments($movie_id: ObjectId) { 10 | movie(query:{ _id: $movie_id }) { 11 | poster 12 | title 13 | fullplot 14 | year 15 | type 16 | rated 17 | imdb { 18 | rating 19 | } 20 | tomatoes { 21 | viewer { 22 | meter 23 | } 24 | critic { 25 | meter 26 | } 27 | } 28 | } 29 | 30 | comments(query: { movie_id: { _id: $movie_id } }, limit: 5, sortBy: DATE_DESC) { 31 | name, 32 | date, 33 | text 34 | } 35 | } 36 | `; 37 | 38 | const ADD_COMMENT = gql` 39 | mutation AddComment($comment: CommentInsertInput!) { 40 | insertOneComment(data: $comment) { 41 | name 42 | text 43 | date 44 | } 45 | } 46 | `; 47 | 48 | const LOAD_COMMENTS_OFFSET = gql` 49 | query LoadCommentsWithOffset($input: CommentsOffsetInput!) { 50 | CommentsOffset(input: $input) { 51 | name, 52 | text, 53 | date 54 | } 55 | } 56 | `; 57 | 58 | @Component({ 59 | selector: 'app-movie-details', 60 | templateUrl: './movie-details.component.html', 61 | styleUrls: ['./movie-details.component.scss'] 62 | }) 63 | export class MovieDetailsComponent implements OnInit { 64 | private id: string; 65 | movieAndComments$: Observable<{ movie: Movie, comments: Comment[] }>; 66 | movie: Movie; 67 | comments: Comment[]; 68 | movieLoading = true; 69 | commentsLoading = false; 70 | 71 | constructor( 72 | private route: ActivatedRoute, 73 | private apollo: Apollo 74 | ) { } 75 | 76 | ngOnInit(): void { 77 | this.route.params.subscribe(params => { 78 | this.id = params['id']; 79 | 80 | this.apollo 81 | .watchQuery({ 82 | query: GET_MOVIE_WITH_COMMENTS, 83 | variables: { 84 | movie_id: this.id 85 | } 86 | }) 87 | .valueChanges 88 | .subscribe({ 89 | next: (result: any) => { 90 | this.movieLoading = result?.loading; 91 | this.movie = result?.data?.movie; 92 | this.comments = result?.data?.comments; 93 | } 94 | }); 95 | }); 96 | } 97 | 98 | addComment(comment: Comment) { 99 | comment.movie_id = { 100 | link: this.id 101 | }; 102 | 103 | this.apollo.mutate({ 104 | mutation: ADD_COMMENT, 105 | variables: { comment } 106 | }) 107 | .subscribe((result: any) => { 108 | if (result?.data?.insertOneComment) { 109 | this.comments = [result?.data?.insertOneComment, ...this.comments]; 110 | } 111 | }); 112 | } 113 | 114 | loadMoreComments() { 115 | this.commentsLoading = true; 116 | 117 | const input = { 118 | movie_id: this.id, 119 | offset: this.comments.length, 120 | limit: 5, 121 | sortBy: "date", 122 | sortOrder: "DESC" 123 | } 124 | 125 | this.apollo.query({ 126 | query: LOAD_COMMENTS_OFFSET, 127 | variables: { input } 128 | }) 129 | .subscribe((result: any) => { 130 | this.commentsLoading = result?.data?.loading; 131 | if (result?.data?.CommentsOffset) { 132 | this.comments = [...this.comments, ...result?.data?.CommentsOffset]; 133 | } 134 | }); 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /src/app/movie.ts: -------------------------------------------------------------------------------- 1 | export interface Movie { 2 | _id?: string; 3 | title?: string; 4 | year?: number; 5 | rated?: string; 6 | released?: string; 7 | plot?: string; 8 | fullplot?: string; 9 | type?: string; 10 | poster?: string; 11 | runtime?: number; 12 | directors?: string[]; 13 | genres?: string[]; 14 | imdb?: { 15 | rating: number; 16 | }; 17 | tomatoes?: { 18 | viewer?: { 19 | meter: number; 20 | } 21 | critic?: { 22 | meter: number; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/app/movies-list/movies-list.component.html: -------------------------------------------------------------------------------- 1 |

Movie Catalog

2 | 3 |
4 | Loading the movies... 5 |
6 | 7 |
8 | 9 | {{ movie.title }} 11 | 12 |
13 |

14 | {{ movie.title }} 15 |

16 | 17 | {{ movie.rated || 'UNRATED' }} | {{ movie.runtime }} min | {{ movie.year }} 18 | ⭐️  {{ movie.imdb?.rating }} 19 | 20 |

{{ movie.plot }}

21 |
22 |
-------------------------------------------------------------------------------- /src/app/movies-list/movies-list.component.scss: -------------------------------------------------------------------------------- 1 | .movie-card { 2 | display: flex; 3 | gap: 20px; 4 | padding: 20px; 5 | margin-bottom: 10px; 6 | background-color: #f6f6f5; 7 | 8 | .movie-poster { 9 | width: 150px; 10 | max-height: 300px; 11 | } 12 | 13 | .movie-details { 14 | display: flex; 15 | flex-direction: column; 16 | justify-content: flex-start; 17 | gap: 10px; 18 | } 19 | 20 | .movie-title a { 21 | color: royalblue; 22 | text-decoration: none; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/app/movies-list/movies-list.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { Apollo, gql } from 'apollo-angular'; 3 | import { Observable } from 'rxjs'; 4 | import { map, tap } from 'rxjs/operators'; 5 | import { Movie } from '../movie'; 6 | 7 | const GET_ALL_MOVIES = gql` 8 | query GetAllMovies { 9 | movies(limit: 20, query: { num_mflix_comments_gt: 10 }) { 10 | _id 11 | title 12 | poster 13 | year 14 | runtime 15 | rated 16 | plot 17 | imdb { 18 | rating 19 | } 20 | } 21 | } 22 | `; 23 | 24 | @Component({ 25 | selector: 'app-movies-list', 26 | templateUrl: './movies-list.component.html', 27 | styleUrls: ['./movies-list.component.scss'] 28 | }) 29 | export class MoviesListComponent implements OnInit { 30 | movies$: Observable; 31 | moviesLoading = true; 32 | 33 | constructor(private apollo: Apollo) {} 34 | 35 | ngOnInit() { 36 | this.movies$ = this.apollo 37 | .watchQuery({query: GET_ALL_MOVIES}) 38 | .valueChanges.pipe( 39 | tap((result: any) => { this.moviesLoading = result?.loading }), 40 | map((result: any) => result?.data?.movies) 41 | ); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mongodb-developer/angular-realm-graphql/e14171318f062f605c44284c0ff27a37a0f4f60c/src/assets/.gitkeep -------------------------------------------------------------------------------- /src/assets/no-poster.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mongodb-developer/angular-realm-graphql/e14171318f062f605c44284c0ff27a37a0f4f60c/src/assets/no-poster.jpeg -------------------------------------------------------------------------------- /src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true, 3 | APP_ID: '', 4 | GRAPHQL_URI: '', 5 | API_KEY: '', 6 | }; 7 | -------------------------------------------------------------------------------- /src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: false, 3 | APP_ID: 'moviecatalog-jglch', 4 | GRAPHQL_URI: 'https://realm.mongodb.com/api/client/v2.0/app/moviecatalog-jglch/graphql', 5 | API_KEY: 'fSrE3UlsR0KK0mriU4gHeaF8Ba6IfhFxXEvvCM9haMhp9dSiLZrvZYyiOt1YQ6fI', 6 | }; 7 | -------------------------------------------------------------------------------- /src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mongodb-developer/angular-realm-graphql/e14171318f062f605c44284c0ff27a37a0f4f60c/src/favicon.ico -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | AngularAnalyticsGraphql 6 | 7 | 8 | 9 | 10 | 12 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule) 12 | .catch(err => console.error(err)); 13 | -------------------------------------------------------------------------------- /src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes recent versions of Safari, Chrome (including 12 | * Opera), Edge on the desktop, and iOS and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/guide/browser-support 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** 22 | * By default, zone.js will patch all possible macroTask and DomEvents 23 | * user can disable parts of macroTask/DomEvents patch by setting following flags 24 | * because those flags need to be set before `zone.js` being loaded, and webpack 25 | * will put import in the top of bundle, so user need to create a separate file 26 | * in this directory (for example: zone-flags.ts), and put the following flags 27 | * into that file, and then add the following code before importing zone.js. 28 | * import './zone-flags'; 29 | * 30 | * The flags allowed in zone-flags.ts are listed here. 31 | * 32 | * The following flags will work for all browsers. 33 | * 34 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 35 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 36 | * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 37 | * 38 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 39 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 40 | * 41 | * (window as any).__Zone_enable_cross_context_check = true; 42 | * 43 | */ 44 | 45 | /*************************************************************************************************** 46 | * Zone JS is required by default for Angular itself. 47 | */ 48 | import 'zone.js'; // Included with Angular CLI. 49 | 50 | 51 | /*************************************************************************************************** 52 | * APPLICATION IMPORTS 53 | */ 54 | -------------------------------------------------------------------------------- /src/styles.scss: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | -------------------------------------------------------------------------------- /tsconfig.app.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "extends": "./tsconfig.json", 4 | "compilerOptions": { 5 | "outDir": "./out-tsc/app", 6 | "types": [] 7 | }, 8 | "files": [ 9 | "src/main.ts", 10 | "src/polyfills.ts" 11 | ], 12 | "include": [ 13 | "src/**/*.d.ts" 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "forceConsistentCasingInFileNames": true, 7 | "strict": true, 8 | "noImplicitOverride": true, 9 | "noPropertyAccessFromIndexSignature": true, 10 | "noImplicitReturns": true, 11 | "noFallthroughCasesInSwitch": true, 12 | "sourceMap": true, 13 | "declaration": false, 14 | "downlevelIteration": true, 15 | "experimentalDecorators": true, 16 | "moduleResolution": "node", 17 | "importHelpers": true, 18 | "target": "es2017", 19 | "module": "es2020", 20 | "lib": [ 21 | "es2020", 22 | "dom", 23 | "esnext.asynciterable" 24 | ], 25 | "allowSyntheticDefaultImports": true, 26 | "strictPropertyInitialization": false 27 | }, 28 | "angularCompilerOptions": { 29 | "enableI18nLegacyMessageIdFormat": false, 30 | "strictInjectionParameters": true, 31 | "strictInputAccessModifiers": true, 32 | "strictTemplates": true 33 | } 34 | } -------------------------------------------------------------------------------- /tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "extends": "./tsconfig.json", 4 | "compilerOptions": { 5 | "outDir": "./out-tsc/spec", 6 | "types": [ 7 | "jasmine" 8 | ] 9 | }, 10 | "files": [ 11 | "src/test.ts", 12 | "src/polyfills.ts" 13 | ], 14 | "include": [ 15 | "src/**/*.spec.ts", 16 | "src/**/*.d.ts" 17 | ] 18 | } 19 | --------------------------------------------------------------------------------