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

Commit

Permalink
fix: fixes parsing errors (#7)
Browse files Browse the repository at this point in the history
* fix: fixes parsing errors

Fixes several parsing errors and changes the type of episodeId to float

fix #6

* Update src/structures/Vehicle.ts

Co-authored-by: Jeroen Claassens <[email protected]>

* fix(unit tests): changed types of unit tests according to changes made before

* Update getFilm.test.ts

Co-authored-by: Jeroen Claassens <[email protected]>
  • Loading branch information
thehairy and favna authored Jul 15, 2021
1 parent 61d0d03 commit f741bf4
Show file tree
Hide file tree
Showing 10 changed files with 7,991 additions and 7,820 deletions.
2 changes: 1 addition & 1 deletion __tests__/scenarios/films/getFilm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ describe('getFilm', () => {

expect(data.errors).toHaveLength(1);
expect(data.errors[0].message).toBe(
'Variable "$film" got invalid value "totally_invalid_film"; Int cannot represent non-integer value: "totally_invalid_film"'
'Variable "$film" got invalid value "totally_invalid_film"; Float cannot represent non numeric value: "totally_invalid_film"'
);
});
});
Expand Down
4 changes: 2 additions & 2 deletions __tests__/testUtils/queries/films.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const TitleOnlyFragment = gql`

export const getFilmTitle = gql`
${TitleOnlyFragment}
query ($film: Int!) {
query ($film: Float!) {
getFilm(film: $film) {
...titleOnlyFilmData
}
Expand All @@ -38,7 +38,7 @@ export const getFilmTitle = gql`

export const getFilmWithNested = gql`
${FullDataFragment}
query ($film: Int!) {
query ($film: Float!) {
getFilm(film: $film) {
...FullDataFragment
}
Expand Down
6 changes: 3 additions & 3 deletions __tests__/testUtils/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export declare type Film = {
/** The director of this film */
readonly director: Scalars['String'];
/** The episode number of this film */
readonly episodeId: Scalars['Int'];
readonly episodeId: Scalars['Float'];
/** The opening crawl text for this film */
readonly openingCrawl: Scalars['String'];
/** The planets that appeared in this film */
Expand Down Expand Up @@ -78,7 +78,7 @@ export declare type Person = {
/** The planet that this person was born on */
readonly homeworld?: Maybe<Planet>;
/** The mass of this person in kilograms when applying standard gravity */
readonly mass?: Maybe<Scalars['Int']>;
readonly mass?: Maybe<Scalars['Float']>;
/** The name of this person */
readonly name: Scalars['String'];
/** The colours of the skin of this person */
Expand Down Expand Up @@ -112,7 +112,7 @@ export declare type Planet = {
/** The number of standard hours this planet takes to rotate around its own axis. Nullable if the rotation period is unknown for this planet */
readonly rotationPeriod?: Maybe<Scalars['Int']>;
/** The percentage of the planet that is naturally occurring water or bodies of water. Null if this is unknown for this planet. */
readonly surfaceWater?: Maybe<Scalars['Int']>;
readonly surfaceWater?: Maybe<Scalars['Float']>;
/** The types of terrain of this planet */
readonly terrains?: Maybe<ReadonlyArray<Scalars['String']>>;
};
Expand Down
4 changes: 2 additions & 2 deletions src/arguments/FilmsArgs.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { IsIn, IsNumber } from 'class-validator';
import { ArgsType, Field, Int } from 'type-graphql';
import { ArgsType, Field, Float } from 'type-graphql';

@ArgsType()
export default class FilmArgs {
@Field(() => Int, { description: 'The film to look up, referenced by episode number' })
@Field(() => Float, { description: 'The film to look up, referenced by episode number' })
@IsNumber()
@IsIn([1, 2, 3, 4, 5, 6])
public film!: number;
Expand Down
2 changes: 1 addition & 1 deletion src/services/FilmService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export default class FilmService {
}

public static findByFuzzy(@Args(() => FuzzyFilmArgs) { film, offset, reverse, take }: FuzzyFilmArgs): Fuse.FuseResult<StarWarsApi.Film>[] {
if (!Number(film)) {
if (!parseFloat(film)) {
film = preParseInput(film);
}

Expand Down
4 changes: 2 additions & 2 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, Int, ObjectType } from 'type-graphql';
import { Field, GraphQLISODateTime, Float, ObjectType } from 'type-graphql';

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

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

@Field(() => String, { description: 'The opening crawl text for this film' })
Expand Down
4 changes: 2 additions & 2 deletions src/structures/Person.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, Int, ObjectType } from 'type-graphql';
import { Field, Float, Int, ObjectType } from 'type-graphql';

@ObjectType({ description: 'A character that appeared in Star Wars' })
export default class Person {
Expand All @@ -28,7 +28,7 @@ export default class Person {
@Field(() => Planet, { nullable: true, description: 'The planet that this person was born on' })
public homeworld?: Planet | null;

@Field(() => Int, { nullable: true, description: 'The mass of this person in kilograms when applying standard gravity' })
@Field(() => Float, { nullable: true, description: 'The mass of this person in kilograms when applying standard gravity' })
public mass?: number | null;

@Field(() => String, { description: 'The name of this person' })
Expand Down
2 changes: 1 addition & 1 deletion src/structures/Planet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default class Planet {
})
public rotationPeriod?: number | null;

@Field(() => Int, {
@Field(() => Float, {
nullable: true,
description: 'The percentage of the planet that is naturally occurring water or bodies of water. Null if this is unknown for this planet.'
})
Expand Down
7 changes: 5 additions & 2 deletions src/structures/Vehicle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import { Field, Float, Int, ObjectType } from 'type-graphql';

@ObjectType({ description: 'A vehicle that appeared in Star Wars' })
export default class Vehicle {
@Field(() => Int, { description: 'The maximum cargo capacity of this vehicle in kilograms' })
public cargoCapacity!: number;
@Field(() => Int, {
nullable: true,
description: 'The maximum cargo capacity of this vehicle in kilograms'
})
public cargoCapacity?: number | null;

@Field(() => String, {
nullable: true,
Expand Down
Loading

0 comments on commit f741bf4

Please sign in to comment.