我有一个使用GraphQL中继连接的页面drafts
.
query {
connections {
drafts(first: 10) {
edges {
node {
... on Draft {
id
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
在这个页面中,我还创建了草稿CreateDraftMutation
.
mutation {
createDraft(input: {
clientMutationId: "1"
content: "content"
}) {
draft {
id
content
}
}
}
Run Code Online (Sandbox Code Playgroud)
在此突变之后,我希望Relay将创建的草稿添加到其商店中.变异配置的最佳候选者是RANGE_ADD,其记录如下:
https://facebook.github.io/relay/docs/guides-mutations.html
RANGE_ADD给定父级,连接以及响应有效负载中新创建的边的名称中继将根据指定的范围行为将节点添加到存储并将其附加到连接.
参数
parentName:string响应中表示连接父级的字段名称
parentID:string包含连接的父节点的DataID
connectionName:string响应中表示连接的字段名称
edgeName:string响应中表示新创建的边的字段名称
rangeBehaviors:{[call:string]:GraphQLMutatorConstants.RANGE_OPERATIONS}
按字母顺序打印的以点分隔的GraphQL调用之间的映射,以及在这些调用的影响下将新边添加到连接时我们希望Relay显示的行为.行为可以是"追加","忽略","前置","重新获取"或"删除"之一.
文档中的示例如下:
class IntroduceShipMutation extends Relay.Mutation {
// This mutation declares a dependency on the faction
// into which this ship is to be introduced.
static …
Run Code Online (Sandbox Code Playgroud) 我有这个。
@login_manager.user_loader
def load_user(id=None):
return User.query.get(id)
Run Code Online (Sandbox Code Playgroud)
在我介绍 Flask-Principal 之前,它运行良好。
@identity_loaded.connect_via(app)
def on_identity_loaded(sender, identity):
# Set the identity user object
identity.user = current_user
# return
if hasattr(current_user, 'id'):
identity.provides.add(UserNeed(current_user.id))
# Assuming the User model has a list of roles, update the
# identity with the roles that the user provides
if hasattr(current_user, 'roles'):
for role in current_user.roles:
identity.provides.add(RoleNeed(role.name))
Run Code Online (Sandbox Code Playgroud)
添加它会导致严重的性能问题。SQLALCHEMY_ECHO 显示每次加载静态文件时都会查询 User 表。
#Warning: Dummy Cache
users = {}
@login_manager.user_loader
def load_user(uid=None):
if uid not in users:
users[uid] = User.query.get(uid)
return users[uid] …
Run Code Online (Sandbox Code Playgroud)