【发布时间】:2021-03-09 09:36:05
【问题描述】:
我有 SHIPS 的 schema.js
// Ships
const ShipType = new GraphQLObjectType({
name: "Ships",
fields: () => ({
ship_id: { type: GraphQLString },
ship_name: { type: GraphQLString },
home_port: { type: GraphQLString },
ship_type: { type: GraphQLString },
year_built: { type: GraphQLInt },
position: { type: ShipPositionType },
active: { type: GraphQLBoolean }
})
})
// Ship positions
const ShipPositionType = new GraphQLObjectType({
name: "ShipPositions",
fields: () => ({
latitude: { type: GraphQLFloat },
longitude: { type: GraphQLFloat }
})
});
在 ShipType 我添加了一个新字段“位置”,它将返回 ShipPositionType
这是我到目前为止返回的内容
// get ships
ships: {
type: new GraphQLList(ShipType),
resolve(parent, args) {
return axios.get('https://api.spacexdata.com/v3/ships')
.then(res => res.data);
}
}
【问题讨论】:
-
如果没有从 axios/ships 响应返回(可能不是),则需要额外的位置解析器
标签: axios graphql react-apollo apollo-client apollo-server