Skip to content

Commit

Permalink
feat: set improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
deviprsd committed Sep 29, 2023
1 parent 9d1f7da commit f43bba2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
22 changes: 11 additions & 11 deletions lib/edgedb/edgeql/generator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ defmodule EdgeDB.EdgeQL.Generator do
{args, positional?} = input_codec_to_args(input_codec, query.codec_storage)
raw_shape = output_codec_to_shape(query, output_codec, query.codec_storage)
raw_schema = shape_to_schema(raw_shape)
complex = complex_shape?(raw_shape)
final_list = query.result_cardinality in [:many, :at_least_one]
complex? = complex_shape?(raw_shape)
final_list? = query.result_cardinality in [:many, :at_least_one]
types = types()

rendered_shape =
Expand Down Expand Up @@ -207,10 +207,10 @@ defmodule EdgeDB.EdgeQL.Generator do
types: types,
shape: rendered_shape,
schema: rendered_schema,
should_render_type_for_shape: rendered_schema && complex,
should_render_type_for_shape: rendered_schema && complex?,
cardinality_to_function: @cardinality_to_function,
result_type:
(complex && final_list && "list(Result.t())") || (complex && "Result.t()") ||
(complex? && final_list? && "list(Result.t())") || (complex? && "Result.t()") ||
rendered_shape,
query: %{
statement: query.statement,
Expand Down Expand Up @@ -304,7 +304,7 @@ defmodule EdgeDB.EdgeQL.Generator do
is_optional: optional?,
is_link_property: link_property?,
index: index,
registered: false
is_registered: false
},
codec_to_shape(codec, codec_storage)
)
Expand All @@ -326,14 +326,14 @@ defmodule EdgeDB.EdgeQL.Generator do
typename = "uuid()"
uuid_typespec = @builtin_scalars_to_typespecs[Codecs.UUID]
register_typespec(typename, uuid_typespec)
%{type: :builtin, typespec: typename, registered: true}
%{type: :builtin, typespec: typename, is_registered: true}
end

defp codec_to_shape(%Codecs.JSON{}, _codec_storage) do
typename = "json()"
json_typespec = @builtin_scalars_to_typespecs[Codecs.JSON]
register_typespec(typename, json_typespec)
%{type: :builtin, typespec: typename, registered: true}
%{type: :builtin, typespec: typename, is_registered: true}
end

defp codec_to_shape(%Codecs.Duration{}, _codec_storage) do
Expand All @@ -351,14 +351,14 @@ defmodule EdgeDB.EdgeQL.Generator do
register_typespec(typename, duration_typespec)
end

%{type: :builtin, typespec: typename, registered: true}
%{type: :builtin, typespec: typename, is_registered: true}
end

defp codec_to_shape(%Codecs.Vector{}, _codec_storage) do
typename = "vector()"
vector_typespec = @builtin_scalars_to_typespecs[Codecs.Vector]
register_typespec(typename, vector_typespec)
%{type: :builtin, typespec: typename, registered: true}
%{type: :builtin, typespec: typename, is_registered: true}
end

defp codec_to_shape(%codec_name{}, _codec_storage) when codec_name in @scalar_codecs do
Expand All @@ -380,14 +380,14 @@ defmodule EdgeDB.EdgeQL.Generator do

register_typespec(full_type_name, {typedoc, subcodec_typespec})

%{type: :builtin, typespec: full_type_name, registered: true}
%{type: :builtin, typespec: full_type_name, is_registered: true}
end

defp codec_to_shape(%Codecs.Enum{name: type_name, members: members}, _codec_storage) do
full_type_name = full_name_to_typespec(type_name)
typedoc = "scalar type #{type_name} extending enum<#{Enum.join(members, ", ")}>"
register_typespec(full_type_name, {typedoc, ["String.t()" | Enum.map(members, &":#{&1}")]})
%{type: :builtin, typespec: full_type_name, registered: true}
%{type: :builtin, typespec: full_type_name, is_registered: true}
end

defp codec_to_shape(%Codecs.Array{codec: subcodec}, codec_storage) do
Expand Down
2 changes: 1 addition & 1 deletion priv/codegen/templates/_builtin.eex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%= if @builtin[:is_list] do %>list(<% end %>
<%= if @builtin[:registered] do %><%= @module_name %>.<% end %><%= @builtin.typespec %>
<%= if @builtin[:is_registered] do %><%= @module_name %>.<% end %><%= @builtin.typespec %>
<%= if @builtin[:is_list] do %>)<% end %>
<%= if @builtin[:is_optional] do %>
| nil
Expand Down
1 change: 1 addition & 0 deletions priv/codegen/templates/_object.eex
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
end;
<% %{type: :set} -> %>
defmodule <%= Macro.camelize(name) %> do
<%= if field.shape[:type] == :builtin do %>@type t() ::<% end %>
<%= @render_set.(
set: field,
render_shape: @render_shape,
Expand Down
2 changes: 1 addition & 1 deletion priv/codegen/templates/_schema.eex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
paths: @paths ++ [name])
%>,
<% {name, schema} -> %>
<%= name %>: %Result.<%= Macro.camelize(name) %><%= @render_schema.(
<%= name %>: %Result.<%= Enum.map_join(@paths ++ [name],".", &(Macro.camelize(&1))) %><%= @render_schema.(
schema: schema,
render_schema: @render_schema,
paths: @paths ++ [name])
Expand Down

0 comments on commit f43bba2

Please sign in to comment.