【发布时间】:2019-02-04 19:10:04
【问题描述】:
目前我将解析器用作 lambda 函数:
import boto3
from boto3.dynamodb.conditions import Key
def lambda_handler(event, context):
list = []
for device in event['source']['devices'] :
dynamodb = boto3.resource('dynamodb')
readings = dynamodb.Table('readings')
response = readings.query(
KeyConditionExpression=Key('device').eq(device['device'])
)
items = response['Items']
list.extend(items)
return list
我希望能够将它作为 dynamodb 上的 VTL 解析器。我的问题是我的表有一个排序键
这意味着我不能使用批处理解析器来查询一堆 id,因为我还需要提供排序键,并且我只想要主分区键的所有结果。
如何使用 VTL 查询一堆 id,基本上是在 VTL 中复制我的 lambda 函数。这甚至可能吗?
已添加架构,请原谅混乱,这是一项正在进行的工作并且正在尝试很多事情。对 graphQL 来说还是很新的
type Device {
id: String
device: String!
}
input DeviceInput {
id: String
device: String!
}
type DeviceReadings {
devices: [Device]
}
type Mutation {
createDevice(input: DeviceInput): Device
}
type PaginatedDevices {
devices: [Device]
readings: [Reading]
cows: [cow]
nextToken: String
}
type Query {
getAllUserDevices(nextToken: String, count: Int): PaginatedDevices
getAllDeviceReadings: DeviceReadings
getAllUserReadings: DeviceReadings
getAllReadings(deviceId: String!): Readings
getCowReadings(cowId: String!): UserCowReadings
}
type Reading {
device: String
time: Int
cow: Int
battery: String
}
type Readings {
items: [Reading]
}
type UserCowReadings {
devices: [Device]
readings: [Reading]
}
type cow {
id: Int
device: String
nait: String
}
schema {
query: Query
mutation: Mutation
}
【问题讨论】:
-
我可以向主分区键添加另一个索引键,以便我可以在索引设备键上运行批处理解析器。这将是一个中等写入数据库,因为一些物联网将写入它,我读到在高写入时创建索引是一个坏主意,输入?
-
你能提供你的 GraphQL 架构吗?
-
添加了,有点乱而且WIP
标签: amazon-web-services graphql aws-appsync resolver