Ash FrameworkAF
Ash Frameworkโ€ข3y agoโ€ข
29 replies
Blibs

GraphQL query of resource stops working after upsert of it

This seems a little bizarre.. I have this in my seeds.exs:

super_user_args = %{
  first_name: "Super",
  surname: "Admin",
  email: "super_admin@rebuilt.com",
  phone_number: "(800) 345-2747",
  password: super_user_password,
  password_confirmation: super_user_password
}

super_admin =
  Accounts.User
  |> Ash.Changeset.new()
  |> Ash.Changeset.for_create(:register_with_password, super_user_args,
    upsert?: true,
    upsert_identity: :unique_email
  )
  |> Ash.Changeset.force_change_attribute(:confirmed_at, DateTime.utc_now())
  |> Ash.Changeset.force_change_attribute(:roles, [:super_admin])
  |> Accounts.create!()


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:

[error] #PID<0.1159.0> running Phoenix.Endpoint.SyncCodeReloadPlug (connection #PID<0.931.0>, stream id 15) terminated
Server: localhost:4000 (http)
Request: POST /playground
** (exit) an exception was raised:
    ** (Jason.EncodeError) invalid byte 0xB5 in <<1, 10, 65, 69, 83, 46, 71, 67, 77, 46, 86, 49, 181, 37, 78, 61, 19, 46, 238, 148, 121, 105, 87, 186, 181, 196, 38, 13, 156, 218, 53, 100, 21, 178, 154, 233, 81, 224, 33, 199, 67, 98, 170, 225, 228, 85, 131, 227, 1, 186, ...>>
        (jason 1.4.0) lib/jason.ex:164: Jason.encode!/2
        (absinthe_plug 1.5.8) lib/absinthe/plug.ex:598: Absinthe.Plug.encode/4
        (phoenix 1.7.0-rc.2) lib/phoenix/router/route.ex:42: Phoenix.Router.Route.call/2


I don't get why, but when the update runs, somehow it generates an invalid binary for these specific fields
Was this page helpful?