Skip to content

Commit

Permalink
feat(be): graphql resolvers
Browse files Browse the repository at this point in the history
  • Loading branch information
krystxf committed Oct 6, 2024
1 parent 6069568 commit e08e40c
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 2 deletions.
45 changes: 45 additions & 0 deletions backend-nest/schema.gql
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# ------------------------------------------------------
# THIS FILE WAS AUTOMATICALLY GENERATED (DO NOT MODIFY)
# ------------------------------------------------------

"""route"""
type Route {
id: ID!
name: String!
}

"""platform"""
type Platform {
id: ID!
name: String!
latitude: Float!
longitude: Float!
routes: [Route!]!
}

"""stop"""
type Stop {
id: ID!
name: String!
avgLatitude: Float!
avgLongitude: Float!
platforms: [Platform!]!
}

type Query {
"""Get all platforms"""
platform(
"""
if set to `true` returns only metro results, otherwise returns all results (including metro). Defaults to `false`.
"""
metroOnly: Boolean = false
): [Platform!]!

"""Get all stops"""
stop(
"""
if set to `true` returns only metro results, otherwise returns all results (including metro). Defaults to `false`.
"""
metroOnly: Boolean = false
): [Stop!]!
}
3 changes: 2 additions & 1 deletion backend-nest/src/modules/platform/platform.module.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Module } from "@nestjs/common";

import { PlatformController } from "src/modules/platform/platform.controller";
import { PlatformResolver } from "src/modules/platform/platform.resolver";
import { PlatformService } from "src/modules/platform/platform.service";

@Module({
controllers: [PlatformController],
providers: [PlatformService],
providers: [PlatformResolver, PlatformService],
imports: [],
})
export class PlatformModule {}
25 changes: 25 additions & 0 deletions backend-nest/src/modules/platform/platform.resolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Args, Query, Resolver } from "@nestjs/graphql";

import { Platform } from "src/models/platform.model";
import { PlatformService } from "src/modules/platform/platform.service";
import { metroOnlyQuery } from "src/swagger/query.swagger";

@Resolver(() => Platform)
export class PlatformResolver {
constructor(private readonly platformService: PlatformService) {}

@Query(() => [Platform], {
description: "Get all platforms",
})
async platform(
@Args("metroOnly", {
description: metroOnlyQuery.description,
defaultValue: false,
nullable: true,
type: () => Boolean,
})
metroOnly,
): Promise<Platform[]> {
return await this.platformService.getAllPlatforms({ metroOnly });
}
}
3 changes: 2 additions & 1 deletion backend-nest/src/modules/stop/stop.module.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Module } from "@nestjs/common";

import { StopController } from "src/modules/stop/stop.controller";
import { StopResolver } from "src/modules/stop/stop.resolver";
import { StopService } from "src/modules/stop/stop.service";

@Module({
controllers: [StopController],
providers: [StopService],
providers: [StopResolver, StopService],
imports: [],
})
export class StopModule {}
25 changes: 25 additions & 0 deletions backend-nest/src/modules/stop/stop.resolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Args, Query, Resolver } from "@nestjs/graphql";

import { Stop } from "src/models/stop.model";
import { StopService } from "src/modules/stop/stop.service";
import { metroOnlyQuery } from "src/swagger/query.swagger";

@Resolver(() => Stop)
export class StopResolver {
constructor(private readonly stopSerice: StopService) {}

@Query(() => [Stop], {
description: "Get all stops",
})
async stop(
@Args("metroOnly", {
description: metroOnlyQuery.description,
defaultValue: false,
nullable: true,
type: () => Boolean,
})
metroOnly,
): Promise<Stop[]> {
return await this.stopSerice.getAll({ metroOnly });
}
}

0 comments on commit e08e40c

Please sign in to comment.