invalid_field: InvalidField | Invalid field for type user: name

Is this incorrect or missing something?
No description
No description
No description
9 Replies
ZachDaniel
ZachDaniel•3mo ago
It is a bug that you're seeing name in the docs only public attributes are shown šŸ¤” Do you possibly have multiple resources w/ the same json api type? Looking at the code, that should only be showing public attributes šŸ¤”
JVMartyns
JVMartynsOP•3mo ago
graphql do
type :user
end

json_api do
type "user"
end
graphql do
type :user
end

json_api do
type "user"
end
and
graphql do
type :pet
end

json_api do
type "pet"
end
graphql do
type :pet
end

json_api do
type "pet"
end
ZachDaniel
ZachDaniel•3mo ago
And you're on the latest versions of packages?
JVMartyns
JVMartynsOP•3mo ago
I ran mix deps.update --all and only igniter was updated: igniter 0.6.13 => 0.6.14
ZachDaniel
ZachDaniel•3mo ago
šŸ¤” šŸ¤” šŸ¤” What happens if you make name public?
JVMartyns
JVMartynsOP•3mo ago
Is it necessary to explicitly define whether an attribute is public or private?
ZachDaniel
ZachDaniel•3mo ago
it defaults to private so yes šŸ˜„
%Parameter{
name: :fields,
in: :query,
description: "Limits the response fields to only those listed for each type",
required: false,
style: :deepObject,
schema: %Schema{
type: :object,
additionalProperties: true,
example: %{
type =>
Ash.Resource.Info.public_attributes(resource)
|> Enum.map_join(",", & &1.name)
},
properties: %{
# There is a static set of types (one per resource)
# so this is safe.
#
# sobelow_skip ["DOS.StringToAtom"]
String.to_atom(type) => %Schema{
description: "Comma separated field names for #{type}",
type: :string,
example:
Ash.Resource.Info.public_attributes(resource)
|> Enum.map_join(",", & &1.name)
}
}
}
}
%Parameter{
name: :fields,
in: :query,
description: "Limits the response fields to only those listed for each type",
required: false,
style: :deepObject,
schema: %Schema{
type: :object,
additionalProperties: true,
example: %{
type =>
Ash.Resource.Info.public_attributes(resource)
|> Enum.map_join(",", & &1.name)
},
properties: %{
# There is a static set of types (one per resource)
# so this is safe.
#
# sobelow_skip ["DOS.StringToAtom"]
String.to_atom(type) => %Schema{
description: "Comma separated field names for #{type}",
type: :string,
example:
Ash.Resource.Info.public_attributes(resource)
|> Enum.map_join(",", & &1.name)
}
}
}
}
for example thats how we generate that value, using only public attributes
JVMartyns
JVMartynsOP•3mo ago
How to define as public? Ah, I discovered: attribute :name, :string, public?: true Has anyone ever discussed this? It didn't seem very intuitive to me. Maybe I'm just tired. Could you point me to where I can find this information in the documentation?
ZachDaniel
ZachDaniel•3mo ago
it probably needs to be front loaded somewhere if this is the only place, but it is described here: https://hexdocs.pm/ash/sensitive-data.html#public-private-attributes

Did you find this page helpful?