Skip to content

Commit

Permalink
Merge branch 'master' into helm-chart-simplified
Browse files Browse the repository at this point in the history
  • Loading branch information
adnanrahic committed Sep 3, 2024
2 parents 09fb1dc + e04430a commit 65d8203
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 3 deletions.
67 changes: 67 additions & 0 deletions api/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"kafkajs": "^2.2.4",
"koa": "^2.14.2",
"koa-bodyparser": "^4.4.0",
"koa-graphql": "^0.12.0",
"koa-logger": "^3.2.1",
"koa-mount": "^4.0.0",
"koa-static": "^5.0.0",
Expand Down
4 changes: 4 additions & 0 deletions api/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import updateHandler from '@pokemon/handlers/update.handler';
import healthcheckHandler from '@pokemon/handlers/healthcheck.handler';
import { setupSequelize } from '@pokemon/utils/db';
import { instrumentRoute } from '@pokemon/middlewares/instrumentation';
import { graphqlHTTP } from 'koa-graphql';
import schema from './schema';
import resolvers from './graphql/resolvers';

const { APP_PORT = 8081 } = process.env;

Expand Down Expand Up @@ -53,6 +56,7 @@ async function startApp() {

ui.use(serve(resolve(__dirname, './ui')));
app.use(mount('/', ui));
app.use(mount('/graphql', graphqlHTTP({ schema, rootValue: resolvers, graphiql: true })));

console.log(`Starting server on port ${APP_PORT}`);
app.listen(APP_PORT);
Expand Down
9 changes: 9 additions & 0 deletions api/src/graphql/create.resolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { getPokemonRepository, Pokemon } from '@pokemon/repositories';

const create = async (raw: Pokemon): Promise<Pokemon> => {
const repository = getPokemonRepository();

return repository.create(new Pokemon(raw));
};

export default create;
20 changes: 20 additions & 0 deletions api/src/graphql/get.resolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { getPokemonRepository, Pokemon } from '@pokemon/repositories';
import { SearchOptions } from '../repositories/pokemon.repository';

type PokemonList = {
items: Pokemon[];
totalCount: number;
};

const get = async (query: SearchOptions): Promise<PokemonList> => {
const repository = getPokemonRepository();

const [items, totalCount] = await Promise.all([repository.findMany(query), repository.count()]);

return {
items,
totalCount,
};
};

export default get;
13 changes: 13 additions & 0 deletions api/src/graphql/import.resolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import PokeAPIService from '@pokemon/services/pokeApi.service';
import PokemonSyncronizer from '@pokemon/services/pokemonSyncronizer.service';

const pokeApiService = new PokeAPIService();
const pokemonSyncronizer = PokemonSyncronizer(pokeApiService);

const importPokemon = async ({ id = 0 }) => {
await pokemonSyncronizer.queue({ id });

return { id };
};

export default importPokemon;
9 changes: 9 additions & 0 deletions api/src/graphql/resolvers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import createPokemon from './create.resolver';
import getPokemonList from './get.resolver';
import importPokemon from './import.resolver';

export default {
getPokemonList,
createPokemon,
importPokemon,
};
2 changes: 0 additions & 2 deletions api/src/repositories/pokemon.repository.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { PokemonModel } from './pokemon.sequelize.repository';

export class Pokemon {
public id?: number;
public name: string;
Expand Down
31 changes: 31 additions & 0 deletions api/src/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { buildSchema } from 'graphql';

const schema = buildSchema(`
type Pokemon {
id: Int
name: String!
type: String!
isFeatured: Boolean!
imageUrl: String
}
type PokemonList {
items: [Pokemon]
totalCount: Int
}
type ImportPokemon {
id: Int!
}
type Query {
getPokemonList(where: String, skip: Int, take: Int): PokemonList
}
type Mutation {
createPokemon(name: String!, type: String!, isFeatured: Boolean!, imageUrl: String): Pokemon!
importPokemon(id: Int!): ImportPokemon!
}
`);

export default schema;
2 changes: 1 addition & 1 deletion test/artillery/import-pokemon.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ config:
environment: "test"
tool: "Artillery"
tracetest:
token: tttoken_a2d67564c92023b6
token: 0_3A703Sg
definition: ./test/artillery/import-pokemon-definition.yml
serverUrl: https://app.tracetest.io/
runInfo:
Expand Down

0 comments on commit 65d8203

Please sign in to comment.