Skip to content

Commit 1a2ff2d

Browse files
author
Franciszek Stodulski
authored
Develop (#22)
* Create docker-compose (#1) * build: created dockerfile * refactor: chaged default server type * Feature/data seed (#2) * feat: create primitive seed * feat: created prototype for seed * feat: single person controller * refactor: changed API endpoint url * feat: added avatarURL for person, added new Query for Person (#3) * feat: added avatarURL for person, added new Query for Person * refactor: avatar_url * Improve setup (#4) * fix: docker-compose config * chore: simplify readme, watch local files in docker * fix: imports in server files * fix: imports in server files * fix: app image setup, readme, import directory * feat: add prettier * fix: remove unwanted comment * chore: add info about api address * Feature/datamodel (#5) * feat: added seed for types * fix: update missing resolvers * fix: fix for code review * refactor: geting rid of docker * Rest endpoints (#6) * fix: update readme * feat: add crud for heroes * feat: types crud * feat: add avatars crud * feat: add rest api docs * fix: remove yarn.lock * fix: code review * feat: avatar crud (#7) * feat: avatar crud * fix: fix for avatar crud * Feature/hero (#8) * fix: fix for hero update * refactor: remove try/catch * feat: added Error Handler for graphql * Feature/hero (#9) * fix: fix for hero update * refactor: remove try/catch * feat: added Error Handler for graphql * feat: updated config * feat: updated hero mutation * feat: add search api (#10) * feat: add search api * refactor: changed a little bit * refactor: remove notreachable code * refactor: update avatar urls * feat: add hero query & add description field * fix: make ID param to be mandatory * refactor: support mutations & make arguments consistent * chore: add pull request template * feat: heroes pagination (#16) * fix(rest): fix for api (#18) * feat: Add pagination to heroes endpoint (#19) * feat: add-pagination-to-heroes-endpoint * feat: use first, skip params for heroes request
1 parent b0304a7 commit 1a2ff2d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1076
-180
lines changed

.dockerignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
Dockerfile
3+
schema-compiled.graphql

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
generated
22
node_modules/
33
schema-compiled.graphql
4+
src/.DS_Store

.prettierrc

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"useTabs": false,
3+
"printWidth": 80,
4+
"tabWidth": 2,
5+
"singleQuote": true,
6+
"trailingComma": "es5",
7+
"jsxBracketSameLine": true,
8+
"semi": true
9+
}

PULL_REQUEST_TEMPLATE.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## Description
2+
3+
<!-- What is the purpose of this PR? -->
4+
<!-- What are the things that might not be obvious to a reviewer?? -->

REST_index.ts

-19
This file was deleted.

datamodel.prisma

-13
This file was deleted.

datamodel/avatar.prisma

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
type Avatar {
2+
id: ID! @id
3+
alt: String! @defalut(value: "Image")
4+
avatar_url: String!
5+
}

datamodel/hero.prisma

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
type Hero {
2+
id: ID! @id
3+
avatar_url: String! @default(value: "https://cdn4.iconfinder.com/data/icons/avatars-xmas-giveaway/128/batman_hero_avatar_comics-512.png")
4+
full_name: String!
5+
description: String!
6+
type: Type! @relation(link: INLINE)
7+
}

datamodel/job.prisma

-5
This file was deleted.

datamodel/person.prisma

-6
This file was deleted.

datamodel/type.prisma

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
type Type {
2+
id: ID! @id
3+
name: String!
4+
}

docker-compose.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
version: "3"
1+
version: '3'
22
services:
33
prisma:
44
image: prismagraphql/prisma:1.34
55
restart: always
6+
depends_on:
7+
- mysql
68
ports:
7-
- "4466:4466"
9+
- '4466:4466'
810
environment:
911
PRISMA_CONFIG: |
1012
port: 4466

package-lock.json

+9-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+9-7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "",
55
"main": "commintlint.conf.js",
66
"dependencies": {
7+
"body-parser": "^1.19.0",
78
"body-parser-graphql": "^1.1.0",
89
"express": "^4.17.1",
910
"gql2ts": "^1.10.1",
@@ -17,20 +18,21 @@
1718
"@types/express": "^4.16.1",
1819
"@types/node": "^12.0.3",
1920
"husky": "^2.3.0",
21+
"prettier": "^1.18.2",
2022
"prisma": "^1.34.0",
2123
"ts-node": "^8.2.0",
2224
"ts-node-dev": "^1.0.0-pre.39",
2325
"typescript": "^3.4.5"
2426
},
2527
"scripts": {
26-
"generate": "prisma generate",
27-
"prepare": "npm i && prisma deploy && npm run start:rest",
28-
"start:graphql": "ts-node GRAPHQL_index.ts",
29-
"start:rest": "ts-node REST_index.ts",
30-
"dev:rest": "npm run deploy && ts-node-dev --no-notify --respawn --transpileOnly ./REST_index.ts",
31-
"dev:graphql": "npm run deploy && ts-node-dev --no-notify --respawn --transpileOnly ./GRAPHQL_index.ts",
28+
"start:rest": "ts-node ./src/server-rest.ts",
29+
"start:graphql": "ts-node ./src/server-graphql.ts",
30+
"dev:rest": "ts-node-dev --no-notify --respawn --transpileOnly ./src/server-rest.ts",
31+
"dev:graphql": "ts-node-dev --no-notify --respawn --transpileOnly ./src/server-graphql.ts",
3232
"deploy": "npm run gst && prisma deploy",
33-
"gst": "ts-node gen-schema.ts"
33+
"generate": "prisma generate",
34+
"gst": "ts-node gen-schema.ts",
35+
"seed": "prisma seed --reset"
3436
},
3537
"author": "",
3638
"license": "ISC",

prisma.yml

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
endpoint: http://localhost:4466
1+
endpoint: 'http://localhost:4466'
22
datamodel:
3-
- ./datamodel/person.prisma
4-
- ./datamodel/job.prisma
3+
- ./datamodel/hero.prisma
4+
- ./datamodel/type.prisma
5+
- ./datamodel/avatar.prisma
56

67
seed:
7-
run: ts-node ./src/seed/index.ts
8+
run: ts-node ./seed.ts
89

910
generate:
1011
- generator: typescript-client

schema.graphql

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
#import Query.*, Mutation.*, * from './src/graphql/Person/person-schema.graphql'
2-
#import Query.*, Mutation.*, * from './src/graphql/Job/job-schema.graphql'
1+
#import Query.*, Mutation.*, * from './src/graphql/Hero/hero-schema.graphql'
2+
#import Query.*, Mutation.*, * from './src/graphql/Type/type-schema.graphql'
3+
#import Query.*, Mutation.*, * from './src/graphql/Avatar/avatar-schema.graphql'

seed.ts

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
import { prisma } from './generated/prisma-client';
2+
3+
// Interfaces
4+
import { IAvatar } from '@interface/avatar';
5+
import { IHero } from '@interface/hero';
6+
7+
// Seed data
8+
import { SEED_AVATARS } from './seed/avatar';
9+
import {
10+
SEED_ANIMAL_HERO,
11+
SEED_HUMAN_HERO,
12+
SEED_OTHER_HERO,
13+
SEED_PLANT_HERO,
14+
} from './seed/hero';
15+
16+
const avatarSeeds = SEED_AVATARS.map(
17+
async ({ alt, avatar_url }: IAvatar, index: number) => {
18+
const response = await prisma.createAvatar({
19+
alt,
20+
avatar_url,
21+
});
22+
23+
return response;
24+
},
25+
);
26+
27+
export async function main() {
28+
const avatarsSeed = await Promise.all(avatarSeeds);
29+
30+
const humanTypeSeed = await prisma.createType({
31+
name: 'Human',
32+
});
33+
34+
const animalTypeSeed = await prisma.createType({
35+
name: 'Animal',
36+
});
37+
38+
const otherTypeSeed = await prisma.createType({
39+
name: 'Other',
40+
});
41+
42+
const plantTypeSeed = await prisma.createType({
43+
name: 'Plant',
44+
});
45+
46+
// HUMAN HERO SEED
47+
const humanHeroSeed = SEED_HUMAN_HERO.map(
48+
async ({ avatar_url, full_name, description, type }: IHero, index: number) => {
49+
return prisma.createHero({
50+
full_name,
51+
avatar_url,
52+
description,
53+
type: {
54+
connect: {
55+
id: type.replace('#ID', humanTypeSeed.id),
56+
},
57+
},
58+
});
59+
},
60+
);
61+
62+
// ANIMAL HERO SEED
63+
const animalHeroSeed = SEED_ANIMAL_HERO.map(
64+
async ({ avatar_url, full_name, description, type }: IHero, index: number) => {
65+
return prisma.createHero({
66+
full_name,
67+
avatar_url,
68+
description,
69+
type: {
70+
connect: {
71+
id: type.replace('#ID', animalTypeSeed.id),
72+
},
73+
},
74+
});
75+
},
76+
);
77+
78+
// PLANT HERO SEED
79+
const plantHeroSeed = SEED_PLANT_HERO.map(
80+
async ({ avatar_url, full_name, description, type }: IHero, index: number) => {
81+
return prisma.createHero({
82+
full_name,
83+
avatar_url,
84+
description,
85+
type: {
86+
connect: {
87+
id: type.replace('#ID', plantTypeSeed.id),
88+
},
89+
},
90+
});
91+
},
92+
);
93+
94+
// OTHER HERO SEED
95+
const otherHeroSeed = SEED_OTHER_HERO.map(
96+
async ({ avatar_url, full_name, description, type }: IHero, index: number) => {
97+
return prisma.createHero({
98+
full_name,
99+
avatar_url,
100+
description,
101+
type: {
102+
connect: {
103+
id: type.replace('#ID', otherTypeSeed.id),
104+
},
105+
},
106+
});
107+
},
108+
);
109+
}
110+
111+
main().catch((error) => console.log(error));

0 commit comments

Comments
 (0)