是否可以通过graphql服务器结合中继和反应来验证具有不同角色的用户?
我环顾四周,找不到有关此主题的更多信息.
在我目前的设置中,具有不同角色的登录功能仍然通过传统的REST API ...(使用json web令牌'安全').
我在我的一个应用程序中做到了,基本上你只需要一个用户界面,如果没有人登录,这个在第一个根查询上返回null,然后你可以用传递凭证的登录变异更新它.主要问题是在发布中继请求中获取cookie或会话,因为它不处理请求中的cookie字段.
这是我的客户端变异:
export default class LoginMutation extends Relay.Mutation {
static fragments = {
user: () => Relay.QL`
fragment on User {
id,
mail
}
`,
};
getMutation() {
return Relay.QL`mutation{Login}`;
}
getVariables() {
return {
mail: this.props.credentials.pseudo,
password: this.props.credentials.password,
};
}
getConfigs() {
return [{
type: 'FIELDS_CHANGE',
fieldIDs: {
user: this.props.user.id,
}
}];
}
getOptimisticResponse() {
return {
mail: this.props.credentials.pseudo,
};
}
getFatQuery() {
return Relay.QL`
fragment on LoginPayload {
user {
userID,
mail
}
}
`;
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的架构方面的突变
var LoginMutation = mutationWithClientMutationId({
name: 'Login',
inputFields: {
mail: {
type: new GraphQLNonNull(GraphQLString)
},
password: {
type: new GraphQLNonNull(GraphQLString)
}
},
outputFields: {
user: {
type: GraphQLUser,
resolve: (newUser) => newUser
}
},
mutateAndGetPayload: (credentials, {
rootValue
}) => co(function*() {
var newUser = yield getUserByCredentials(credentials, rootValue);
console.log('schema:loginmutation');
delete newUser.id;
return newUser;
})
});
Run Code Online (Sandbox Code Playgroud)
让我的用户通过页面刷新进行记录我发送自己的请求并用cookie字段填充...这是目前使其工作的唯一方法...
归档时间: |
|
查看次数: |
2155 次 |
最近记录: |