我想为应用程序使用单个更改将用户信息发送到服务器,然后在输出中获取顶级查询。(我知道这不是一个好的约定,但我想这样做是为了测试我是否可以提高性能)。
因此,只有一个突变会获取用户的信息并返回提要。这种变化更新了在每个查询中作为请求上下文获取的用户信息。上下文用于生成个性化提要。但是,当我调用此更改时,返回的输出是使用旧上下文计算的。我需要做的是更新这个相同突变的上下文。
我放下了代码的简化版本来展示发生了什么:
const UserType = new GraphQLObjectType({
name: 'User',
fields: () => ({
someData: {
type: GraphQLList(Post),
resolve: (user, args, context) => getFeed(context) // context in here is the old context.
},
})
})
const someMutation = mutationWithClientMutationId({
name: 'someMutation',
inputFields: {
location: { type: GraphQLString },
},
outputFields: {
user: {
type: UserType,
resolve: (source, args, context) => getUser(context.location),
},
},
mutateAndGetPayload: async (data, context) => {
updateUserInfo(data)
// I have tried updating context like this but it's …Run Code Online (Sandbox Code Playgroud) 我是nodejs和javascript的新手,我目前正在开发一个开源项目,因为昨晚我试图将此函数从异步转换为同步,但我做不到,我使用了async/await,但我认为我不太理解这个概念,这个函数使用 aes256 算法加密和压缩文件,我异步工作得很好,但我想添加这个新功能,允许您递归地加密目录的内容。
function encrypt({ file, password }, error_callback, succ_callback) {
const initVect = crypto.randomBytes(16);
// Generate a cipher key from the password.
const CIPHER_KEY = crypto.createHash('sha256').update(password).digest();;
const readStream = fs.createReadStream(file);
const gzip = zlib.createGzip();
const cipher = crypto.createCipheriv('aes-256-cbc', CIPHER_KEY, initVect);
const appendInitVect = new AppendInitVect(initVect);
// Create a write stream with a different file extension.
const writeStream = fs.createWriteStream(path.join(file + ".dnc"));
readStream
.pipe(gzip)
.pipe(cipher)
.pipe(appendInitVect)
.pipe(writeStream);
readStream.on('error', error_callback);
readStream.on('end', succ_callback);
}
Run Code Online (Sandbox Code Playgroud)