PokeMon datamodel

1
2
3
4
5
6
7
8
9
10
11
12
type Trainer {
id: String!
name: String!
ownedPokemons: [Pokemon] # 一个训练师有多个宠物
}

type Pokemon {
id: String!
url: String!
name: String!
trainer: Trainer # 一个宠物属于一个训练师
}

基础查询

1
2
3
4
5
6
7
8
9
10
11
12
13
const TrainerQuery = gql`
query TrainerQuery($name: String!) {
Trainer(name: $name) {
id
name
ownedPokemons {
id
name
url
}
}
}
`

ownedPokeMons是一个数组,可以用Trainer.ownedPokemons.length,获取到训练师所有的宠物的数量.

宠物详情查询

1
2
3
4
5
6
7
8
9
const PokemonQuery = gql`
query PokemonQuery($id: ID!) {
Pokemon(id: $id) {
id
url
name
}
}
`