Improve GraphQL documentation and cleanup API

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2020-11-19 17:06:28 +01:00
parent e8a3b6aa94
commit 3eacbb2ca3
87 changed files with 6542 additions and 6314 deletions

View File

@@ -58,24 +58,42 @@ defmodule Mobilizon.GraphQL.Schema.UserType do
field(:participations, :paginated_participant_list,
description: "The list of participations this user has"
) do
arg(:after_datetime, :datetime)
arg(:before_datetime, :datetime)
arg(:page, :integer, default_value: 1)
arg(:limit, :integer, default_value: 10)
arg(:after_datetime, :datetime, description: "Filter participations by event start datetime")
arg(:before_datetime, :datetime, description: "Filter participations by event end datetime")
arg(:page, :integer,
default_value: 1,
description: "The page in the paginated participations list"
)
arg(:limit, :integer,
default_value: 10,
description: "The limit of participations per page"
)
resolve(&User.user_participations/3)
end
field(:memberships, :paginated_member_list,
description: "The list of memberships for this user"
) do
arg(:page, :integer, default_value: 1)
arg(:limit, :integer, default_value: 10)
arg(:page, :integer,
default_value: 1,
description: "The page in the paginated memberships list"
)
arg(:limit, :integer, default_value: 10, description: "The limit of memberships per page")
resolve(&User.user_memberships/3)
end
field(:drafts, list_of(:event), description: "The list of draft events this user has created") do
arg(:page, :integer, default_value: 1)
arg(:limit, :integer, default_value: 10)
arg(:page, :integer,
default_value: 1,
description: "The page in the paginated drafts events list"
)
arg(:limit, :integer, default_value: 10, description: "The limit of drafts events per page")
resolve(&User.user_drafted_events/3)
end
@@ -94,10 +112,11 @@ defmodule Mobilizon.GraphQL.Schema.UserType do
)
end
@desc "The list of roles an user can have"
enum :user_role do
value(:administrator)
value(:moderator)
value(:user)
value(:administrator, description: "Administrator role")
value(:moderator, description: "Moderator role")
value(:user, description: "User role")
end
@desc "Token"
@@ -112,9 +131,9 @@ defmodule Mobilizon.GraphQL.Schema.UserType do
field(:elements, non_null(list_of(:user)), description: "User elements")
end
@desc "The list of possible options for the event's status"
@desc "The list of sortable fields for an user list"
enum :sortable_user_field do
value(:id)
value(:id, description: "The user's ID")
end
object :user_settings do
@@ -142,11 +161,24 @@ defmodule Mobilizon.GraphQL.Schema.UserType do
)
end
@desc "The list of values the for pending notification settings"
enum :notification_pending_enum do
value(:none, as: :none)
value(:direct, as: :direct)
value(:one_hour, as: :one_hour)
value(:one_day, as: :one_day)
value(:none, as: :none, description: "None. The notification won't be sent.")
value(:direct,
as: :direct,
description: "Direct. The notification will be sent right away each time."
)
value(:one_hour,
as: :one_hour,
description: "One hour. Notifications will be sent at most each hour"
)
value(:one_day,
as: :one_day,
description: "One day. Notifications will be sent at most each day"
)
end
object :user_queries do
@@ -163,12 +195,12 @@ defmodule Mobilizon.GraphQL.Schema.UserType do
@desc "List instance users"
field :users, :users do
arg(:email, :string, default_value: "")
arg(:page, :integer, default_value: 1)
arg(:limit, :integer, default_value: 10)
arg(:email, :string, default_value: "", description: "Filter users by email")
arg(:page, :integer, default_value: 1, description: "The page in the paginated users list")
arg(:limit, :integer, default_value: 10, description: "The limit of users per page")
arg(:sort, :sortable_user_field, default_value: :id)
arg(:direction, :sort_direction, default_value: :desc)
arg(:sort, :sortable_user_field, default_value: :id, description: "Sort column")
arg(:direction, :sort_direction, default_value: :desc, description: "Sort direction")
resolve(&User.list_users/3)
end
@@ -177,99 +209,128 @@ defmodule Mobilizon.GraphQL.Schema.UserType do
object :user_mutations do
@desc "Create an user"
field :create_user, type: :user do
arg(:email, non_null(:string))
arg(:password, non_null(:string))
arg(:locale, :string)
arg(:email, non_null(:string), description: "The new user's email")
arg(:password, non_null(:string), description: "The new user's password")
arg(:locale, :string, description: "The new user's locale")
resolve(&User.create_user/3)
end
@desc "Validate an user after registration"
field :validate_user, type: :login do
arg(:token, non_null(:string))
arg(:token, non_null(:string),
description: "The token that will be used to validate the user"
)
resolve(&User.validate_user/3)
end
@desc "Resend registration confirmation token"
field :resend_confirmation_email, type: :string do
arg(:email, non_null(:string))
arg(:locale, :string)
arg(:email, non_null(:string), description: "The email used to register")
arg(:locale, :string, description: "The user's locale")
resolve(&User.resend_confirmation_email/3)
end
@desc "Send a link through email to reset user password"
field :send_reset_password, type: :string do
arg(:email, non_null(:string))
arg(:locale, :string)
arg(:email, non_null(:string), description: "The user's email")
arg(:locale, :string, description: "The user's locale")
resolve(&User.send_reset_password/3)
end
@desc "Reset user password"
field :reset_password, type: :login do
arg(:token, non_null(:string))
arg(:password, non_null(:string))
arg(:locale, :string, default_value: "en")
arg(:token, non_null(:string),
description: "The user's token that will be used to reset the password"
)
arg(:password, non_null(:string), description: "The new password")
arg(:locale, :string, default_value: "en", description: "The user's locale")
resolve(&User.reset_password/3)
end
@desc "Login an user"
field :login, type: :login do
arg(:email, non_null(:string))
arg(:password, non_null(:string))
arg(:email, non_null(:string), description: "The user's email")
arg(:password, non_null(:string), description: "The user's password")
resolve(&User.login_user/3)
end
@desc "Refresh a token"
field :refresh_token, type: :refreshed_token do
arg(:refresh_token, non_null(:string))
arg(:refresh_token, non_null(:string), description: "A refresh token")
resolve(&User.refresh_token/3)
end
@desc "Change default actor for user"
field :change_default_actor, :user do
arg(:preferred_username, non_null(:string))
arg(:preferred_username, non_null(:string), description: "The actor preferred_username")
resolve(&User.change_default_actor/3)
end
@desc "Change an user password"
field :change_password, :user do
arg(:old_password, non_null(:string))
arg(:new_password, non_null(:string))
arg(:old_password, non_null(:string), description: "The user's current password")
arg(:new_password, non_null(:string), description: "The user's new password")
resolve(&User.change_password/3)
end
@desc "Change an user email"
field :change_email, :user do
arg(:email, non_null(:string))
arg(:password, non_null(:string))
arg(:email, non_null(:string), description: "The user's new email")
arg(:password, non_null(:string), description: "The user's current password")
resolve(&User.change_email/3)
end
@desc "Validate an user email"
field :validate_email, :user do
arg(:token, non_null(:string))
arg(:token, non_null(:string),
description: "The token that will be used to validate the email change"
)
resolve(&User.validate_email/3)
end
@desc "Delete an account"
field :delete_account, :deleted_object do
arg(:password, :string)
arg(:user_id, :id)
arg(:password, :string, description: "The user's password")
arg(:user_id, :id, description: "The user's ID")
resolve(&User.delete_account/3)
end
@desc "Set user settings"
field :set_user_settings, :user_settings do
arg(:timezone, :string)
arg(:notification_on_day, :boolean)
arg(:notification_each_week, :boolean)
arg(:notification_before_event, :boolean)
arg(:notification_pending_participation, :notification_pending_enum)
arg(:notification_pending_membership, :notification_pending_enum)
arg(:timezone, :string, description: "The timezone for this user")
arg(:notification_on_day, :boolean,
description:
"Whether this user will receive an email at the start of the day of an event."
)
arg(:notification_each_week, :boolean,
description: "Whether this user will receive an weekly event recap"
)
arg(:notification_before_event, :boolean,
description: "Whether this user will receive a notification right before event"
)
arg(:notification_pending_participation, :notification_pending_enum,
description: "When does the user receives a notification about new pending participations"
)
arg(:notification_pending_membership, :notification_pending_enum,
description:
"When does the user receives a notification about a new pending membership in one of the group they're admin for"
)
resolve(&User.set_user_setting/3)
end
@desc "Update the user's locale"
field :update_locale, :user do
arg(:locale, :string)
arg(:locale, :string, description: "The user's new locale")
resolve(&User.update_locale/3)
end
end