【发布时间】:2019-07-12 05:34:09
【问题描述】:
在我的解析器中,我似乎无法获取连接的数据
这在 graphql 游乐场 (prisma) 中有效,但我不确定如何在 apollo 服务器中形成解析器的语法
// my typedef for activity is
type Activity {
id: ID! @id
ActivityType: ActivityType!
title: String!
date: DateTime
user: User!
distance: Float!
distance_unit: Unit!
duration: Float!
elevation: Float
elevation_unit: Unit
createdAt: DateTime! @createdAt
updatedAt: DateTime! @updatedAt
// and my resolver currently looks like this
async activity(parent, args, ctx, info) {
const foundActivity = await ctx.db.query.activity({
where: {
id: args.id
}
});
// todo fetch user data from query
console.log(foundActivity);
}
// where db has been placed onto the ctx (context)
// the CL gives all of the data for Activity apart from the user
// in the playground I would do something like this
query activity {
activity(where: {
id: "cjxxow7c8si4o0b5314f9ibek"
}){
title
user {
id
name
}
}
}
// but I do not know how to specify what is returned in my resolver.
console.log(foundActivity) gives:
{ id: 'cjxxpuh1bsq750b53psd2c77d',
ActivityType: 'CYCLING',
title: 'Test Activity',
date: '2019-07-10T20:21:27.681Z',
distance: 13.4,
distance_unit: 'KM',
duration: 90030,
elevation: 930,
elevation_unit: 'METERS',
createdAt: '2019-07-10T20:48:50.879Z',
updatedAt: '2019-07-10T20:48:50.879Z' }
Prisma 是 DB ORM,然后我有一个 Apollo-Server 2 服务器在其上运行。不幸的是,堆栈溢出也认为这篇文章中的代码太多,所以我将不得不讨论一些无关紧要的乱码,因为他们的系统无法处理它。
【问题讨论】:
标签: graphql apollo-server