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
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.
3 Replies
ZachDaniel
ZachDaniel3y ago
You need to specify the managed relationship in the graphql dsl: https://ash-hq.org/docs/dsl/ash-resource#graphql-managed_relationships-managed_relationship
Ash HQ
Ash.Resource
View the documentation for Ash.Resource on Ash HQ.
moxley
moxleyOP3y ago
Got it. thanks @Zach Daniel ! One thing about that page you referenced. The page is for the Ash.Resource DSL, and the information in it is about AshGraphql. I never would have expected to find direct info about AshGraphql inside the Ash.Resource documentation.
ZachDaniel
ZachDaniel3y ago
Yeah, so we combined it to be about the entity that the DSL belongs in. I can see how that would be confusing

Did you find this page helpful?