GraphQL query of resource stops working after upsert of it
This seems a little bizarre.. I have this in my seeds.exs:
First time that this runs in an empty database, it will create the row. After this, I can query that users with GraphQL without any problem.
But, if afterwards I run my seeds.exs file again, it will run the above code again and update that row in the database.
After that, if I try to query from GraphQL with
first_name
, surname
or phone_number
which are stored as encrypted data, I get:
I don't get why, but when the update runs, somehow it generates an invalid binary for these specific fields14 Replies
what on earth
Oh, 🤔 I think I might see the issue
well, not 100% sure
When you do a simple create, what does the
first_name
value look like?
and how are you doing the encryption?
I have a feeling this is in some way related to how your encrypted type is implementedI basically copied whay you did in AshHq hahaha
The type:
The calculation:
interesting. Okay, lemme see what happens when I upsert ash_hq stuff 😆
I think this will help

the
user
is the user when it was created, the user2
is the user after the upsert
As you can see, the user
will load the first_name correctly, the user after the upsert will put binary data into the first_name
field for some reason🤔 yeah, this may actually be a problem with the way I implemented that type...
The basic issue is that we can't do a repeatable cast of that value
Alright, so we've nailed it down 🙂
Someone else had a problem with the
EncryptedString
type, and basically the answer is not to use types to encrypt values.
I'll push up an update to ash_hq showing how I'm doing it now
AlrightThe main thing you'll want to notice is the migration, you have to do some goofy things if you've already deployed your app
but if its local dev then you can just blow it all away and regenerate migrations 😄
good thing that it's only local dev for me right now hahahah
Btw, shouldn't the attributes be :binary instead of :string in this case?
Here to be more specific:

I'm base64 encoding/decoding now for compatibility of the pattern
because someone else had issues using encoded
:binary
in embedded attributesAh, I see
(because they are json in the database and can't have binary) So I figured the ash_hq example should do that
but you can make them
:binary
and remove the base64 encodign/decodingThanks Zach, I will try that out tomorrow morning!