Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the dedicated listVariables endpoint and start using executeGql wrapper #263

Merged
merged 2 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/graphql/Variable/Variable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,8 @@ mutation sdk_add_variables(\$variablesToCreate: [VariableCreateInput!]!) {
"""

GQL_LIST_VARIABLES = GQL.gql"""
query list_variables($fgId: ID!, $varwhere: VariableWhere = {}) {
factorgraphs(where: { id: $fgId }) {
variables (where: $varwhere){
label
}
}
query list_variables($fgId: ID!, $varwhere: ListWhere = {}) {
listVariables(fgId: $fgId, where: $varwhere)
}
"""

Expand Down
33 changes: 6 additions & 27 deletions src/services/Agent.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,7 @@ function getAgent(client::NavAbilityClient, label::Symbol)

T = Vector{NvaNode{Agent}}

response = GQL.execute(
client.client,
QUERY_GET_AGENT,
T;
variables,
throw_on_execution_error = true,
)
response = executeGql(client, QUERY_GET_AGENT, variables, T)

return handleQuery(response, "agents", label)
end
Expand Down Expand Up @@ -55,13 +49,7 @@ function addAgent!(client::NavAbilityClient, label::Symbol, agent = nothing; age
# AgentRemoteResponse
T = @NamedTuple{agents::Vector{NvaNode{Agent}}}

response = GQL.execute(
client.client,
GQL_ADD_AGENTS,
T;
variables,
throw_on_execution_error = true,
)
response = executeGql(client, GQL_ADD_AGENTS, variables, T)

return handleMutate(response, "addAgents", :agents)[1]
end
Expand All @@ -81,13 +69,7 @@ function listAgents(client::NavAbilityClient)

T = Vector{Dict{String, Vector{@NamedTuple{label::Symbol}}}}

response = GQL.execute(
client.client,
QUERY_LIST_AGENTS,
T;
variables,
throw_on_execution_error = true,
)
response = executeGql(client, QUERY_LIST_AGENTS, variables, T)

return last.(handleQuery(response, "orgs", Symbol(client.id))["agents"])
end
Expand All @@ -102,12 +84,9 @@ query getAgentMetadata($id: ID!) {

function DFG.getAgentMetadata(fgclient::NavAbilityDFG)
variables = (id = getId(fgclient.agent),)
response = GQL.execute(
fgclient.client.client,
QUERY_GET_AGENT_METADATA;
variables,
throw_on_execution_error = true,
)

response = executeGql(fgclient, QUERY_GET_AGENT_METADATA, variables, Any)

b64data = handleQuery(response, "agents", fgclient.agent.label)["metadata"]
if isnothing(b64data)
return Dict{Symbol, DFG.SmallDataTypes}()
Expand Down
42 changes: 11 additions & 31 deletions src/services/BlobEntry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@ function getBlobEntry(fgclient::NavAbilityDFG, variableLabel::Symbol, label::Sym

T = Vector{DFG.BlobEntry}

response = GQL.execute(
fgclient.client.client,
GQL_GET_BLOBENTRY,
T;
variables=(id=id,),
throw_on_execution_error = true,
)
response = executeGql(fgclient, GQL_GET_BLOBENTRY, (id=id,), T)

return handleQuery(response, "blobEntries", label)
end
Expand Down Expand Up @@ -202,14 +196,8 @@ function addBlobEntries!(

T = @NamedTuple{blobEntries::Vector{BlobEntry}}

response = GQL.execute(
fgclient.client.client,
GQL_ADD_BLOBENTRIES,
T; #FIXME BlobEntryResponse
# BlobEntryResponse;
variables = (blobEntries=input,),
throw_on_execution_error = true,
)
response = executeGql(fgclient, GQL_ADD_BLOBENTRIES, (blobEntries=input,), T)

return handleMutate(response, "addBlobEntries", :blobEntries)

end
Expand All @@ -230,33 +218,25 @@ function DFG.listGraphBlobEntries(fgclient::NavAbilityDFG)

T = Vector{Dict{String, Vector{@NamedTuple{label::Symbol}}}}

response = GQL.execute(
fgclient.client.client,
GQL_LIST_FACTORGRAPH_BLOBENTRIES,
T;
variables,
throw_on_execution_error = true,
)
response = executeGql(fgclient, GQL_LIST_FACTORGRAPH_BLOBENTRIES, variables, T)

return last.(handleQuery(response, "factorgraphs", fgclient.fg.label)["blobEntries"])

end

function DFG.listAgentBlobEntries(fgclient::NavAbilityDFG)
getAgentBlobEntries(fgclient.client, fgclient.agent)
end

variables = (id=getId(fgclient.agent),)
function DFG.listAgentBlobEntries(client::NavAbilityClient, agent::NvaNode{Agent})

variables = (id=getId(agent),)

T = Vector{Dict{String, Vector{@NamedTuple{label::Symbol}}}}

response = GQL.execute(
fgclient.client.client,
GQL_LIST_AGENT_BLOBENTRIES,
T;
variables,
throw_on_execution_error = true,
)
response = executeGql(client, GQL_LIST_AGENT_BLOBENTRIES, variables, T)

return last.(handleQuery(response, "agents", fgclient.agent.label)["blobEntries"])
return last.(handleQuery(response, "agents", agent.label)["blobEntries"])

end

Expand Down
15 changes: 15 additions & 0 deletions src/services/Common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@ function getCommonProperties(::Type{T}, from::F, exclude = Symbol[]) where {T, F
return (k => getproperty(from, k) for k in commonfields)
end

#TODO update all GQL.execute calls to use this
function executeGql(cfg::NavAbilityDFG, query::AbstractString, variables, T::Type; kwargs...)
executeGql(cfg.client, query, variables, T; kwargs...)
end

function executeGql(client::NavAbilityClient, query::AbstractString, variables, T::Type; throw_on_execution_error = true, kwargs...)
return GQL.execute(
client.client,
query,
T;
variables,
throw_on_execution_error,
)
end

function handleQuery(response, nodeName::String, label::Symbol)
res = isnothing(response.data) ? nothing : get(response.data, nodeName, nothing)
if isnothing(res)
Expand Down
50 changes: 31 additions & 19 deletions src/services/Variable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -187,38 +187,50 @@ end
function listVariables(fgclient::NavAbilityDFG,
regexFilter::Union{Nothing, Regex} = nothing;
tags::Vector{Symbol} = Symbol[],
solvable::Int = 0
solvable::Union{Int, Nothing} = nothing,
solvableFilter::Union{Nothing, Base.Fix2} = isnothing(solvable) ? nothing : >=(solvable),
typeFilter::Union{Nothing, Type{<:InferenceVariable}} = nothing,
)
#TODO deprecate solvable "solvable::Int is deprecated, use solvableFilter = >=(solvable) instead"
!isnothing(typeFilter) && @warn("typeFilter is not implemented yet")

fgId = NvaSDK.getId(fgclient.fg)

variables = Dict(
"fgId" => fgId,
"varwhere" => Dict{String,Union{Int, Symbol}}(
"solvable_GTE" => solvable,
"varwhere" => Dict{String,Union{Int, Vector{Int}, Symbol}}(
),
)

if !isempty(tags)
@assert length(tags) == 1 "Only one tag is supported in tags filter"
@assert length(tags) == 1 "Only one tag is currently supported in tags filter"
variables["varwhere"]["tags_INCLUDES"]=tags[1]
end

T = Vector{Dict{String, Vector{@NamedTuple{label::Symbol}}}}
if !isnothing(solvableFilter)
if solvableFilter.f == >=
variables["varwhere"]["solvable_GTE"] = solvableFilter.x
elseif solvableFilter.f == >
variables["varwhere"]["solvable_GT"] = solvableFilter.x
elseif solvableFilter.f == <=
variables["varwhere"]["solvable_LTE"] = solvableFilter.x
elseif solvableFilter.f == <
variables["varwhere"]["solvable_LT"] = solvableFilter.x
elseif solvableFilter.f == ==
variables["varwhere"]["solvable"] = solvableFilter.x
elseif solvableFilter.f == in
variables["varwhere"]["solvable_IN"] = solvableFilter.x
else
error("Unsupported solvableFilter function: $(solvableFilter.f)")
end
end

response = GQL.execute(
fgclient.client.client,
GQL_LIST_VARIABLES,
T;
variables,
throw_on_execution_error = true,
)
response = executeGql(fgclient, GQL_LIST_VARIABLES_DIRECT, variables, Vector{Symbol})
labels = handleQuery(response, "listVariables")

labels = last.(handleQuery(response, "factorgraphs", fgclient.fg.label)["variables"])
if isnothing(regexFilter)
return labels
else
return filter!(x -> occursin(regexFilter, string(x)), labels)
end
!isnothing(regexFilter) &&
filter!(x -> occursin(regexFilter, string(x)), labels)

return labels
end

function getVariable(fgclient::NavAbilityDFG{VT, <:AbstractDFGFactor}, label::Symbol) where VT
Expand Down
Loading