Ash FrameworkAF
Ash Framework4w ago
15 replies
Steven0351

GraphQL json input

I have a few resources that have a jsonb column that allow for user defined metadata to be stored. These are just defined as maps on the actual Ash resource itself, and the GraphQL schema also reports the input as a Json scalar type. However, when I make a request that provides any metadata the graphql api yells at me for invalid input. I'm sure i'm holding something wrong. I figure the worst case scenario is that send it over as a json string and decode to a map

mutation InsertMetadata($metadata: Json) {
  insertMetadata(input: { metadata: $metadata }) {
    result {
      metadata
    }
  }
}

# Variables provided
{
  "metadata": {
    "key": "value"
  }
}

# Response
{
  "errors": [
    {
      "message": "Argument \"input\" has invalid value { metadata: $metadata}.\nIn field \"metadata\": Expected type \"Json\", found $metadata.\nIn field \"key\": Unknown field."
    }
  ]
}


This is how the attribute is defined in the resource
  attributes do
    attribute :metadata, :map do
      allow_nil? true
      default %{}
      public? true
      description "Additional context (environment, purpose, notes, etc.)"
    end
  end


I have ash_json configured like this in my config.exs
# Configure the JSON type for Ash.GraphQL
config :ash_graphql, :json_type, :json
Was this page helpful?