Ash FrameworkAF
Ash Framework3y ago
4 replies
moxley

How to manage relationships with AshGraphql

I have a Resource called WebSite that has_many :components, and each is a WebComponent. This test failed:

test "success creating a WebSite", ctx do
  input = %{
    attrs: [%{title: "Test Site", key: "test_site"}],
    components: [%{type: "html", value: "test"}]
  }

  resp_body = post_gql(ctx, query: @create_web_site, variables: %{input: input})

  %{
    "data" => %{
      "createWebSite" => %{
        "result" => result,
        # Argument "input" has invalid value $input. In field "components": Expected type "[JsonString!]"
        "errors" => []
      }
    }
  } = resp_body
end


In the list of components in the input, does each component need to be individually JSON-encoded? Apparently it does, because when I encode the component, the test passes. Why would this need to be JSON-encoded? Is this documented somewhere? I didn't see mention of it.
Was this page helpful?