zf

zenflows testing
git clone https://s.sonu.ch/~srfsh/zf.git
Log | Files | Refs | Submodules | README | LICENSE

type.ex (2845B)


      1 # Zenflows is designed to implement the Valueflows vocabulary,
      2 # written and maintained by srfsh <info@dyne.org>.
      3 # Copyright (C) 2021-2023 Dyne.org foundation <foundation@dyne.org>.
      4 #
      5 # This program is free software: you can redistribute it and/or modify
      6 # it under the terms of the GNU Affero General Public License as published by
      7 # the Free Software Foundation, either version 3 of the License, or
      8 # (at your option) any later version.
      9 #
     10 # This program is distributed in the hope that it will be useful,
     11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 # GNU Affero General Public License for more details.
     14 #
     15 # You should have received a copy of the GNU Affero General Public License
     16 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
     17 
     18 defmodule Zenflows.VF.Agent.Type do
     19 @moduledoc false
     20 
     21 use Absinthe.Schema.Notation
     22 
     23 alias Zenflows.VF.{Agent, Agent.Resolv}
     24 @name """
     25 An informal or formal textual identifier for an agent.  Does not imply
     26 uniqueness.
     27 """
     28 @images """
     29 The image files relevant to the agent, such as a logo, avatar, photo, etc.
     30 """
     31 @note "A textual description or comment."
     32 @primary_location """
     33 The main place an agent is located, often an address where activities
     34 occur and mail can be sent.  This is usually a mappable geographic
     35 location.  It also could be a website address, as in the case of agents
     36 who have no physical location.
     37 """
     38 
     39 @desc "A person or group or organization with economic agency."
     40 interface :agent do
     41 	field :id, non_null(:id)
     42 
     43 	@desc @name
     44 	field :name, non_null(:string)
     45 
     46 	@desc @images
     47 	field :images, list_of(non_null(:file)), resolve: &Resolv.images/3
     48 
     49 	@desc @note
     50 	field :note, :string
     51 
     52 	@desc @primary_location
     53 	field :primary_location, :spatial_thing,
     54 		resolve: &Resolv.primary_location/3
     55 
     56 	resolve_type fn
     57 		%Agent{type: :per}, _ -> :person
     58 		%Agent{type: :org}, _ -> :organization
     59 		nil, _ -> nil
     60 	end
     61 end
     62 
     63 object :agent_edge do
     64 	field :cursor, non_null(:id)
     65 	field :node, non_null(:agent)
     66 end
     67 
     68 object :agent_connection do
     69 	field :page_info, non_null(:page_info)
     70 	field :edges, non_null(list_of(non_null(:agent_edge)))
     71 end
     72 
     73 input_object :agent_filter_params do
     74 	field :name, :string
     75 end
     76 
     77 object :query_agent do
     78 	@desc "Loads details of the currently authenticated agent."
     79 	field :my_agent, :agent do
     80 		resolve &Resolv.my_agent/2
     81 	end
     82 
     83 	@desc "Find an agent (person or organization) by their ID."
     84 	field :agent, :agent do
     85 		arg :id, non_null(:id)
     86 		resolve &Resolv.agent/2
     87 	end
     88 
     89 	@desc """
     90 	Loads all agents publicly registered within this collaboration
     91 	space.
     92 	"""
     93 	field :agents, :agent_connection do
     94 		arg :first, :integer
     95 		arg :after, :id
     96 		arg :last, :integer
     97 		arg :before, :id
     98 		arg :filter, :agent_filter_params
     99 		resolve &Resolv.agents/2
    100 	end
    101 end
    102 
    103 # object :mutation_agent
    104 end