To build a example chat app.
* make sure you have installed Angular CLI
* add environment variable mongodb_gdg
for your MongoDb, the gdg_test
database will be used.
export mongodb_gdg='<<USERNAME>>:<<PASSWORD>>@<<MONGODB_URL>>'
Start:
npm i;
cd web;
npm i;
npm i -g @angular/cli;
ng build --prod &&
cd .. &&
tsc &&
npm run serve;
start a mongodb atlas server
npm init;
npm install express mongoose apollo-server-express graphql class-validator type-graphql reflect-metadata @typegoose/typegoose body-parser
--save;
npm install @types/express @types/mongoose @types/body-parser --save-dev;
typescript config file.
{
"compilerOptions": {
"outDir": "./build",
"rootDir": ".",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"strictPropertyInitialization": false,
},
"exclude": [
"web/**/*",
]
}
mkdir web;
cd web;
ng new ui --directory ./;
ng serve;
angular.json
{
"projects": {
"ui": {
"architect": {
"build": {
"options": {
"outputPath": "dist/dev"
},
"configurations": {
"production": {
"outputPath": "dist/production"
}
}
}
}
}
}
}
web/package.json
{
"scripts": {
"bp": "ng build --prod --aot --vendor-chunk --common-chunk --buildOptimizer"
}
}
mkdir schema;
mkdir server;
ng add apollo-angular;
A new Angular Module graphql.module.ts
file should be automatically created
If you do not get this file please visit: https://www.apollographql.com/docs/angular/basics/setup/#installation-without-angular-schematics
npm install --save-dev @graphql-codegen/cli @graphql-codegen/typescript;
npx graphql-codegen init;
- What type of application are you building?
Application built with Angular
- Where is your schema?
http://localhost:3000/graphql
- Where are your operations and fragments? Enter
- Pick plugins: Enter
- Where to write the output: Enter
- Do you want to generate an introspection file? Enter
- How to name the config file? Enter
- What script in package.json should run the codegen?
cg
- This allow you to use
npm run cg;
to do code generate from graphql query
- This allow you to use
npm i;
Create a file with simple query @ src > app > test.graphql
query Test{
scho
}
- If you need a MongoDb database use MongoDb Atlas its' free.