Commit 3ed3b6e1 authored by Mayel's avatar Mayel

missing fields

parent 96d605cc
Pipeline #215169732 failed with stage
in 1 minute and 11 seconds
......@@ -42,15 +42,6 @@ defmodule ValueFlows.Claim.GraphQL do
})
end
def fetch_resource_conforms_to_edge(%{resource_conforms_to_id: id} = thing, _, _)
when is_binary(id) do
thing = Repo.preload(thing, :resource_conforms_to)
{:ok, Map.get(thing, :resource_conforms_to)}
end
def fetch_resource_conforms_to_edge(_, _, _) do
{:ok, nil}
end
def fetch_triggered_by_edge(%{triggered_by_id: id} = thing, _, _) when is_binary(id) do
thing = Repo.preload(thing, :triggered_by)
......
......@@ -121,11 +121,17 @@ defmodule ValueFlows.Hydration do
resolve: &ValueFlows.Proposal.ProposedIntentGraphQL.published_in_edge/3
],
resource_conforms_to: [
resolve: &ValueFlows.Planning.Intent.GraphQL.fetch_resource_conforms_to_edge/3
resolve: &ValueFlows.Util.GraphQL.fetch_resource_conforms_to_edge/3
],
resource_inventoried_as: [
resolve: &ValueFlows.Planning.Intent.GraphQL.fetch_resource_inventoried_as_edge/3
],
resource_quantity: [
resolve: &ValueFlows.Util.GraphQL.resource_quantity_edge/3
],
effort_quantity: [
resolve: &ValueFlows.Util.GraphQL.effort_quantity_edge/3
],
input_of: [
resolve: &ValueFlows.Planning.Intent.GraphQL.fetch_input_of_edge/3
],
......@@ -150,7 +156,7 @@ defmodule ValueFlows.Hydration do
resolve: &ValueFlows.Util.GraphQL.effort_quantity_edge/3
],
resource_conforms_to: [
resolve: &ValueFlows.Claim.GraphQL.fetch_resource_conforms_to_edge/3,
resolve: &ValueFlows.Util.GraphQL.fetch_resource_conforms_to_edge/3,
],
triggered_by: [
resolve: &ValueFlows.Claim.GraphQL.fetch_triggered_by_edge/3,
......@@ -175,6 +181,15 @@ defmodule ValueFlows.Hydration do
action: [
resolve: &ValueFlows.Knowledge.Action.GraphQL.action_edge/3
],
resource_conforms_to: [
resolve: &ValueFlows.Util.GraphQL.fetch_resource_conforms_to_edge/3,
],
resource_quantity: [
resolve: &ValueFlows.Util.GraphQL.resource_quantity_edge/3
],
effort_quantity: [
resolve: &ValueFlows.Util.GraphQL.effort_quantity_edge/3
],
in_scope_of: [
resolve: &CommonResolver.context_edge/3
],
......@@ -215,6 +230,9 @@ defmodule ValueFlows.Hydration do
canonical_url: [
resolve: &ValueFlows.Util.GraphQL.canonical_url_edge/3
],
state: [
resolve: &ValueFlows.Observation.EconomicResource.GraphQL.fetch_state_edge/3
],
in_scope_of: [
resolve: &CommonResolver.context_edge/3
],
......@@ -227,6 +245,9 @@ defmodule ValueFlows.Hydration do
image: [
resolve: &UploadResolver.image_content_edge/3
],
available_quantity: [
resolve: &ValueFlows.Util.GraphQL.available_quantity_edge/3
],
accounting_quantity: [
resolve: &ValueFlows.Util.GraphQL.accounting_quantity_edge/3
],
......@@ -279,6 +300,9 @@ defmodule ValueFlows.Hydration do
],
outputs: [
resolve: &ValueFlows.Observation.Process.GraphQL.outputs/3
],
based_on: [
resolve: &ValueFlows.Observation.Process.GraphQL.fetch_based_on_edge/3
]
},
......
defmodule ValueFlows.Knowledge.Action.Actions do
# @on_load :load_actions
def action!(label) do
def action!(label) do
with {:ok, action} <- action(label) do
action
else _ -> nil
else
_ -> nil
end
end
......@@ -12,7 +13,6 @@ defmodule ValueFlows.Knowledge.Action.Actions do
action(Atom.to_string(label))
end
def action(label) do
case load_actions()[label] do
nil ->
......
......@@ -193,6 +193,7 @@ defmodule ValueFlows.Knowledge.ProcessSpecification.GraphQL do
end
end
# defp validate_agent(pointer) do
# if Pointers.table!(pointer).schema in valid_contexts() do
# :ok
......
......@@ -157,6 +157,7 @@ defmodule ValueFlows.Observation.EconomicEvent.EventSideEffects do
EconomicResources.update(resource, %{onhand_quantity: by_quantity}) do
resource
end
resource
end
......@@ -191,10 +192,22 @@ defmodule ValueFlows.Observation.EconomicEvent.EventSideEffects do
measurement
end
def return_updated_event(event, {:error, e}) do
{:error, e}
end
def return_updated_event(event, resource) do
{:ok, %{event | resource_inventoried_as: resource}}
end
def return_updated_event(event, {:error, e}, _) do
{:error, e}
end
def return_updated_event(event, _, {:error, e}) do
{:error, e}
end
def return_updated_event(event, resource, to_resource) do
{:ok, %{event | resource_inventoried_as: resource, to_resource_inventoried_as: to_resource}}
end
......
......@@ -2,7 +2,6 @@
defmodule ValueFlows.Observation.Process.GraphQL do
require Logger
alias CommonsPub.{
# Activities,
# Communities,
......@@ -181,7 +180,7 @@ defmodule ValueFlows.Observation.Process.GraphQL do
processes_filtered(%{agent: creator})
end
def creator_processes(_, _page_opts, _info) do
def creator_processes(_, _page_opts, _info) do
{:ok, nil}
end
......@@ -208,6 +207,16 @@ defmodule ValueFlows.Observation.Process.GraphQL do
)
end
def fetch_based_on_edge(%{based_on_id: id} = thing, _, _)
when is_binary(id) do
thing = Repo.preload(thing, :based_on)
{:ok, Map.get(thing, :based_on)}
end
def fetch_based_on_edge(_, _, _) do
{:ok, nil}
end
def list_processes(page_opts, base_filters, _data_filters, _cursor_type) do
FetchPage.run(%FetchPage{
queries: Queries,
......@@ -226,7 +235,7 @@ defmodule ValueFlows.Observation.Process.GraphQL do
# preload: [:provider, :receiver, :tags],
# cursor_fn: Processes.cursor(:followers),
page_opts: page_opts,
cursor_fn: & &1.id,
cursor_fn: & &1.id,
base_filters: [
:default,
# preload: [:provider, :receiver, :tags],
......
......@@ -365,6 +365,12 @@ defmodule ValueFlows.Observation.EconomicResource.GraphQL do
EconomicResources.trace(id)
end
def fetch_state_edge(%{state_id: id} = thing, _, _) when is_binary(id) do
thing = EconomicResources.preload_state(thing)
{:ok, Map.get(thing, :conforms_to)}
end
def create_resource(%{new_inventoried_resource: resource_attrs}, info) do
with {:ok, resource} <- create_resource(%{economic_resource: resource_attrs}, info) do
{:ok, Map.get(resource, :economic_resource)}
......
......@@ -71,7 +71,7 @@ defmodule ValueFlows.Observation.EconomicResource do
@required ~w(name is_public)a
@cast @required ++ ~w(note tracking_identifier current_location_id is_disabled image_id)a ++
~w(primary_accountable_id contained_in_id unit_of_effort_id conforms_to_id current_location_id)a
~w(primary_accountable_id state_id contained_in_id unit_of_effort_id conforms_to_id current_location_id)a
def create_changeset(
%User{} = creator,
......
......@@ -273,16 +273,6 @@ defmodule ValueFlows.Planning.Intent.GraphQL do
)
end
def fetch_resource_conforms_to_edge(%{resource_conforms_to_id: id} = thing, _, _)
when is_binary(id) do
thing = Repo.preload(thing, :resource_conforms_to)
{:ok, Map.get(thing, :resource_conforms_to)}
end
def fetch_resource_conforms_to_edge(_, _, _) do
{:ok, nil}
end
def fetch_resource_inventoried_as_edge(%{resource_inventoried_as_id: id} = thing, _, _)
when is_binary(id) do
thing = Repo.preload(thing, :resource_inventoried_as)
......
......@@ -41,6 +41,7 @@ defmodule ValueFlows.Simulate do
|> Map.put_new_lazy("created", &past_datetime_iso/0)
|> Map.put_new_lazy("due", &future_datetime_iso/0)
|> Map.put_new_lazy("action", &action_id/0)
# |> Map.put_new_lazy("resourceClassifiedAs", fn -> some(1..5, &url/0) end)
end
......@@ -57,7 +58,9 @@ defmodule ValueFlows.Simulate do
end
def fake_agent!(overrides \\ %{}, opts \\ []) when is_map(overrides) and is_list(opts) do
ValueFlows.Agent.Agents.character_to_agent(a_fake_user!(ValueFlows.Agent.Agents.agent_to_character(agent(overrides))))
ValueFlows.Agent.Agents.character_to_agent(
a_fake_user!(ValueFlows.Agent.Agents.agent_to_character(agent(overrides)))
)
end
def resource_specification(base \\ %{}) do
......@@ -118,7 +121,7 @@ defmodule ValueFlows.Simulate do
|> Map.put_new_lazy(:name, &name/0)
|> Map.put_new_lazy(:note, &summary/0)
|> Map.put_new_lazy(:tracking_identifier, &uuid/0)
# |> Map.put_new_lazy(:state, &action_id/0)
|> Map.put_new_lazy(:state, &action_id/0)
# |> Map.put_new_lazy(:accounting_quantity, &measure/0)
# |> Map.put_new_lazy(:onhand_quantity, &measure/0)
# |> Map.put_new_lazy(:unit_of_effort, &unit/0)
......@@ -217,7 +220,7 @@ defmodule ValueFlows.Simulate do
|> Map.put_new_lazy(:has_end, &future_datetime/0)
|> Map.put_new_lazy(:has_point_in_time, &future_datetime/0)
|> Map.put_new_lazy(:due, &future_datetime/0)
# TODO: list of URIs
# TODO: list of URIs?
|> Map.put_new_lazy(:resource_classified_as, fn -> some(1..5, &url/0) end)
|> Map.put_new_lazy(:finished, &bool/0)
|> Map.put_new_lazy(:is_public, &truth/0)
......@@ -249,6 +252,21 @@ defmodule ValueFlows.Simulate do
end
def fake_intent!(user, overrides \\ %{}) do
unit = fake_unit!(user)
fake_intent!(user, overrides, unit)
end
def fake_intent!(user, overrides, unit) do
measure_attrs = %{unit_id: unit.id}
measures = %{
available_quantity: measure(measure_attrs),
resource_quantity: measure(measure_attrs),
effort_quantity: measure(measure_attrs)
}
overrides = Map.merge(overrides, measures)
{:ok, intent} = Intents.create(user, intent(overrides))
intent
end
......@@ -288,7 +306,8 @@ defmodule ValueFlows.Simulate do
measure_attrs = %{unit_id: unit.id}
measures = %{
resource_quantity: measure(measure_attrs)
resource_quantity: measure(measure_attrs),
effort_quantity: measure(measure_attrs)
}
overrides = Map.merge(overrides, measures)
......@@ -317,7 +336,7 @@ defmodule ValueFlows.Simulate do
measures = %{
accounting_quantity: measure(measure_attrs),
onhand_quantity: measure(measure_attrs),
onhand_quantity: measure(measure_attrs)
}
overrides = Map.merge(overrides, measures)
......
......@@ -71,6 +71,26 @@ defmodule ValueFlows.Util.GraphQL do
{:ok, nil}
end
def fetch_resource_conforms_to_edge(%{resource_conforms_to_id: id} = thing, _, _)
when is_binary(id) do
thing = Repo.preload(thing, :resource_conforms_to)
{:ok, Map.get(thing, :resource_conforms_to)}
end
def fetch_resource_conforms_to_edge(_, _, _) do
{:ok, nil}
end
def available_quantity_edge(%{available_quantity_id: id} = thing, _, _) when not is_nil(id) do
thing = Repo.preload(thing, available_quantity: [:unit])
{:ok, Map.get(thing, :available_quantity)}
end
def available_quantity_edge(_, _, _) do
{:ok, nil}
end
def resource_quantity_edge(%{resource_quantity_id: id} = thing, _, _) when not is_nil(id) do
thing = Repo.preload(thing, resource_quantity: [:unit])
{:ok, Map.get(thing, :resource_quantity)}
......
......@@ -6,6 +6,7 @@ defmodule Valueflows.Agent.Person.GraphQLTest do
import CommonsPub.Web.Test.GraphQLAssertions
import Geolocation.Test.Faking
import Measurement.Simulate
import ValueFlows.Simulate
import ValueFlows.Test.Faking
......@@ -28,28 +29,50 @@ defmodule Valueflows.Agent.Person.GraphQLTest do
# attach some data to the person...
intent =
fake_intent!(user, %{ provider: user.id })
unit = fake_unit!(user)
resource =
fake_economic_resource!(user, %{
primary_accountable: user.id
})
intent = fake_intent!(user, %{provider: user.id})
rspec = fake_resource_specification!(user)
process = fake_process!(user)
from_resource =
fake_economic_resource!(user2, %{name: "Previous Resource", conforms_to: rspec.id}, unit)
resource =
fake_economic_resource!(
user,
%{
primary_accountable: user.id,
name: "Resulting Resource",
conforms_to: rspec.id
},
unit
)
pspec = fake_process_specification!(user)
process = fake_process!(user, %{based_on: pspec.id})
event =
fake_economic_event!(user, %{
provider: user2.id,
receiver: user.id,
action: "transfer",
input_of: fake_process!(user).id,
output_of: fake_process!(user2).id,
resource_conforms_to: fake_resource_specification!(user2).id,
resource_inventoried_as: fake_economic_resource!(user2, %{name: "Previous Resourec"}).id,
to_resource_inventoried_as: fake_economic_resource!(user, %{name: "Resulting Resource"}).id
})
IO.inspect(ress: ValueFlows.Observation.EconomicResource.EconomicResources.many(agent_id: user.id))
fake_economic_event!(
user,
%{
provider: user2.id,
receiver: user.id,
action: "transfer",
input_of: fake_process!(user).id,
output_of: fake_process!(user2).id,
resource_conforms_to: fake_resource_specification!(user).id,
resource_inventoried_as: from_resource.id,
to_resource_inventoried_as: resource.id
},
unit
)
IO.inspect(event: event)
# IO.inspect(
# resource: ValueFlows.Observation.EconomicResource.EconomicResources.many(agent_id: user.id)
# )
assert queried =
CommonsPub.Web.GraphQL.QueryHelper.run_query_id(
......@@ -61,7 +84,6 @@ defmodule Valueflows.Agent.Person.GraphQLTest do
@debug
)
assert_agent(queried)
# assert_optional(assert_url(queried["image"]))
assert_intent(List.first(queried["intents"]))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment