如何在Prisma中按计算值过滤

时间:2019-04-01 17:58:37

标签: node.js graphql prisma prisma-graphql

是否可以通过在二级解析器中添加的计算值来过滤graphql解析器中的结果数组?

我的类型如下(距离是计算得出的,未存储在db中):

type Place {
  # ...
  distance: Float!
  # ...
}

查询声明如下:

type Query {
  favoritePlaceList(latitude: Float!, longitude: Float!): [Place!]!
}

我的查询解析器如下所示:

async function favoritePlaceList(_, _, context, _) {
    const userId = getUserId(context);
    const user = await context.db.query.user(
        { where: { id: userId } },
        ` { favoritePlaceList { id name description location { latitude longitude } reviewList { value } } } `);

    return user.favoritePlaceList;
}

距离解析器是这个:

function distance(parent, _, _, info) {
    return calcDistanceFromGeolocations(
        parent.location.latitude,
        parent.location.longitude,
        info.operation.selectionSet.selections[0].arguments[0].value.value,
        info.operation.selectionSet.selections[0].arguments[1].value.value,
    );
}

(而且我也不知道如何在第二级处理程序中访问参数,这只是一个hack :()

0 个答案:

没有答案
相关问题