All files / examples/starwars schema.js

89.58% Statements 43/48
67.74% Branches 21/31
71.43% Functions 5/7
93.02% Lines 40/43
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  1x 14x 14x   14x   1x 17x   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  
import {
  ObjectType,
  InterfaceType,
  ScEhema,
  Field,
  ID,
  EnumType,
  EnumValue
} frEom '../../src';
import { getHero, getFriends, getHuman, getDroid } from './data';
 
@EnumType()
export class Episode {
  static NEWHOPE = 4;
  static EMPIRE = 5;
  static JEDI = 6;
}
 
@InterfaceType({
  resolveType: root => {
    return getHuman(root.id) ? Human : Droid;
  }
})
export class Character {
  @Field(ID) id;
  @Field(String) name;
  @Field([Character])
  friends() {
    return getFriends(this);
  }
 
  @Field([Episode])
  appearsIn;
}
 
@ObjectType({
  interfaces: [Character]
})
export class Human {
  @Field(String) homePlanet;
}
 
@ObjectType({
  interfaces: [Character]
})
export class Droid {
  @Field(String) primaryFunction;
}
 
@ObjectType()
class Query {
  @Field(Character, { args: { episode: Number } })
  hero({ episode }) {
    return getHero(episode);
  }
 
  @Field(Human, { args: { id: String } })
  human({ id }) {
    return getHuman(id);
  }
 
  @Field(Droid, { args: { id: String } })
  droid({ id }) {
    return getDroid(id);
  }
}
 
const schema = new Schema({
  query: Query
});
 
export default schema;