You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What are the recommendations of encrypting/decrypting field (definition and input).
let's uppose the following type:
type Person { name: String @encrypt, ...other field }
Now I want to encrypt values of person.name.
My directive template:
...
classEncryptedStringextendsGraphQLScalarType{constructor(config: SomeType){const{ name ='SomeName'}=config;constcipher=newAesCipher({key: config.key,iv: config.iv});// Some util for encryptionsuper({
name,description: 'description',serialize(value: string){returncipher.encrypt(value);},parseValue(value: any){returncipher.decrypt(value);},parseLiteral(ast: ValueNode){if(ast.kind==='StringValue')returncipher.encrypt(ast.value);returnnull;},});}}...[MapperKind.OBJECT_FIELD]: (fieldConfig,schem)=>{const encryptedDirective =getDirective(schema,fieldConfig,directiveName)?.[0];if(encryptedDirective){const{ resolve =defaultFieldResolver}=fieldConfig;fieldConfig.resolve=asyncfunction(source,args,context,info){constkeyManager=KeyManagerService.secureGetKeyForTenant(context.userId);// From DBconstresult=awaitresolve(source,args,context,info);if(typeofresult==='string'&&keyManager?.key){constnewResult=newEncryptedType({key: keyManager.key});returnnewResult;}returnresult;returnresolve(source,args,context,info);};returnfieldConfig;}}
...
The above code produces an error. EncryptedString returns its name.
I need to resolve the fieldConfig here because I need the userId. On the other hand, I need EncryptedString-Scalar because I want to perform some encryption based on whether it's parsedValue, serialize, or parseLiteral.
From my guess, const newResult = new EncryptedType({ key: keyManager.key }); return a type not a value. this may be the reson the code is breaking.
Is there a way to call parsedValue, serialize, and parseLiteral directly inside fieldConfig.resolve? Or is there a way to access apollo context (userId) outside of fieldConfig.resolve?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
What are the recommendations of encrypting/decrypting field (definition and input).
let's uppose the following type:
type Person { name: String @encrypt, ...other field }
Now I want to encrypt values of
person.name
.My directive template:
The above code produces an error.
EncryptedString
returns its name.I need to resolve the
fieldConfig
here because I need theuserId
. On the other hand, I needEncryptedString-Scalar
because I want to perform some encryption based on whether it'sparsedValue
,serialize
, orparseLiteral
.From my guess,
const newResult = new EncryptedType({ key: keyManager.key });
return atype
not avalue
. this may be the reson the code is breaking.Is there a way to call
parsedValue
,serialize
, andparseLiteral
directly insidefieldConfig.resolve
? Or is there a way to accessapollo context
(userId
) outside offieldConfig.resolve
?Beta Was this translation helpful? Give feedback.
All reactions