Updating
This commit is contained in:
25
graphql/.eslintrc.js
Normal file
25
graphql/.eslintrc.js
Normal file
@@ -0,0 +1,25 @@
|
||||
module.exports = {
|
||||
parser: '@typescript-eslint/parser',
|
||||
parserOptions: {
|
||||
project: 'tsconfig.json',
|
||||
tsconfigRootDir: __dirname,
|
||||
sourceType: 'module',
|
||||
},
|
||||
plugins: ['@typescript-eslint/eslint-plugin'],
|
||||
extends: [
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
'plugin:prettier/recommended',
|
||||
],
|
||||
root: true,
|
||||
env: {
|
||||
node: true,
|
||||
jest: true,
|
||||
},
|
||||
ignorePatterns: ['.eslintrc.js'],
|
||||
rules: {
|
||||
'@typescript-eslint/interface-name-prefix': 'off',
|
||||
'@typescript-eslint/explicit-function-return-type': 'off',
|
||||
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
},
|
||||
};
|
||||
35
graphql/.gitignore
vendored
Normal file
35
graphql/.gitignore
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
# compiled output
|
||||
/dist
|
||||
/node_modules
|
||||
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
pnpm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
|
||||
# OS
|
||||
.DS_Store
|
||||
|
||||
# Tests
|
||||
/coverage
|
||||
/.nyc_output
|
||||
|
||||
# IDEs and editors
|
||||
/.idea
|
||||
.project
|
||||
.classpath
|
||||
.c9/
|
||||
*.launch
|
||||
.settings/
|
||||
*.sublime-workspace
|
||||
|
||||
# IDE - VSCode
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
4
graphql/.prettierrc
Normal file
4
graphql/.prettierrc
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"singleQuote": true,
|
||||
"trailingComma": "all"
|
||||
}
|
||||
8
graphql/Dockerfile
Normal file
8
graphql/Dockerfile
Normal file
@@ -0,0 +1,8 @@
|
||||
FROM node:16.19.0-alpine3.17
|
||||
WORKDIR /user/src/app
|
||||
COPY package*.json ./
|
||||
RUN npm install
|
||||
COPY . .
|
||||
RUN npm run build
|
||||
EXPOSE 8080
|
||||
CMD ["node", "dist/main"]
|
||||
73
graphql/README.md
Normal file
73
graphql/README.md
Normal file
@@ -0,0 +1,73 @@
|
||||
<p align="center">
|
||||
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="200" alt="Nest Logo" /></a>
|
||||
</p>
|
||||
|
||||
[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
|
||||
[circleci-url]: https://circleci.com/gh/nestjs/nest
|
||||
|
||||
<p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
|
||||
<p align="center">
|
||||
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
|
||||
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
|
||||
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
|
||||
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
|
||||
<a href="https://coveralls.io/github/nestjs/nest?branch=master" target="_blank"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9" alt="Coverage" /></a>
|
||||
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
|
||||
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
|
||||
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
|
||||
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg"/></a>
|
||||
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
|
||||
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a>
|
||||
</p>
|
||||
<!--[](https://opencollective.com/nest#backer)
|
||||
[](https://opencollective.com/nest#sponsor)-->
|
||||
|
||||
## Description
|
||||
|
||||
[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
$ npm install
|
||||
```
|
||||
|
||||
## Running the app
|
||||
|
||||
```bash
|
||||
# development
|
||||
$ npm run start
|
||||
|
||||
# watch mode
|
||||
$ npm run start:dev
|
||||
|
||||
# production mode
|
||||
$ npm run start:prod
|
||||
```
|
||||
|
||||
## Test
|
||||
|
||||
```bash
|
||||
# unit tests
|
||||
$ npm run test
|
||||
|
||||
# e2e tests
|
||||
$ npm run test:e2e
|
||||
|
||||
# test coverage
|
||||
$ npm run test:cov
|
||||
```
|
||||
|
||||
## Support
|
||||
|
||||
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).
|
||||
|
||||
## Stay in touch
|
||||
|
||||
- Author - [Kamil Myśliwiec](https://kamilmysliwiec.com)
|
||||
- Website - [https://nestjs.com](https://nestjs.com/)
|
||||
- Twitter - [@nestframework](https://twitter.com/nestframework)
|
||||
|
||||
## License
|
||||
|
||||
Nest is [MIT licensed](LICENSE).
|
||||
8
graphql/nest-cli.json
Normal file
8
graphql/nest-cli.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/nest-cli",
|
||||
"collection": "@nestjs/schematics",
|
||||
"sourceRoot": "src",
|
||||
"compilerOptions": {
|
||||
"deleteOutDir": true
|
||||
}
|
||||
}
|
||||
16739
graphql/package-lock.json
generated
Normal file
16739
graphql/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
77
graphql/package.json
Normal file
77
graphql/package.json
Normal file
@@ -0,0 +1,77 @@
|
||||
{
|
||||
"name": "graphql",
|
||||
"version": "0.0.1",
|
||||
"description": "",
|
||||
"author": "",
|
||||
"private": true,
|
||||
"license": "UNLICENSED",
|
||||
"scripts": {
|
||||
"build": "nest build",
|
||||
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
||||
"start": "nest start",
|
||||
"start:dev": "nest start --watch",
|
||||
"start:debug": "nest start --debug --watch",
|
||||
"start:prod": "node dist/main",
|
||||
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
||||
"test": "jest",
|
||||
"test:watch": "jest --watch",
|
||||
"test:cov": "jest --coverage",
|
||||
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
||||
"test:e2e": "jest --config ./test/jest-e2e.json"
|
||||
},
|
||||
"dependencies": {
|
||||
"@nestjs/apollo": "^10.1.7",
|
||||
"@nestjs/axios": "^1.0.1",
|
||||
"@nestjs/common": "^9.0.0",
|
||||
"@nestjs/core": "^9.0.0",
|
||||
"@nestjs/platform-express": "^9.0.0",
|
||||
"axios": "^1.3.1",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rxjs": "^7.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nestjs/cli": "^9.0.0",
|
||||
"@nestjs/graphql": "^10.1.7",
|
||||
"@nestjs/schematics": "^9.0.0",
|
||||
"@nestjs/testing": "^9.0.0",
|
||||
"@types/express": "^4.17.13",
|
||||
"@types/jest": "29.2.4",
|
||||
"@types/node": "18.11.18",
|
||||
"@types/supertest": "^2.0.11",
|
||||
"@typescript-eslint/eslint-plugin": "^5.0.0",
|
||||
"@typescript-eslint/parser": "^5.0.0",
|
||||
"apollo-server-express": "^3.11.1",
|
||||
"eslint": "^8.0.1",
|
||||
"eslint-config-prettier": "^8.3.0",
|
||||
"eslint-plugin-prettier": "^4.0.0",
|
||||
"graphql": "^16.6.0",
|
||||
"graphql-tools": "^8.3.17",
|
||||
"jest": "29.3.1",
|
||||
"prettier": "^2.3.2",
|
||||
"source-map-support": "^0.5.20",
|
||||
"supertest": "^6.1.3",
|
||||
"ts-jest": "29.0.3",
|
||||
"ts-loader": "^9.2.3",
|
||||
"ts-morph": "^17.0.1",
|
||||
"ts-node": "^10.0.0",
|
||||
"tsconfig-paths": "4.1.1",
|
||||
"typescript": "^4.7.4"
|
||||
},
|
||||
"jest": {
|
||||
"moduleFileExtensions": [
|
||||
"js",
|
||||
"json",
|
||||
"ts"
|
||||
],
|
||||
"rootDir": "src",
|
||||
"testRegex": ".*\\.spec\\.ts$",
|
||||
"transform": {
|
||||
"^.+\\.(t|j)s$": "ts-jest"
|
||||
},
|
||||
"collectCoverageFrom": [
|
||||
"**/*.(t|j)s"
|
||||
],
|
||||
"coverageDirectory": "../coverage",
|
||||
"testEnvironment": "node"
|
||||
}
|
||||
}
|
||||
22
graphql/src/app.controller.spec.ts
Normal file
22
graphql/src/app.controller.spec.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
|
||||
describe('AppController', () => {
|
||||
let appController: AppController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const app: TestingModule = await Test.createTestingModule({
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
}).compile();
|
||||
|
||||
appController = app.get<AppController>(AppController);
|
||||
});
|
||||
|
||||
describe('root', () => {
|
||||
it('should return "Hello World!"', () => {
|
||||
expect(appController.getHello()).toBe('Hello World!');
|
||||
});
|
||||
});
|
||||
});
|
||||
12
graphql/src/app.controller.ts
Normal file
12
graphql/src/app.controller.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
import { AppService } from './app.service';
|
||||
|
||||
@Controller()
|
||||
export class AppController {
|
||||
constructor(private readonly appService: AppService) {}
|
||||
|
||||
@Get()
|
||||
getHello(): string {
|
||||
return this.appService.getHello();
|
||||
}
|
||||
}
|
||||
17
graphql/src/app.module.ts
Normal file
17
graphql/src/app.module.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { GraphQLModule } from '@nestjs/graphql';
|
||||
import { TeamModule } from './teams/team.module';
|
||||
import { VenueModule } from './venues/venue.module';
|
||||
import { ApolloDriver, ApolloDriverConfig } from '@nestjs/apollo'
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
GraphQLModule.forRoot<ApolloDriverConfig>({
|
||||
typePaths: ['./**/*.graphql'],
|
||||
driver: ApolloDriver
|
||||
}),
|
||||
TeamModule,
|
||||
VenueModule,
|
||||
],
|
||||
})
|
||||
export class AppModule {}
|
||||
8
graphql/src/app.service.ts
Normal file
8
graphql/src/app.service.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class AppService {
|
||||
getHello(): string {
|
||||
return 'Hello World!';
|
||||
}
|
||||
}
|
||||
10
graphql/src/generate-typings.js
Normal file
10
graphql/src/generate-typings.js
Normal file
@@ -0,0 +1,10 @@
|
||||
"use strict";
|
||||
exports.__esModule = true;
|
||||
var graphql_1 = require("@nestjs/graphql");
|
||||
var path_1 = require("path");
|
||||
var definitionsFactory = new graphql_1.GraphQLDefinitionsFactory();
|
||||
definitionsFactory.generate({
|
||||
typePaths: ['./src/**/*.graphql'],
|
||||
path: (0, path_1.join)(process.cwd(), 'src/graphql.ts'),
|
||||
outputAs: 'class'
|
||||
});
|
||||
10
graphql/src/generate-typings.ts
Normal file
10
graphql/src/generate-typings.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { GraphQLDefinitionsFactory } from '@nestjs/graphql';
|
||||
import { join } from 'path';
|
||||
|
||||
const definitionsFactory = new GraphQLDefinitionsFactory();
|
||||
|
||||
definitionsFactory.generate({
|
||||
typePaths: ['./src/**/*.graphql'],
|
||||
path: join(process.cwd(), 'src/graphql.ts'),
|
||||
outputAs: 'class'
|
||||
})
|
||||
88
graphql/src/graphql.ts
Normal file
88
graphql/src/graphql.ts
Normal file
@@ -0,0 +1,88 @@
|
||||
|
||||
/*
|
||||
* -------------------------------------------------------
|
||||
* THIS FILE WAS AUTOMATICALLY GENERATED (DO NOT MODIFY)
|
||||
* -------------------------------------------------------
|
||||
*/
|
||||
|
||||
/* tslint:disable */
|
||||
/* eslint-disable */
|
||||
|
||||
export class Team {
|
||||
id?: Nullable<string>;
|
||||
name?: Nullable<string>;
|
||||
abbreviation?: Nullable<string>;
|
||||
active?: Nullable<string>;
|
||||
allStarStatus?: Nullable<string>;
|
||||
clubName?: Nullable<string>;
|
||||
divisionId?: Nullable<number>;
|
||||
fileCode?: Nullable<string>;
|
||||
firstYearOfPlay?: Nullable<number>;
|
||||
franchiseName?: Nullable<string>;
|
||||
leagueId?: Nullable<number>;
|
||||
link?: Nullable<string>;
|
||||
locationName?: Nullable<string>;
|
||||
season?: Nullable<string>;
|
||||
shortName?: Nullable<string>;
|
||||
springLeagueId?: Nullable<number>;
|
||||
springVenueId?: Nullable<number>;
|
||||
sportId?: Nullable<number>;
|
||||
teamCode?: Nullable<string>;
|
||||
teamName?: Nullable<string>;
|
||||
venueId?: Nullable<number>;
|
||||
}
|
||||
|
||||
export class TeamsPagedResponse {
|
||||
currentPage?: Nullable<number>;
|
||||
errors?: Nullable<string>;
|
||||
message?: Nullable<string>;
|
||||
pageSize?: Nullable<number>;
|
||||
results?: Nullable<Nullable<Team>[]>;
|
||||
succeeded?: Nullable<boolean>;
|
||||
totalItemCount?: Nullable<number>;
|
||||
totalPageCount?: Nullable<number>;
|
||||
}
|
||||
|
||||
export class TeamResponse {
|
||||
errors?: Nullable<string>;
|
||||
message?: Nullable<string>;
|
||||
results: Team;
|
||||
succeeded: boolean;
|
||||
}
|
||||
|
||||
export abstract class IQuery {
|
||||
abstract teams(pageNumber: number, pageSize: number): TeamsPagedResponse | Promise<TeamsPagedResponse>;
|
||||
|
||||
abstract teamById(id: number): TeamResponse | Promise<TeamResponse>;
|
||||
|
||||
abstract venues(pageNumber: number, pageSize: number): VenuesPagedResponse | Promise<VenuesPagedResponse>;
|
||||
|
||||
abstract venueById(id: number): VenueResponse | Promise<VenueResponse>;
|
||||
}
|
||||
|
||||
export class Venue {
|
||||
active: string;
|
||||
id: number;
|
||||
link: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export class VenuesPagedResponse {
|
||||
currentPage: number;
|
||||
errors?: Nullable<string>;
|
||||
message?: Nullable<string>;
|
||||
pageSize: number;
|
||||
results: Nullable<Venue>[];
|
||||
succeeded: boolean;
|
||||
totalItemCount: number;
|
||||
totalPageCount: number;
|
||||
}
|
||||
|
||||
export class VenueResponse {
|
||||
errors?: Nullable<string>;
|
||||
message?: Nullable<string>;
|
||||
results: Venue;
|
||||
succeeded: boolean;
|
||||
}
|
||||
|
||||
type Nullable<T> = T | null;
|
||||
8
graphql/src/main.ts
Normal file
8
graphql/src/main.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { AppModule } from './app.module';
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule);
|
||||
await app.listen(8081);
|
||||
}
|
||||
bootstrap();
|
||||
54
graphql/src/teams/schema.graphql
Normal file
54
graphql/src/teams/schema.graphql
Normal file
@@ -0,0 +1,54 @@
|
||||
type Team {
|
||||
id: String
|
||||
name: String
|
||||
abbreviation: String
|
||||
active: String
|
||||
allStarStatus: String
|
||||
clubName: String
|
||||
divisionId: Int
|
||||
fileCode: String
|
||||
firstYearOfPlay: Int
|
||||
franchiseName: String
|
||||
leagueId: Int
|
||||
link: String
|
||||
locationName: String
|
||||
season: String
|
||||
shortName: String
|
||||
springLeagueId: Int
|
||||
springVenueId: Int
|
||||
sportId: Int
|
||||
teamCode: String
|
||||
teamName: String
|
||||
venueId: Int
|
||||
}
|
||||
|
||||
type TeamsPagedResponse {
|
||||
currentPage: Int
|
||||
errors: String
|
||||
message: String
|
||||
pageSize: Int
|
||||
results: [Team]
|
||||
succeeded: Boolean
|
||||
totalItemCount: Int
|
||||
totalPageCount: Int
|
||||
}
|
||||
|
||||
type TeamResponse {
|
||||
errors: String
|
||||
message: String
|
||||
results: Team!
|
||||
succeeded: Boolean!
|
||||
}
|
||||
|
||||
type Query {
|
||||
teams(
|
||||
pageNumber: Int!
|
||||
pageSize: Int!
|
||||
): TeamsPagedResponse!
|
||||
}
|
||||
|
||||
type Query {
|
||||
teamById(
|
||||
id: Int!
|
||||
): TeamResponse!
|
||||
}
|
||||
11
graphql/src/teams/team.module.ts
Normal file
11
graphql/src/teams/team.module.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { HttpModule } from '@nestjs/axios';
|
||||
import { TeamResolvers } from './team.resolvers';
|
||||
import { TeamService } from './team.service';
|
||||
|
||||
@Module({
|
||||
imports: [HttpModule],
|
||||
providers: [TeamService, TeamResolvers]
|
||||
})
|
||||
|
||||
export class TeamModule {}
|
||||
18
graphql/src/teams/team.resolvers.ts
Normal file
18
graphql/src/teams/team.resolvers.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { Args, Resolver, Query } from '@nestjs/graphql';
|
||||
import { TeamService } from './team.service';
|
||||
import { Team } from '../graphql';
|
||||
|
||||
@Resolver('Team')
|
||||
export class TeamResolvers {
|
||||
constructor (private readonly teamService: TeamService) {}
|
||||
|
||||
@Query()
|
||||
async teams(@Args('pageNumber') pageNumber: number, @Args('pageSize') pageSize: number): Promise<Team[]>{
|
||||
return this.teamService.findAll(pageNumber, pageSize);
|
||||
}
|
||||
|
||||
@Query()
|
||||
async teamById(@Args('id') id: number): Promise<Team> {
|
||||
return this.teamService.findById(id);
|
||||
}
|
||||
}
|
||||
23
graphql/src/teams/team.service.ts
Normal file
23
graphql/src/teams/team.service.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { HttpService } from '@nestjs/axios';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Team } from 'src/graphql';
|
||||
import { AxiosResponse } from 'axios';
|
||||
|
||||
@Injectable()
|
||||
export class TeamService {
|
||||
constructor (private readonly httpService: HttpService) {}
|
||||
|
||||
private readonly teams: Team[] = [];
|
||||
|
||||
async findAll(pageNumber: number, pageSize: number): Promise<Team[]> {
|
||||
const response: AxiosResponse = await this.httpService.axiosRef.get(`http://localhost:5520/api/teams?pageNumber=${pageNumber}&pageSize=${pageSize}`);
|
||||
|
||||
return response.data;
|
||||
}
|
||||
|
||||
async findById(id: number): Promise<Team> {
|
||||
const response: AxiosResponse = await this.httpService.axiosRef.get(`http://localhost:5520/api/teams/${id}`);
|
||||
|
||||
return response.data
|
||||
}
|
||||
}
|
||||
37
graphql/src/venues/schema.graphql
Normal file
37
graphql/src/venues/schema.graphql
Normal file
@@ -0,0 +1,37 @@
|
||||
type Venue {
|
||||
active: String!
|
||||
id: Int!
|
||||
link: String!
|
||||
name: String!
|
||||
}
|
||||
|
||||
type VenuesPagedResponse {
|
||||
currentPage: Int!
|
||||
errors: String
|
||||
message: String
|
||||
pageSize: Int!
|
||||
results: [Venue]!
|
||||
succeeded: Boolean!
|
||||
totalItemCount: Int!
|
||||
totalPageCount: Int!
|
||||
}
|
||||
|
||||
type VenueResponse {
|
||||
errors: String
|
||||
message: String
|
||||
results: Venue!
|
||||
succeeded: Boolean!
|
||||
}
|
||||
|
||||
type Query {
|
||||
venues(
|
||||
pageNumber: Int!
|
||||
pageSize: Int!
|
||||
): VenuesPagedResponse!
|
||||
}
|
||||
|
||||
type Query {
|
||||
venueById(
|
||||
id: Int!
|
||||
): VenueResponse!
|
||||
}
|
||||
11
graphql/src/venues/venue.module.ts
Normal file
11
graphql/src/venues/venue.module.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { Module } from "@nestjs/common";
|
||||
import { HttpModule } from '@nestjs/axios';
|
||||
import { VenueResolvers } from './venue.resolvers';
|
||||
import { VenueService } from './venue.service';
|
||||
|
||||
@Module({
|
||||
imports: [HttpModule],
|
||||
providers: [VenueService, VenueResolvers]
|
||||
})
|
||||
|
||||
export class VenueModule {}
|
||||
18
graphql/src/venues/venue.resolvers.ts
Normal file
18
graphql/src/venues/venue.resolvers.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { Resolver, Query, Args } from "@nestjs/graphql";
|
||||
import { VenueService } from "./venue.service";
|
||||
import { Venue } from '../graphql';
|
||||
|
||||
@Resolver('Venue')
|
||||
export class VenueResolvers {
|
||||
constructor (private readonly venueService: VenueService) {}
|
||||
|
||||
@Query()
|
||||
async venues(@Args('pageNumber') pageNumber: number, @Args('pageSize') pageSize: number): Promise<Venue[]> {
|
||||
return this.venueService.findAll(pageNumber, pageSize);
|
||||
}
|
||||
|
||||
@Query()
|
||||
async venueById(@Args('id') id: number): Promise<Venue> {
|
||||
return this.venueService.findById(id);
|
||||
}
|
||||
}
|
||||
23
graphql/src/venues/venue.service.ts
Normal file
23
graphql/src/venues/venue.service.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { HttpService } from "@nestjs/axios";
|
||||
import { Injectable } from "@nestjs/common";
|
||||
import { Venue } from '../graphql';
|
||||
import { AxiosResponse } from 'axios';
|
||||
|
||||
@Injectable()
|
||||
export class VenueService {
|
||||
constructor (private readonly httpService: HttpService) {}
|
||||
|
||||
private readonly venues: Venue[] = [];
|
||||
|
||||
async findAll(pageNumber: number, pageSize: number): Promise<Venue[]> {
|
||||
const response: AxiosResponse = await this.httpService.axiosRef.get(`http://localhost:5510/api/venues?pageNumber=${pageNumber}&pageSize=${pageSize}`);
|
||||
|
||||
return response.data;
|
||||
}
|
||||
|
||||
async findById(id: number): Promise<Venue> {
|
||||
const response: AxiosResponse = await this.httpService.axiosRef.get(`http://localhost:5510/api/venues/${id}`);
|
||||
|
||||
return response.data;
|
||||
}
|
||||
}
|
||||
24
graphql/test/app.e2e-spec.ts
Normal file
24
graphql/test/app.e2e-spec.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { INestApplication } from '@nestjs/common';
|
||||
import * as request from 'supertest';
|
||||
import { AppModule } from './../src/app.module';
|
||||
|
||||
describe('AppController (e2e)', () => {
|
||||
let app: INestApplication;
|
||||
|
||||
beforeEach(async () => {
|
||||
const moduleFixture: TestingModule = await Test.createTestingModule({
|
||||
imports: [AppModule],
|
||||
}).compile();
|
||||
|
||||
app = moduleFixture.createNestApplication();
|
||||
await app.init();
|
||||
});
|
||||
|
||||
it('/ (GET)', () => {
|
||||
return request(app.getHttpServer())
|
||||
.get('/')
|
||||
.expect(200)
|
||||
.expect('Hello World!');
|
||||
});
|
||||
});
|
||||
9
graphql/test/jest-e2e.json
Normal file
9
graphql/test/jest-e2e.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"moduleFileExtensions": ["js", "json", "ts"],
|
||||
"rootDir": ".",
|
||||
"testEnvironment": "node",
|
||||
"testRegex": ".e2e-spec.ts$",
|
||||
"transform": {
|
||||
"^.+\\.(t|j)s$": "ts-jest"
|
||||
}
|
||||
}
|
||||
4
graphql/tsconfig.build.json
Normal file
4
graphql/tsconfig.build.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"exclude": ["node_modules", "test", "dist", "**/*spec.ts"]
|
||||
}
|
||||
21
graphql/tsconfig.json
Normal file
21
graphql/tsconfig.json
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"removeComments": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"target": "es2017",
|
||||
"sourceMap": true,
|
||||
"outDir": "./dist",
|
||||
"baseUrl": "./",
|
||||
"incremental": true,
|
||||
"skipLibCheck": true,
|
||||
"strictNullChecks": false,
|
||||
"noImplicitAny": false,
|
||||
"strictBindCallApply": false,
|
||||
"forceConsistentCasingInFileNames": false,
|
||||
"noFallthroughCasesInSwitch": false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user