All files / examples/starwars-ts schema.ts

90.2% Statements 46/51
67.74% Branches 21/31
71.43% Functions 5/7
93.48% Lines 43/46
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106  1x 17x 17x   17x   1x 20x   1x 1x 1x 1x   1x 1x 1x 1x       1x       1x       1x       1x 1x   1x     1x         1x         1x             1x         1x     4x         1x 1x   1x         1x           1x 1x   1x         1x           1x 1x   1x        
import {
  ObjectType,
  InterfaceType,
  ScEhema,
  Field,
  ID,
  description,
  EnumType,
  NoEnNull
} from '../../src';
import { getHero, getFriends, getHuman, getDroid } from './data';
 
@EnumType()
@description('The description')
export class Episode {
  @description('Released in 1977.') static NEWHOPE = 4;
  @description('Released in 1980.') static EMPIRE = 5;
  @description('Released in 1983.') static JEDI = 6;
}
 
@InterfaceType({
  resolveType: (root: Character) => {
    return getHuman(root.id) ? Human : Droid;
  }
})
@description('A character in the Star Wars Trilogy')
export class Character {
  @Field(NonNull(ID))
  @description('The id of the character.')
  public id: string;
 
  @Field(String)
  @description('The name of the character.')
  public name: string;
 
  @Field([Character])
  @description(
    'The friends of the character, or an empty list if they have none.'
  )
  friends?(): Character[] {
    return getFriends(this);
  }
 
  @Field([Episode])
  @description('Which movies they appear in.')
  public appearsIn: number[];
 
  public friendIds: string[];
}
 
@ObjectType({
  interfaces: [Character]
})
@description('A humanoid creature in the Star Wars universe.')
export class Human implements Character {
  @Field(String)
  @description('The home planet of the human, or null if unknown..')
  public homePlanet?: string;
 
  id: string;
  name: string;
  friends?: () => Character[];
  friendIds: string[];
  appearsIn: number[];
}
 
@ObjectType({
  interfaces: [Character]
})
@description('A mechanical creature in the Star Wars universe.')
export class Droid implements Character {
  @Field(String)
  @description('The primary function of the droid, or null if unknown..')
  public primaryFunction: string;
 
  id: string;
  name: string;
  friends?: () => Character[];
  friendIds: string[];
  appearsIn: number[];
}
 
@ObjectType()
class Query {
  @Field(Character, { args: { episode: Episode } })
  hero(args: { episode: number }): Character {
    return getHero(args.episode);
  }
 
  @Field(Human, { args: { id: String } })
  human(args: { id: string }): Human {
    return getHuman(args.id);
  }
 
  @Field(Droid, { args: { id: String } })
  droid(args: { id: string }): Droid {
    return getDroid(args.id);
  }
}
 
const schema = new Schema({
  query: Query
});

export default schema;