是否可以在AWS AppSync中订阅自定义过滤逻辑?
据我所知,目前的行为是:例如,我的架构如下所示
type Mutation {
createEvent(userId: ID!, event: Event!): Event!
}
type Subscription {
onEvent(userId: ID!): Event!
@aws_subscribe(mutations: ["createEvent"])
}
Run Code Online (Sandbox Code Playgroud)
AppSync的当前行为是,当我触发createEvent时,AppSync承诺如果userId相等,则Subscription的订阅者会收到Event.即AppSync的过滤逻辑就像
if (Muatation.userId == Subscription.userId) {
// forward to subscriber
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我想要不同的过滤逻辑呢?例如,我想订阅除了由我触发的所有其他事件?即
if (Muatation.userId != Subscription.userId) {
// forward to subscriber
}
Run Code Online (Sandbox Code Playgroud)
那么,是否可以在AppSync中使用自定义过滤逻辑?
我正在将 aws-appsync 与 apollo-client 一起使用,当我尝试在不提供所有字段的情况下执行突变时,会收到类似“{...} 中缺少字段 x”的警告。我真的需要提供所有(包括可选)字段吗?我该如何优雅地处理这个问题?
我想知道这是预期的行为还是我遗漏了一些明显的东西。我不想保持必须传递所有可选字段并将这些字段作为空值存储在数据库中的额外复杂性。我想,因为它们只是警告,所以我会忽略它们,但我发现更新将在数据库中执行,但是 inmemorycache 缓存不会总是更新。它有时会显示更新,有时不会。
import {compose, graphql} from "react-apollo";
import gql from "graphql-tag";
import React from "react";
export const EditCard = (props) => {
const handleSave = () => {
props.update({
givenName :'someGivenName',
//middleName omitted on purpose
familyName :'someFamilyName',
});
};
return (
<>...more stuff here...</>
);
};
export const card = gql`
fragment card on Identity{
givenName
middleName
familyName
}
`;
export const CardsGraphQL = gql`
query GerCards {
cards: listIdentitys(filter: {type: {eq: …Run Code Online (Sandbox Code Playgroud) 在AWS AppSync中,似乎不会将在主查询上发送的参数转发给所有子解析器。
type Query {
article(id: String!, consistentRead: Boolean): Article
book(id: String!, consistentRead: Boolean): Book
}
type Article {
title: String!
id: String!
}
type Book {
articleIds: [String]!
articles: [Article]!
id: String!
}
Run Code Online (Sandbox Code Playgroud)
当我打电话时:
query GetBook {
book(id: 123, consistentRead: true) {
articles {
title
}
}
}
Run Code Online (Sandbox Code Playgroud)
获取书的第一个查询在中接收consistentRead参数$context.arguments,但随后的检索文章的查询则没有。($context.arguments为空)
我也尝试过articles(consistentRead: Boolean): [Article]!里面book但是没有运气。
有谁知道在AppSync中是否可以将参数传递给同一请求的所有查询?
我知道上下文是您在Lambda函数中定义的名称,但是对于Appsync解析器,我有点困惑。我已经看到了两者$ctx,$context并在包括AWS文档在内的AppSync解析器中使用了它们。AWS自己的一些代码生成工具(例如AWS Amplify CLI)会创建在同一代码中使用两者的解析器!我在文档中找不到任何解释此内容的信息。这里发生了什么?
amazon-web-services graphql aws-appsync aws-appsync-ios appsync-apollo-client
我有以下架构:
input CreateEventInput {
userID: String!
eventID: ID!
type: String!
data: String
dateTime: AWSDateTime!
}
type Mutation {
createEvent(input: CreateEventInput!): event
}
type Subscription {
onCreateEvent(): event
@aws_subscribe(mutations: ["createEvent"])
Run Code Online (Sandbox Code Playgroud)
该createEvent解析器设置userID,如:
"key" : {
"userID" : $util.dynamodb.toDynamoDBJson($context.identity.username),
"eventID" : $util.dynamodb.toDynamoDBJson($util.autoId())
}
Run Code Online (Sandbox Code Playgroud)
我想限制订阅,以便只记录userID = $context.identity.username返回给用户的位置。
有谁知道如何设置?我想我需要一个关于订阅的解析器,但我找不到一个明确的例子,你有一个主分区键 ( userID) 和主排序键 ( eventID)。
我真的很感激任何帮助或指导。如果需要,我可以更改架构或数据库。
更新:
我相信我可以将订阅响应映射模板设置为:
#if(${context.identity.username} != ${context.arguments.userID})
$utils.unauthorized()
#else
##User is authorized, but we return null to continue
null
#end
Run Code Online (Sandbox Code Playgroud)
但是,我不知道在请求映射模板中放什么。
amazon-dynamodb amazon-cognito aws-appsync aws-amplify appsync-apollo-client
我有一个简单的 GraphQL 枚举,定义如下:
enum PassType {
DailyFit
StarterFit
MonthlyFit
QuarterlyFit
DoubleFit
MultiFit10
MultiFit20
}
Run Code Online (Sandbox Code Playgroud)
我想在<select>标签中重用这些值。我使用 Apollo 和 AWS Appync 作为 GraphQL 基础设施。有没有办法从 Apollo 客户端获取这些,而无需在前端手动复制它们?
我有一个需要更新 AWS AppSync 架构的用例。由于我的应用程序用户将拥有不同版本的应用程序,因此不同版本需要使用的架构会有所不同。
有没有办法对 AppSync 架构进行版本控制并从 iOS 和 Android 应用程序调用不同版本的架构?
我可以获得两个平台的示例代码指针吗?
amazon-web-services aws-appsync aws-appsync-ios appsync-apollo-client
APPSYNC_ERROR: Attempt to invoke virtual method
Run Code Online (Sandbox Code Playgroud)
java.util.Map com.amazonaws.mobile.client.AWSMobileClientStore.get(java.lang.String[]) on a null object reference
I am trying to inserting data in AWS table, But i got this error. Can you help me to resolve this issue?
AWSAppSyncClient client = AWSAppSyncClient.builder()
.context(context)
.region(AppHelper.cognitoRegion)
.serverUrl(AppHelper.SERVER_URL)
.cognitoUserPoolsAuthProvider(new CognitoUserPoolsAuthProvider() {
@Override
public String getLatestAuthToken() {
try {
return AWSMobileClient.getInstance().getTokens().getIdToken().getTokenString();
} catch (Exception e){
Log.e("APPSYNC_ERROR", e.getLocalizedMessage());
return e.getLocalizedMessage();
}
}
}).persistentMutationsCallback(new PersistentMutationsCallback() {
@Override
public void onResponse(PersistentMutationsResponse response) {
Log.d("NOTERROR", response.getMutationClassName());
}
@Override
public void onFailure(PersistentMutationsError …Run Code Online (Sandbox Code Playgroud) android amazon-web-services aws-sdk aws-appsync appsync-apollo-client