从yml(或json)模板在AWS CloudFormation中创建资源时,是否可以在数组上进行迭代以使模板简短易读。例如,我有一个Appsync项目,在其中必须创建一堆几乎相同的AWS类型“ AWS :: AppSync :: Resolver”的解析器。在我用于Cloud Formation的YML模板中,1这样的资源可能看起来像这样
Resource:
GraphQlAddPostsResolver:
Type: "AWS::AppSync::Resolver"
DependsOn: GraphQlSchema
Properties:
ApiId:
Fn::GetAtt: [GraphQlApi, ApiId]
TypeName: Mutation #<---
FieldName: addPost #<----
DataSourceName:
Fn::GetAtt: [GraphQlLambdaDataSource, Name]
RequestMappingTemplate: |
{
"version" : "2017-02-28",
"operation": "Invoke",
"payload": {
"field": "addPost", #<---
"context": $util.toJson($context)
}
}
ResponseMappingTemplate: |
$util.toJson($context.result)
Run Code Online (Sandbox Code Playgroud)
我可能有十几个或更多这些解析器,唯一的区别是我用表示的地方<----。有什么办法可以遍历一组值,比如
- Field: addPost
Type: Mutation
- Field: allPosts
Type: Query
- Field: getPost
Type: Query
## etc...
Run Code Online (Sandbox Code Playgroud) yaml resolver amazon-web-services aws-cloudformation aws-appsync
我是 graphql 的新手。我使用 aws appsync 实现了一个 react-native 应用程序。以下是我在架构中编写的代码
type Messages {
id: ID!
createdAt: String!
updateAt: String!
text: String!
sendBy: Person!
@relation(name: "UserMessages")}
type Person {
id: ID!
createdAt: String!
updateAt: String!
name: String!
messages: [Messages!]!
@relation(name: "UserMessages")}
Run Code Online (Sandbox Code Playgroud)
当我尝试查询 sendBy 值时,它给了我一个错误说
query getMessages{
getMessages(id : "a0546b5d-1faf-444c-b243-fab5e1f47d2d") {
id
text
sendBy {
name
}
}
}
{
"data": {
"getMessages": null
},
"errors": [
{
"path": [
"getMessages",
"sendBy"
],
"locations": null,
"message": "Cannot return null for non-nullable type: 'Person' within …Run Code Online (Sandbox Code Playgroud) 在Lambda中,我想签署我的AppSync端点,aws-signature-v4以便将其用于突变.
生成的URL似乎没问题,但是当我尝试它时,它会给我以下错误:
{
"errors" : [ {
"errorType" : "InvalidSignatureException",
"message" : "The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details. etc...
} ]
}
这是我的lambda函数
import { Context, Callback } from 'aws-lambda';
import { GraphQLClient } from 'graphql-request';
const v4 = require('aws-signature-v4');
export async function handle(event: any, context: Context, callback: Callback) {
context.callbackWaitsForEmptyEventLoop = false;
const …Run Code Online (Sandbox Code Playgroud) 我正在使用 AWS AppSync。当请求失败时,我正在尝试使用解析器响应映射模板中的$util.error()帮助程序(此处记录)输出一些错误详细信息。无论我做什么,我都无法让 AppSync 输出输出中的data和errorInfo字段error。
这是我拥有的 Lambda。
exports.handler = (event, context, callback) => {
callback(null, {
data: {
name: "Test",
},
errorMessage: "Some error Message",
errorType: "SomeErrorType",
errors: {
"foo": "bar",
"bazz": "buzz",
}
})
};
Run Code Online (Sandbox Code Playgroud)
如您所见,它非常简单。我只是用返回一个对象data,errors,errorMessage和errorType属性。
这是我的响应映射模板
$utils.error($context.result.errorMessage, $context.result.errorType, $context.result.data, $context.result.errors)
Run Code Online (Sandbox Code Playgroud)
再次,非常直接。我只是直接使用来自 Lambda 的字段抛出错误。
但是当我执行查询时,我得到了这个:
{
"data": {
"myField": null
},
"errors": [
{
"path": [
"myField"
],
"data": null,
"errorType": …Run Code Online (Sandbox Code Playgroud) 我在我的 Appsync 解析器中这样做:
{
"version" : "2017-02-28",
"operation" : "UpdateItem",
"key" : {
"pk" : { "S" : "Container" },
"id" : { "S" : "${ctx.args.id}" }
},
"update" : {
"expression" : "SET #name = :name, description = :description",
"expressionNames": {
"#name" : "name"
},
"expressionValues": {
":name" : { "S": "${context.arguments.name}" },
":description" : { "S": "${context.arguments.description}" },
}
}
}
Run Code Online (Sandbox Code Playgroud)
但有时我可能不会同时传递名称和描述。当这些参数为空时,我如何使它不设置这些列?
我已在App Sync控制台中编写了以下订阅和变异代码:
subscription SubscribeToCreateDoctor {
subscribeToCreateDoctor {
id
name
}
}
mutation CreateDoctor {
createDoctor(
input: {
name: "sanju",
registrationNo: "some value",
speciality: "some value",
profilePic: "some value",
placeOfResidence: "some value",
medicalCenter: "some value",
direction: "some value",
municipality: "some value",
isAvailable: "No",
}) {
id
name
}
}
Run Code Online (Sandbox Code Playgroud)
在模式中,我同时定义了变异和订阅:
type Subscription {
subscribeToCreateDoctor: Doctor
@aws_subscribe(mutations: ["createDoctor"])
}
type Mutation {
createDoctor(input: CreateDoctorInput!): Doctor
}
Run Code Online (Sandbox Code Playgroud)
当我在App Sync控制台中测试CreateDoctor突变时,得到以下响应:
{
"data": {
"createDoctor": {
"id": "5845c994-2389-4df9-8a3e-e13dc24b0153",
"name": "Sanju"
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是,我没有看到在AWS App …
我有一个需要更新 AWS AppSync 架构的用例。由于我的应用程序用户将拥有不同版本的应用程序,因此不同版本需要使用的架构会有所不同。
有没有办法对 AppSync 架构进行版本控制并从 iOS 和 Android 应用程序调用不同版本的架构?
我可以获得两个平台的示例代码指针吗?
amazon-web-services aws-appsync aws-appsync-ios appsync-apollo-client
我在打字稿中有一个反应组件,我想将 appsync graphql 查询的结果设置为状态属性。
import React, { Component } from 'react';
import { API, graphqlOperation } from 'aws-amplify';
import {ListProjectsQuery} from './API'
import {listProjects } from './graphql/queries';
class App extends Component<{}, {
projects:ListProjectsQuery
}> {
state = {
projects: null
};
async componentDidMount() {
const projects = await API.graphql(graphqlOperation(listProjects));
this.setState({ projects });
}
...
Run Code Online (Sandbox Code Playgroud)
如何定义默认状态属性以使其工作?
我在 amplify github 问题中发现了类似的问题,但该解决方案是在无状态功能组件的上下文中。我正在使用有状态组件。
根据我的尝试,我似乎得到了三个错误之一。
上面的代码抛出Type 'null' is not assignable to type 'ListProjectsQuery'..
这是有道理的,所以我尝试在状态下映射形状,如下所示:
state = {
projects: {listProjects: {items: [{name: …Run Code Online (Sandbox Code Playgroud) amazon-web-services typescript reactjs aws-appsync aws-amplify
我正在使用 AWS AppSync 创建一个 GraphQL 架构,我想Union用作突变返回。我想这样写突变:
mutation addUpdateTariff($tariff: TariffInput!, $seasonalTimeTariff: [SeasonalTimeTariffInput!]) {
addUpdateTariff(tariff: $tariff, seasonalTimeTariff: $seasonalTimeTariff) {
id
type
values {
... on SteppedTariff {
endDate
}
... on SeasonalTimeTariff {
endDate
peakConsumption
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
但我收到此错误:
Request failed with status code 400
Run Code Online (Sandbox Code Playgroud)
该字段values可以是SteppedTariff或类型SeasonalTimeTariff,取决于addUpdateTariff突变的输入。据我搜索,Union仅用于查询,我没有找到一些说明它不能以不同方式使用的文档。
我错过了什么还是我真的不能用Union这种方式?
架构:
type Tariff {
id: ID!
type: TariffType!
values: [TariffValue!]
}
type SteppedTariff {
endDate: AWSDate
}
type SeasonalTimeTariff { …Run Code Online (Sandbox Code Playgroud) 我正在使用具有以下(简化)架构的 AWS AppSync 的 GraphQL 服务器:
type Query {
getIssue(id: String!): Issue
}
type Issue {
id: String!
data: IssueData!
}
type Event {
id: String!
time: AWSDateTime!
status: [String]
}
type Payment {
id: String!
amount: Int!
status: String
}
union IssueData = Event | Payment
Run Code Online (Sandbox Code Playgroud)
当我进行包含内联片段的查询以选择status作为字段中anEvent或Paymenttype的子项时Issue/data,我收到FieldsConflict错误:
query getIssue($id: String!) {
getIssue(id: $id) {
id
data {
... on Event {
time
status
}
... on Payment …Run Code Online (Sandbox Code Playgroud) aws-appsync ×10
graphql ×3
aws-amplify ×1
aws-lambda ×1
aws-sdk ×1
react-native ×1
reactjs ×1
resolver ×1
typescript ×1
yaml ×1