I would like to add docs to my GraphQL types and their fields, so the devs working on the UI side can easily understand the data structure.
I saw that ash-graphql internally uses “Absinthe.Blueprint.Schema.FieldDefinition” but I don’t know how to create my own field description from outside.
In ApolloSandbox the autogenerated page looks like this:
PageOfChannelTag
A page of :channel_tag
Kind of type: [Object]
FIELDS |
DETAILS |
count [Int] |
Total count on all pages |
hasNextPage [Boolean] |
Whether or not there is a next page |
results [ChannelTag] |
The records contained in the page |
Well, I’m sorry about it… I found the answer by searching differently in the Ash repo.
So I am sharing a summary in case someone else faces the same concern:
On the relationships you can do the following
relationships do
belongs_to :tag, MyApp.Organizations.Tag do
allow_nil? false
#This description is mapped directly to the GraphQL Fields
description "Tag assigned to the channel"
end
end
On the attributes you can do the following
attributes do
uuid_primary_key :id do
#This description is mapped directly to the GraphQL Fields
description "Primary ID"
end
end
The one that took me the most to figure out hehe
calculations do
calculate :channel_id_test, :uuid do
#This description is mapped directly to the GraphQL Fields
description "Channel ID where the tag is assigned to"
calculation fn record, %{api: api} ->
api.load!(record, :channel).id
end
end
end
1 Like