Skip to content
This repository has been archived by the owner on Aug 28, 2022. It is now read-only.

Commit

Permalink
feat: setup basic film service
Browse files Browse the repository at this point in the history
  • Loading branch information
favna committed Jun 20, 2021
1 parent 3f483ae commit f15f209
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
12 changes: 6 additions & 6 deletions src/assets/films.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default new GraphQLCollection<number, StarWarsApi.Film>([
'people and restore\n' +
'freedom to the galaxy....',
planets: ['tatooine', 'alderaan', 'yaviniv'],
producer: ['Gary Kurtz', 'Rick McCallum'],
producers: ['Gary Kurtz', 'Rick McCallum'],
releaseDate: '1977-05-25T00:00:00.000Z',
species: ['human', 'droid', 'wookie', 'rodian', 'hutt'],
starships: [
Expand Down Expand Up @@ -113,7 +113,7 @@ export default new GraphQLCollection<number, StarWarsApi.Film>([
'thousands of remote probes into\n' +
'the far reaches of space....',
planets: ['hoth', 'dagobah', 'bespin', 'ordmantell'],
producer: ['Gary Kurtz', 'Rick McCallum'],
producers: ['Gary Kurtz', 'Rick McCallum'],
releaseDate: '1980-05-17T00:00:00.000Z',
species: ['human', 'droid', 'wookie', 'yodasspecies', 'trandoshan'],
starships: [
Expand Down Expand Up @@ -179,7 +179,7 @@ export default new GraphQLCollection<number, StarWarsApi.Film>([
'struggling to restore freedom\n' +
'to the galaxy...',
planets: ['tatooine', 'dagobah', 'endor', 'naboo', 'coruscant'],
producer: ['Howard G. Kazanjian', 'George Lucas', 'Rick McCallum'],
producers: ['Howard G. Kazanjian', 'George Lucas', 'Rick McCallum'],
releaseDate: '1983-05-25T00:00:00.000Z',
species: ['human', 'droid', 'wookie', 'hutt', 'yodasspecies', 'moncalamari', 'ewok', 'sullustan', 'twilek'],
starships: [
Expand Down Expand Up @@ -263,7 +263,7 @@ export default new GraphQLCollection<number, StarWarsApi.Film>([
'peace and justice in the\n' +
'galaxy, to settle the conflict....',
planets: ['tatooine', 'naboo', 'coruscant'],
producer: ['Rick McCallum'],
producers: ['Rick McCallum'],
releaseDate: '1999-05-19T00:00:00.000Z',
species: [
'human',
Expand Down Expand Up @@ -368,7 +368,7 @@ export default new GraphQLCollection<number, StarWarsApi.Film>([
'to assist the overwhelmed\n' +
'Jedi....',
planets: ['tatooine', 'naboo', 'coruscant', 'kamino', 'geonosis'],
producer: ['Rick McCallum'],
producers: ['Rick McCallum'],
releaseDate: '2002-05-16T00:00:00.000Z',
species: [
'human',
Expand Down Expand Up @@ -489,7 +489,7 @@ export default new GraphQLCollection<number, StarWarsApi.Film>([
'catoneimoidia',
'saleucami'
],
producer: ['Rick McCallum'],
producers: ['Rick McCallum'],
releaseDate: '2005-05-19T00:00:00.000Z',
species: [
'human',
Expand Down
12 changes: 12 additions & 0 deletions src/services/FilmService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,22 @@ export default class FilmService {
return films.get(film);
}

// TODO: add parameter to prevent deep-nesting
// TODO: ensure requestedFields supports deep-nesting
public mapFilmDataToFilmGraphQL(data: StarWarsApi.Film, requestedFields: GraphQLSet<keyof Film>): Film {
const film = new Film();

addPropertyToClass(film, 'characters', data.characters, requestedFields); // TODO: map to actual characters
addPropertyToClass(film, 'director', data.director, requestedFields);
addPropertyToClass(film, 'episodeId', data.episodeId, requestedFields);
addPropertyToClass(film, 'openingCrawl', data.openingCrawl, requestedFields);
addPropertyToClass(film, 'planets', data.planets, requestedFields); // TODO: map to actual planets
addPropertyToClass(film, 'producers', data.producers, requestedFields);
addPropertyToClass(film, 'releaseDate', new Date(data.releaseDate), requestedFields);
addPropertyToClass(film, 'species', data.species, requestedFields); // TODO: map to actual species
addPropertyToClass(film, 'starships', data.starships, requestedFields); // TODO: map to actual starships
addPropertyToClass(film, 'title', data.title, requestedFields);
addPropertyToClass(film, 'vehicles', data.vehicles, requestedFields); // TODO: map to actual vehicles

return film;
}
Expand Down
6 changes: 3 additions & 3 deletions src/structures/Film.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Planet from '#structures/Planet';
import Species from '#structures/Species';
import Starship from '#structures/Starship';
import Vehicle from '#structures/Vehicle';
import { Field, GraphQLISODateTime, ObjectType } from 'type-graphql';
import { Field, GraphQLISODateTime, Int, ObjectType } from 'type-graphql';

@ObjectType({ description: 'A Star Wars film' })
export default class Film {
Expand All @@ -13,8 +13,8 @@ export default class Film {
@Field(() => String, { description: 'The director of this film' })
public director!: string;

@Field(() => String, { description: 'The episode number of this film' })
public episodeId!: string;
@Field(() => Int, { description: 'The episode number of this film' })
public episodeId!: number;

@Field(() => String, { description: 'The opening crawl text for this film' })
public openingCrawl!: string;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/star-wars.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ declare namespace StarWarsApi {
episodeId: number;
openingCrawl: string;
planets: string[];
producer: string[];
producers: string[];
releaseDate: string;
species: string[];
starships: string[];
Expand Down

0 comments on commit f15f209

Please sign in to comment.