Current section
Files
Jump to
Current section
Files
src/mochi@introspection.erl
-module(mochi@introspection).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/mochi/introspection.gleam").
-export([get_introspection_schema_type/0, get_introspection_type_type/0, get_introspection_object_type/1, build_field_type_introspection/2, build_type_introspection/2, build_schema_introspection/1]).
-file("src/mochi/introspection.gleam", 222).
-spec field_def(binary(), mochi@schema:field_type()) -> mochi@schema:field_definition().
field_def(Name, Field_type) ->
{field_definition,
Name,
none,
Field_type,
maps:new(),
none,
false,
none,
none,
none}.
-file("src/mochi/introspection.gleam", 25).
-spec get_introspection_schema_type() -> mochi@schema:object_type().
get_introspection_schema_type() ->
{object_type,
<<"__Schema"/utf8>>,
{some,
<<"A GraphQL Schema defines the capabilities of a GraphQL server."/utf8>>},
maps:from_list(
[{<<"description"/utf8>>,
field_def(
<<"description"/utf8>>,
{named, <<"String"/utf8>>}
)},
{<<"types"/utf8>>,
field_def(
<<"types"/utf8>>,
{non_null,
{list, {non_null, {named, <<"__Type"/utf8>>}}}}
)},
{<<"queryType"/utf8>>,
field_def(
<<"queryType"/utf8>>,
{non_null, {named, <<"__Type"/utf8>>}}
)},
{<<"mutationType"/utf8>>,
field_def(
<<"mutationType"/utf8>>,
{named, <<"__Type"/utf8>>}
)},
{<<"subscriptionType"/utf8>>,
field_def(
<<"subscriptionType"/utf8>>,
{named, <<"__Type"/utf8>>}
)},
{<<"directives"/utf8>>,
field_def(
<<"directives"/utf8>>,
{non_null,
{list, {non_null, {named, <<"__Directive"/utf8>>}}}}
)}]
),
[]}.
-file("src/mochi/introspection.gleam", 117).
-spec get_introspection_field_type() -> mochi@schema:object_type().
get_introspection_field_type() ->
{object_type,
<<"__Field"/utf8>>,
{some,
<<"Object and Interface types are described by a list of Fields."/utf8>>},
maps:from_list(
[{<<"name"/utf8>>,
field_def(
<<"name"/utf8>>,
{non_null, {named, <<"String"/utf8>>}}
)},
{<<"description"/utf8>>,
field_def(
<<"description"/utf8>>,
{named, <<"String"/utf8>>}
)},
{<<"args"/utf8>>,
field_def(
<<"args"/utf8>>,
{non_null,
{list, {non_null, {named, <<"__InputValue"/utf8>>}}}}
)},
{<<"type"/utf8>>,
field_def(
<<"type"/utf8>>,
{non_null, {named, <<"__Type"/utf8>>}}
)},
{<<"isDeprecated"/utf8>>,
field_def(
<<"isDeprecated"/utf8>>,
{non_null, {named, <<"Boolean"/utf8>>}}
)},
{<<"deprecationReason"/utf8>>,
field_def(
<<"deprecationReason"/utf8>>,
{named, <<"String"/utf8>>}
)}]
),
[]}.
-file("src/mochi/introspection.gleam", 149).
-spec get_introspection_input_value_type() -> mochi@schema:object_type().
get_introspection_input_value_type() ->
{object_type,
<<"__InputValue"/utf8>>,
{some, <<"Arguments provided to Fields or Directives."/utf8>>},
maps:from_list(
[{<<"name"/utf8>>,
field_def(
<<"name"/utf8>>,
{non_null, {named, <<"String"/utf8>>}}
)},
{<<"description"/utf8>>,
field_def(
<<"description"/utf8>>,
{named, <<"String"/utf8>>}
)},
{<<"type"/utf8>>,
field_def(
<<"type"/utf8>>,
{non_null, {named, <<"__Type"/utf8>>}}
)},
{<<"defaultValue"/utf8>>,
field_def(
<<"defaultValue"/utf8>>,
{named, <<"String"/utf8>>}
)},
{<<"isDeprecated"/utf8>>,
field_def(
<<"isDeprecated"/utf8>>,
{named, <<"Boolean"/utf8>>}
)},
{<<"deprecationReason"/utf8>>,
field_def(
<<"deprecationReason"/utf8>>,
{named, <<"String"/utf8>>}
)}]
),
[]}.
-file("src/mochi/introspection.gleam", 168).
-spec get_introspection_enum_value_type() -> mochi@schema:object_type().
get_introspection_enum_value_type() ->
{object_type,
<<"__EnumValue"/utf8>>,
{some, <<"One possible value for a given Enum."/utf8>>},
maps:from_list(
[{<<"name"/utf8>>,
field_def(
<<"name"/utf8>>,
{non_null, {named, <<"String"/utf8>>}}
)},
{<<"description"/utf8>>,
field_def(
<<"description"/utf8>>,
{named, <<"String"/utf8>>}
)},
{<<"isDeprecated"/utf8>>,
field_def(
<<"isDeprecated"/utf8>>,
{non_null, {named, <<"Boolean"/utf8>>}}
)},
{<<"deprecationReason"/utf8>>,
field_def(
<<"deprecationReason"/utf8>>,
{named, <<"String"/utf8>>}
)}]
),
[]}.
-file("src/mochi/introspection.gleam", 188).
-spec get_introspection_directive_type() -> mochi@schema:object_type().
get_introspection_directive_type() ->
{object_type,
<<"__Directive"/utf8>>,
{some,
<<"A Directive provides a way to describe alternate runtime execution."/utf8>>},
maps:from_list(
[{<<"name"/utf8>>,
field_def(
<<"name"/utf8>>,
{non_null, {named, <<"String"/utf8>>}}
)},
{<<"description"/utf8>>,
field_def(
<<"description"/utf8>>,
{named, <<"String"/utf8>>}
)},
{<<"isRepeatable"/utf8>>,
field_def(
<<"isRepeatable"/utf8>>,
{non_null, {named, <<"Boolean"/utf8>>}}
)},
{<<"locations"/utf8>>,
field_def(
<<"locations"/utf8>>,
{non_null,
{list, {non_null, {named, <<"String"/utf8>>}}}}
)},
{<<"args"/utf8>>,
field_def(
<<"args"/utf8>>,
{non_null,
{list, {non_null, {named, <<"__InputValue"/utf8>>}}}}
)}]
),
[]}.
-file("src/mochi/introspection.gleam", 239).
-spec field_def_with_include_deprecated(
binary(),
binary(),
binary(),
mochi@schema:field_type()
) -> mochi@schema:field_definition().
field_def_with_include_deprecated(
Field_name,
Data_key,
All_data_key,
Field_type
) ->
{field_definition,
Field_name,
none,
Field_type,
maps:from_list(
[{<<"includeDeprecated"/utf8>>,
{argument_definition,
<<"includeDeprecated"/utf8>>,
none,
mochi@schema:boolean_type(),
{some, gleam_stdlib:identity(false)}}}]
),
{some,
fun(Info) ->
Include_deprecated = begin
_pipe = gleam_stdlib:map_get(
erlang:element(3, Info),
<<"includeDeprecated"/utf8>>
),
_pipe@2 = gleam@result:'try'(
_pipe,
fun(V) ->
_pipe@1 = gleam@dynamic@decode:run(
V,
{decoder,
fun gleam@dynamic@decode:decode_bool/1}
),
gleam@result:map_error(_pipe@1, fun(_) -> nil end)
end
),
gleam@result:unwrap(_pipe@2, false)
end,
case erlang:element(2, Info) of
none ->
{ok, gleam_stdlib:identity(nil)};
{some, Parent} ->
case Include_deprecated of
true ->
_pipe@3 = gleam@dynamic@decode:run(
Parent,
gleam@dynamic@decode:at(
[All_data_key],
{decoder,
fun gleam@dynamic@decode:decode_dynamic/1}
)
),
gleam@result:map_error(
_pipe@3,
fun(_) ->
<<"Cannot read "/utf8,
All_data_key/binary>>
end
);
false ->
_pipe@4 = gleam@dynamic@decode:run(
Parent,
gleam@dynamic@decode:at(
[Data_key],
{decoder,
fun gleam@dynamic@decode:decode_dynamic/1}
)
),
gleam@result:map_error(
_pipe@4,
fun(_) ->
<<"Cannot read "/utf8, Data_key/binary>>
end
)
end
end
end},
false,
none,
none,
none}.
-file("src/mochi/introspection.gleam", 63).
-spec get_introspection_type_type() -> mochi@schema:object_type().
get_introspection_type_type() ->
{object_type,
<<"__Type"/utf8>>,
{some,
<<"The fundamental unit of any GraphQL Schema is the type."/utf8>>},
maps:from_list(
[{<<"kind"/utf8>>,
field_def(
<<"kind"/utf8>>,
{non_null, {named, <<"String"/utf8>>}}
)},
{<<"name"/utf8>>,
field_def(<<"name"/utf8>>, {named, <<"String"/utf8>>})},
{<<"description"/utf8>>,
field_def(
<<"description"/utf8>>,
{named, <<"String"/utf8>>}
)},
{<<"specifiedByURL"/utf8>>,
field_def(
<<"specifiedByURL"/utf8>>,
{named, <<"String"/utf8>>}
)},
{<<"fields"/utf8>>,
field_def_with_include_deprecated(
<<"fields"/utf8>>,
<<"fields"/utf8>>,
<<"__fields_all"/utf8>>,
{list, {non_null, {named, <<"__Field"/utf8>>}}}
)},
{<<"interfaces"/utf8>>,
field_def(
<<"interfaces"/utf8>>,
{list, {non_null, {named, <<"__Type"/utf8>>}}}
)},
{<<"possibleTypes"/utf8>>,
field_def(
<<"possibleTypes"/utf8>>,
{list, {non_null, {named, <<"__Type"/utf8>>}}}
)},
{<<"enumValues"/utf8>>,
field_def_with_include_deprecated(
<<"enumValues"/utf8>>,
<<"enumValues"/utf8>>,
<<"__enumValues_all"/utf8>>,
{list, {non_null, {named, <<"__EnumValue"/utf8>>}}}
)},
{<<"inputFields"/utf8>>,
field_def(
<<"inputFields"/utf8>>,
{list, {non_null, {named, <<"__InputValue"/utf8>>}}}
)},
{<<"ofType"/utf8>>,
field_def(<<"ofType"/utf8>>, {named, <<"__Type"/utf8>>})}]
),
[]}.
-file("src/mochi/introspection.gleam", 13).
-spec get_introspection_object_type(binary()) -> gleam@option:option(mochi@schema:object_type()).
get_introspection_object_type(Name) ->
case Name of
<<"__Schema"/utf8>> ->
{some, get_introspection_schema_type()};
<<"__Type"/utf8>> ->
{some, get_introspection_type_type()};
<<"__Field"/utf8>> ->
{some, get_introspection_field_type()};
<<"__InputValue"/utf8>> ->
{some, get_introspection_input_value_type()};
<<"__EnumValue"/utf8>> ->
{some, get_introspection_enum_value_type()};
<<"__Directive"/utf8>> ->
{some, get_introspection_directive_type()};
_ ->
none
end.
-file("src/mochi/introspection.gleam", 371).
-spec build_builtin_directive(
binary(),
binary(),
list(binary()),
list(gleam@dynamic:dynamic_())
) -> gleam@dynamic:dynamic_().
build_builtin_directive(Name, Description, Locations, Args) ->
gleam_stdlib:identity(
maps:from_list(
[{<<"name"/utf8>>, gleam_stdlib:identity(Name)},
{<<"description"/utf8>>, gleam_stdlib:identity(Description)},
{<<"locations"/utf8>>,
gleam_stdlib:identity(
gleam@list:map(Locations, fun gleam_stdlib:identity/1)
)},
{<<"args"/utf8>>, gleam_stdlib:identity(Args)},
{<<"isRepeatable"/utf8>>, gleam_stdlib:identity(false)}]
)
).
-file("src/mochi/introspection.gleam", 515).
-spec get_all_type_names(mochi@schema:schema()) -> list(binary()).
get_all_type_names(Schema_def) ->
Builtin = [<<"String"/utf8>>,
<<"Int"/utf8>>,
<<"Float"/utf8>>,
<<"Boolean"/utf8>>,
<<"ID"/utf8>>],
Introspection = [<<"__Schema"/utf8>>,
<<"__Type"/utf8>>,
<<"__Field"/utf8>>,
<<"__InputValue"/utf8>>,
<<"__EnumValue"/utf8>>,
<<"__Directive"/utf8>>,
<<"__DirectiveLocation"/utf8>>,
<<"__TypeKind"/utf8>>],
User_types = maps:keys(erlang:element(5, Schema_def)),
Root_types = begin
_pipe = [erlang:element(2, Schema_def),
erlang:element(3, Schema_def),
erlang:element(4, Schema_def)],
gleam@list:filter_map(
_pipe,
fun(Opt) ->
_pipe@1 = gleam@option:map(
Opt,
fun(O) -> erlang:element(2, O) end
),
gleam@option:to_result(_pipe@1, nil)
end
)
end,
_pipe@2 = lists:append([Builtin, User_types, Root_types, Introspection]),
gleam@list:unique(_pipe@2).
-file("src/mochi/introspection.gleam", 563).
-spec get_scalar_description(binary()) -> binary().
get_scalar_description(Name) ->
case Name of
<<"String"/utf8>> ->
<<"The String scalar type represents textual data"/utf8>>;
<<"Int"/utf8>> ->
<<"The Int scalar type represents non-fractional signed whole numeric values"/utf8>>;
<<"Float"/utf8>> ->
<<"The Float scalar type represents signed double-precision fractional values"/utf8>>;
<<"Boolean"/utf8>> ->
<<"The Boolean scalar type represents true or false"/utf8>>;
<<"ID"/utf8>> ->
<<"The ID scalar type represents a unique identifier"/utf8>>;
_ ->
<<""/utf8>>
end.
-file("src/mochi/introspection.gleam", 653).
-spec build_enum_values(mochi@schema:enum_type(), boolean()) -> list(gleam@dynamic:dynamic_()).
build_enum_values(Enum, Include_deprecated) ->
_pipe = maps:to_list(erlang:element(4, Enum)),
_pipe@1 = gleam@list:filter(
_pipe,
fun(Kv) ->
{_, Def} = Kv,
Include_deprecated orelse not erlang:element(5, Def)
end
),
gleam@list:map(
_pipe@1,
fun(Kv@1) ->
{Name, Def@1} = Kv@1,
gleam_stdlib:identity(
maps:from_list(
[{<<"name"/utf8>>, gleam_stdlib:identity(Name)},
{<<"description"/utf8>>,
gleam_stdlib:identity(
gleam@option:unwrap(
erlang:element(3, Def@1),
<<""/utf8>>
)
)},
{<<"isDeprecated"/utf8>>,
gleam_stdlib:identity(erlang:element(5, Def@1))},
{<<"deprecationReason"/utf8>>,
case erlang:element(6, Def@1) of
{some, Reason} ->
gleam_stdlib:identity(Reason);
none ->
gleam_stdlib:identity(nil)
end}]
)
)
end
).
-file("src/mochi/introspection.gleam", 734).
-spec build_union_introspection(
mochi@schema:schema(),
mochi@schema:union_type()
) -> gleam@dynamic:dynamic_().
build_union_introspection(Schema_def, Union) ->
Possible = gleam@list:map(
erlang:element(4, Union),
fun(T) ->
gleam_stdlib:identity(
maps:from_list(
[{<<"kind"/utf8>>, gleam_stdlib:identity(<<"OBJECT"/utf8>>)},
{<<"name"/utf8>>,
gleam_stdlib:identity(erlang:element(2, T))},
{<<"ofType"/utf8>>, gleam_stdlib:identity(nil)}]
)
)
end
),
_ = Schema_def,
gleam_stdlib:identity(
maps:from_list(
[{<<"kind"/utf8>>, gleam_stdlib:identity(<<"UNION"/utf8>>)},
{<<"name"/utf8>>,
gleam_stdlib:identity(erlang:element(2, Union))},
{<<"description"/utf8>>,
gleam_stdlib:identity(
gleam@option:unwrap(
erlang:element(3, Union),
<<""/utf8>>
)
)},
{<<"possibleTypes"/utf8>>, gleam_stdlib:identity(Possible)},
{<<"fields"/utf8>>, gleam_stdlib:identity(nil)},
{<<"interfaces"/utf8>>, gleam_stdlib:identity(nil)},
{<<"enumValues"/utf8>>, gleam_stdlib:identity(nil)},
{<<"inputFields"/utf8>>, gleam_stdlib:identity(nil)},
{<<"ofType"/utf8>>, gleam_stdlib:identity(nil)}]
)
).
-file("src/mochi/introspection.gleam", 832).
-spec make_type_object(
binary(),
binary(),
binary(),
gleam@option:option(list(gleam@dynamic:dynamic_())),
gleam@option:option(list(gleam@dynamic:dynamic_())),
gleam@option:option(list(gleam@dynamic:dynamic_())),
gleam@option:option(list(gleam@dynamic:dynamic_())),
gleam@option:option(list(gleam@dynamic:dynamic_())),
gleam@option:option(list(gleam@dynamic:dynamic_())),
gleam@option:option(list(gleam@dynamic:dynamic_()))
) -> gleam@dynamic:dynamic_().
make_type_object(
Kind,
Name,
Description,
Fields,
Fields_all,
Interfaces,
Enum_values,
Enum_values_all,
Input_fields,
Possible_types
) ->
gleam_stdlib:identity(
maps:from_list(
[{<<"kind"/utf8>>, gleam_stdlib:identity(Kind)},
{<<"name"/utf8>>, gleam_stdlib:identity(Name)},
{<<"description"/utf8>>, gleam_stdlib:identity(Description)},
{<<"fields"/utf8>>,
begin
_pipe = gleam@option:map(
Fields,
fun gleam_stdlib:identity/1
),
gleam@option:unwrap(_pipe, gleam_stdlib:identity(nil))
end},
{<<"__fields_all"/utf8>>,
begin
_pipe@1 = gleam@option:map(
Fields_all,
fun gleam_stdlib:identity/1
),
gleam@option:unwrap(_pipe@1, gleam_stdlib:identity(nil))
end},
{<<"interfaces"/utf8>>,
begin
_pipe@2 = gleam@option:map(
Interfaces,
fun gleam_stdlib:identity/1
),
gleam@option:unwrap(_pipe@2, gleam_stdlib:identity(nil))
end},
{<<"possibleTypes"/utf8>>,
begin
_pipe@3 = gleam@option:map(
Possible_types,
fun gleam_stdlib:identity/1
),
gleam@option:unwrap(_pipe@3, gleam_stdlib:identity(nil))
end},
{<<"enumValues"/utf8>>,
begin
_pipe@4 = gleam@option:map(
Enum_values,
fun gleam_stdlib:identity/1
),
gleam@option:unwrap(_pipe@4, gleam_stdlib:identity(nil))
end},
{<<"__enumValues_all"/utf8>>,
begin
_pipe@5 = gleam@option:map(
Enum_values_all,
fun gleam_stdlib:identity/1
),
gleam@option:unwrap(_pipe@5, gleam_stdlib:identity(nil))
end},
{<<"inputFields"/utf8>>,
begin
_pipe@6 = gleam@option:map(
Input_fields,
fun gleam_stdlib:identity/1
),
gleam@option:unwrap(_pipe@6, gleam_stdlib:identity(nil))
end},
{<<"ofType"/utf8>>, gleam_stdlib:identity(nil)}]
)
).
-file("src/mochi/introspection.gleam", 548).
-spec build_scalar_introspection(binary()) -> gleam@dynamic:dynamic_().
build_scalar_introspection(Name) ->
make_type_object(
<<"SCALAR"/utf8>>,
Name,
get_scalar_description(Name),
none,
none,
none,
none,
none,
none,
none
).
-file("src/mochi/introspection.gleam", 678).
-spec build_enum_introspection(mochi@schema:enum_type()) -> gleam@dynamic:dynamic_().
build_enum_introspection(Enum) ->
make_type_object(
<<"ENUM"/utf8>>,
erlang:element(2, Enum),
gleam@option:unwrap(erlang:element(3, Enum), <<""/utf8>>),
none,
none,
none,
{some, build_enum_values(Enum, false)},
{some, build_enum_values(Enum, true)},
none,
none
).
-file("src/mochi/introspection.gleam", 795).
-spec build_meta_type_introspection(binary()) -> gleam@dynamic:dynamic_().
build_meta_type_introspection(Name) ->
case Name of
<<"__Schema"/utf8>> ->
make_type_object(
<<"OBJECT"/utf8>>,
Name,
<<"Introspection type"/utf8>>,
{some, []},
{some, []},
{some, []},
none,
none,
none,
none
);
<<"__Type"/utf8>> ->
make_type_object(
<<"OBJECT"/utf8>>,
Name,
<<"Introspection type"/utf8>>,
{some, []},
{some, []},
{some, []},
none,
none,
none,
none
);
<<"__Field"/utf8>> ->
make_type_object(
<<"OBJECT"/utf8>>,
Name,
<<"Introspection type"/utf8>>,
{some, []},
{some, []},
{some, []},
none,
none,
none,
none
);
<<"__InputValue"/utf8>> ->
make_type_object(
<<"OBJECT"/utf8>>,
Name,
<<"Introspection type"/utf8>>,
{some, []},
{some, []},
{some, []},
none,
none,
none,
none
);
<<"__EnumValue"/utf8>> ->
make_type_object(
<<"OBJECT"/utf8>>,
Name,
<<"Introspection type"/utf8>>,
{some, []},
{some, []},
{some, []},
none,
none,
none,
none
);
<<"__Directive"/utf8>> ->
make_type_object(
<<"OBJECT"/utf8>>,
Name,
<<"Introspection type"/utf8>>,
{some, []},
{some, []},
{some, []},
none,
none,
none,
none
);
<<"__TypeKind"/utf8>> ->
make_type_object(
<<"ENUM"/utf8>>,
Name,
<<"Introspection enum"/utf8>>,
none,
none,
none,
{some, []},
{some, []},
none,
none
);
<<"__DirectiveLocation"/utf8>> ->
make_type_object(
<<"ENUM"/utf8>>,
Name,
<<"Introspection enum"/utf8>>,
none,
none,
none,
{some, []},
{some, []},
none,
none
);
_ ->
gleam_stdlib:identity(nil)
end.
-file("src/mochi/introspection.gleam", 936).
-spec serialize_default_value(gleam@option:option(gleam@dynamic:dynamic_())) -> gleam@dynamic:dynamic_().
serialize_default_value(Default_value) ->
case Default_value of
none ->
gleam_stdlib:identity(nil);
{some, V} ->
case mochi@output:from_dynamic(V) of
{ok, {v_string, S}} ->
gleam_stdlib:identity(S);
{ok, {v_int, I}} ->
gleam_stdlib:identity(erlang:integer_to_binary(I));
{ok, {v_float, F}} ->
gleam_stdlib:identity(gleam_stdlib:float_to_string(F));
{ok, {v_bool, true}} ->
gleam_stdlib:identity(<<"true"/utf8>>);
{ok, {v_bool, false}} ->
gleam_stdlib:identity(<<"false"/utf8>>);
{ok, v_null} ->
gleam_stdlib:identity(nil);
{ok, _} ->
gleam_stdlib:identity(nil);
{error, _} ->
gleam_stdlib:identity(nil)
end
end.
-file("src/mochi/introspection.gleam", 990).
-spec get_type_kind(mochi@schema:schema(), binary()) -> binary().
get_type_kind(Schema_def, Name) ->
case Name of
<<"String"/utf8>> ->
<<"SCALAR"/utf8>>;
<<"Int"/utf8>> ->
<<"SCALAR"/utf8>>;
<<"Float"/utf8>> ->
<<"SCALAR"/utf8>>;
<<"Boolean"/utf8>> ->
<<"SCALAR"/utf8>>;
<<"ID"/utf8>> ->
<<"SCALAR"/utf8>>;
_ ->
case gleam_stdlib:map_get(erlang:element(5, Schema_def), Name) of
{ok, {object_type_def, _}} ->
<<"OBJECT"/utf8>>;
{ok, {scalar_type_def, _}} ->
<<"SCALAR"/utf8>>;
{ok, {enum_type_def, _}} ->
<<"ENUM"/utf8>>;
{ok, {interface_type_def, _}} ->
<<"INTERFACE"/utf8>>;
{ok, {union_type_def, _}} ->
<<"UNION"/utf8>>;
{ok, {input_object_type_def, _}} ->
<<"INPUT_OBJECT"/utf8>>;
{error, _} ->
case begin
_pipe = [erlang:element(2, Schema_def),
erlang:element(3, Schema_def),
erlang:element(4, Schema_def)],
gleam@list:find(
_pipe,
fun(Opt) ->
_pipe@1 = gleam@option:map(
Opt,
fun(O) -> erlang:element(2, O) =:= Name end
),
gleam@option:unwrap(_pipe@1, false)
end
)
end of
{ok, _} ->
<<"OBJECT"/utf8>>;
{error, _} ->
<<"OBJECT"/utf8>>
end
end
end.
-file("src/mochi/introspection.gleam", 958).
-spec build_field_type_introspection(
mochi@schema:schema(),
mochi@schema:field_type()
) -> gleam@dynamic:dynamic_().
build_field_type_introspection(Schema_def, Field_type) ->
case Field_type of
{non_null, Inner} ->
gleam_stdlib:identity(
maps:from_list(
[{<<"kind"/utf8>>,
gleam_stdlib:identity(<<"NON_NULL"/utf8>>)},
{<<"name"/utf8>>, gleam_stdlib:identity(nil)},
{<<"ofType"/utf8>>,
build_field_type_introspection(Schema_def, Inner)}]
)
);
{list, Inner@1} ->
gleam_stdlib:identity(
maps:from_list(
[{<<"kind"/utf8>>, gleam_stdlib:identity(<<"LIST"/utf8>>)},
{<<"name"/utf8>>, gleam_stdlib:identity(nil)},
{<<"ofType"/utf8>>,
build_field_type_introspection(Schema_def, Inner@1)}]
)
);
{named, Name} ->
gleam_stdlib:identity(
maps:from_list(
[{<<"kind"/utf8>>,
gleam_stdlib:identity(
get_type_kind(Schema_def, Name)
)},
{<<"name"/utf8>>, gleam_stdlib:identity(Name)},
{<<"ofType"/utf8>>, gleam_stdlib:identity(nil)}]
)
)
end.
-file("src/mochi/introspection.gleam", 326).
-spec build_directive_introspection(
mochi@schema:schema(),
mochi@schema:directive_definition()
) -> gleam@dynamic:dynamic_().
build_directive_introspection(Schema_def, Directive) ->
Args = begin
_pipe = erlang:element(4, Directive),
_pipe@1 = maps:to_list(_pipe),
gleam@list:map(
_pipe@1,
fun(Kv) ->
{Arg_name, Arg_def} = Kv,
gleam_stdlib:identity(
maps:from_list(
[{<<"name"/utf8>>, gleam_stdlib:identity(Arg_name)},
{<<"description"/utf8>>,
gleam_stdlib:identity(
gleam@option:unwrap(
erlang:element(3, Arg_def),
<<""/utf8>>
)
)},
{<<"type"/utf8>>,
build_field_type_introspection(
Schema_def,
erlang:element(4, Arg_def)
)},
{<<"defaultValue"/utf8>>,
gleam_stdlib:identity(nil)}]
)
)
end
)
end,
Locations = begin
_pipe@2 = erlang:element(5, Directive),
gleam@list:map(
_pipe@2,
fun(Loc) ->
gleam_stdlib:identity(
mochi@schema:directive_location_to_string(Loc)
)
end
)
end,
gleam_stdlib:identity(
maps:from_list(
[{<<"name"/utf8>>,
gleam_stdlib:identity(erlang:element(2, Directive))},
{<<"description"/utf8>>,
gleam_stdlib:identity(
gleam@option:unwrap(
erlang:element(3, Directive),
<<""/utf8>>
)
)},
{<<"locations"/utf8>>, gleam_stdlib:identity(Locations)},
{<<"args"/utf8>>, gleam_stdlib:identity(Args)},
{<<"isRepeatable"/utf8>>,
gleam_stdlib:identity(erlang:element(6, Directive))}]
)
).
-file("src/mochi/introspection.gleam", 388).
-spec make_bool_arg(
mochi@schema:schema(),
binary(),
binary(),
gleam@dynamic:dynamic_()
) -> gleam@dynamic:dynamic_().
make_bool_arg(Schema_def, Name, Description, Default_value) ->
gleam_stdlib:identity(
maps:from_list(
[{<<"name"/utf8>>, gleam_stdlib:identity(Name)},
{<<"description"/utf8>>, gleam_stdlib:identity(Description)},
{<<"type"/utf8>>,
build_field_type_introspection(
Schema_def,
{non_null, {named, <<"Boolean"/utf8>>}}
)},
{<<"defaultValue"/utf8>>, Default_value}]
)
).
-file("src/mochi/introspection.gleam", 410).
-spec make_string_arg(
mochi@schema:schema(),
binary(),
binary(),
boolean(),
gleam@dynamic:dynamic_()
) -> gleam@dynamic:dynamic_().
make_string_arg(Schema_def, Name, Description, Required, Default_value) ->
Arg_type = case Required of
true ->
{non_null, {named, <<"String"/utf8>>}};
false ->
{named, <<"String"/utf8>>}
end,
gleam_stdlib:identity(
maps:from_list(
[{<<"name"/utf8>>, gleam_stdlib:identity(Name)},
{<<"description"/utf8>>, gleam_stdlib:identity(Description)},
{<<"type"/utf8>>,
build_field_type_introspection(Schema_def, Arg_type)},
{<<"defaultValue"/utf8>>, Default_value}]
)
).
-file("src/mochi/introspection.gleam", 431).
-spec build_skip_directive_introspection(mochi@schema:schema()) -> gleam@dynamic:dynamic_().
build_skip_directive_introspection(Schema_def) ->
build_builtin_directive(
<<"skip"/utf8>>,
<<"Directs the executor to skip this field or fragment when the `if` argument is true."/utf8>>,
[<<"FIELD"/utf8>>,
<<"FRAGMENT_SPREAD"/utf8>>,
<<"INLINE_FRAGMENT"/utf8>>],
[make_bool_arg(
Schema_def,
<<"if"/utf8>>,
<<"Skipped when true."/utf8>>,
gleam_stdlib:identity(nil)
)]
).
-file("src/mochi/introspection.gleam", 447).
-spec build_include_directive_introspection(mochi@schema:schema()) -> gleam@dynamic:dynamic_().
build_include_directive_introspection(Schema_def) ->
build_builtin_directive(
<<"include"/utf8>>,
<<"Directs the executor to include this field or fragment only when the `if` argument is true."/utf8>>,
[<<"FIELD"/utf8>>,
<<"FRAGMENT_SPREAD"/utf8>>,
<<"INLINE_FRAGMENT"/utf8>>],
[make_bool_arg(
Schema_def,
<<"if"/utf8>>,
<<"Included when true."/utf8>>,
gleam_stdlib:identity(nil)
)]
).
-file("src/mochi/introspection.gleam", 463).
-spec build_deprecated_directive_introspection(mochi@schema:schema()) -> gleam@dynamic:dynamic_().
build_deprecated_directive_introspection(Schema_def) ->
build_builtin_directive(
<<"deprecated"/utf8>>,
<<"Marks an element of a GraphQL schema as no longer supported."/utf8>>,
[<<"FIELD_DEFINITION"/utf8>>,
<<"ARGUMENT_DEFINITION"/utf8>>,
<<"INPUT_FIELD_DEFINITION"/utf8>>,
<<"ENUM_VALUE"/utf8>>],
[make_string_arg(
Schema_def,
<<"reason"/utf8>>,
<<"Explains why this element was deprecated, usually also including a suggestion for how to access supported similar data. Formatted using the Markdown syntax, as specified by [CommonMark](https://commonmark.org/)."/utf8>>,
false,
gleam_stdlib:identity(<<"\"No longer supported\""/utf8>>)
)]
).
-file("src/mochi/introspection.gleam", 487).
-spec build_specified_by_directive_introspection(mochi@schema:schema()) -> gleam@dynamic:dynamic_().
build_specified_by_directive_introspection(Schema_def) ->
build_builtin_directive(
<<"specifiedBy"/utf8>>,
<<"Exposes a URL that specifies the behavior of this scalar."/utf8>>,
[<<"SCALAR"/utf8>>],
[make_string_arg(
Schema_def,
<<"url"/utf8>>,
<<"The URL that specifies the behavior of this scalar."/utf8>>,
true,
gleam_stdlib:identity(nil)
)]
).
-file("src/mochi/introspection.gleam", 307).
-spec build_directives_introspection(mochi@schema:schema()) -> gleam@dynamic:dynamic_().
build_directives_introspection(Schema_def) ->
Builtin_directives = [build_skip_directive_introspection(Schema_def),
build_include_directive_introspection(Schema_def),
build_deprecated_directive_introspection(Schema_def),
build_specified_by_directive_introspection(Schema_def)],
Custom_directives = begin
_pipe = erlang:element(6, Schema_def),
_pipe@1 = maps:to_list(_pipe),
gleam@list:map(
_pipe@1,
fun(Kv) ->
{_, Directive_def} = Kv,
build_directive_introspection(Schema_def, Directive_def)
end
)
end,
gleam_stdlib:identity(lists:append(Builtin_directives, Custom_directives)).
-file("src/mochi/introspection.gleam", 764).
-spec build_input_introspection(
mochi@schema:schema(),
mochi@schema:input_object_type()
) -> gleam@dynamic:dynamic_().
build_input_introspection(Schema_def, Input) ->
Fields = begin
_pipe = maps:to_list(erlang:element(4, Input)),
gleam@list:map(
_pipe,
fun(Kv) ->
{Name, Def} = Kv,
gleam_stdlib:identity(
maps:from_list(
[{<<"name"/utf8>>, gleam_stdlib:identity(Name)},
{<<"description"/utf8>>,
gleam_stdlib:identity(
gleam@option:unwrap(
erlang:element(3, Def),
<<""/utf8>>
)
)},
{<<"type"/utf8>>,
build_field_type_introspection(
Schema_def,
erlang:element(4, Def)
)},
{<<"defaultValue"/utf8>>,
serialize_default_value(erlang:element(5, Def))}]
)
)
end
)
end,
make_type_object(
<<"INPUT_OBJECT"/utf8>>,
erlang:element(2, Input),
gleam@option:unwrap(erlang:element(3, Input), <<""/utf8>>),
none,
none,
none,
none,
none,
{some, Fields},
none
).
-file("src/mochi/introspection.gleam", 889).
-spec build_fields_introspection(
mochi@schema:schema(),
gleam@dict:dict(binary(), mochi@schema:field_definition()),
boolean()
) -> list(gleam@dynamic:dynamic_()).
build_fields_introspection(Schema_def, Fields, Include_deprecated) ->
_pipe = maps:to_list(Fields),
_pipe@1 = gleam@list:filter(
_pipe,
fun(Kv) ->
{_, Def} = Kv,
Include_deprecated orelse not erlang:element(7, Def)
end
),
gleam@list:map(
_pipe@1,
fun(Kv@1) ->
{Name, Def@1} = Kv@1,
Args = begin
_pipe@2 = maps:to_list(erlang:element(5, Def@1)),
gleam@list:map(
_pipe@2,
fun(Arg_kv) ->
{Arg_name, Arg_def} = Arg_kv,
gleam_stdlib:identity(
maps:from_list(
[{<<"name"/utf8>>,
gleam_stdlib:identity(Arg_name)},
{<<"description"/utf8>>,
gleam_stdlib:identity(
gleam@option:unwrap(
erlang:element(3, Arg_def),
<<""/utf8>>
)
)},
{<<"type"/utf8>>,
build_field_type_introspection(
Schema_def,
erlang:element(4, Arg_def)
)},
{<<"defaultValue"/utf8>>,
serialize_default_value(
erlang:element(5, Arg_def)
)}]
)
)
end
)
end,
gleam_stdlib:identity(
maps:from_list(
[{<<"name"/utf8>>, gleam_stdlib:identity(Name)},
{<<"description"/utf8>>,
gleam_stdlib:identity(
gleam@option:unwrap(
erlang:element(3, Def@1),
<<""/utf8>>
)
)},
{<<"args"/utf8>>, gleam_stdlib:identity(Args)},
{<<"type"/utf8>>,
build_field_type_introspection(
Schema_def,
erlang:element(4, Def@1)
)},
{<<"isDeprecated"/utf8>>,
gleam_stdlib:identity(erlang:element(7, Def@1))},
{<<"deprecationReason"/utf8>>,
case erlang:element(8, Def@1) of
{some, Reason} ->
gleam_stdlib:identity(Reason);
none ->
gleam_stdlib:identity(nil)
end}]
)
)
end
).
-file("src/mochi/introspection.gleam", 623).
-spec build_object_introspection(
mochi@schema:schema(),
mochi@schema:object_type()
) -> gleam@dynamic:dynamic_().
build_object_introspection(Schema_def, Obj) ->
Fields = build_fields_introspection(
Schema_def,
erlang:element(4, Obj),
false
),
Fields_all = build_fields_introspection(
Schema_def,
erlang:element(4, Obj),
true
),
Interfaces = gleam@list:map(
erlang:element(5, Obj),
fun(I) ->
gleam_stdlib:identity(
maps:from_list(
[{<<"kind"/utf8>>,
gleam_stdlib:identity(<<"INTERFACE"/utf8>>)},
{<<"name"/utf8>>,
gleam_stdlib:identity(erlang:element(2, I))},
{<<"ofType"/utf8>>, gleam_stdlib:identity(nil)}]
)
)
end
),
make_type_object(
<<"OBJECT"/utf8>>,
erlang:element(2, Obj),
gleam@option:unwrap(erlang:element(3, Obj), <<""/utf8>>),
{some, Fields},
{some, Fields_all},
{some, Interfaces},
none,
none,
none,
none
).
-file("src/mochi/introspection.gleam", 506).
-spec build_type_ref(
mochi@schema:schema(),
gleam@option:option(mochi@schema:object_type())
) -> gleam@dynamic:dynamic_().
build_type_ref(Schema_def, Obj) ->
_pipe = Obj,
_pipe@1 = gleam@option:map(
_pipe,
fun(O) -> build_object_introspection(Schema_def, O) end
),
gleam@option:unwrap(_pipe@1, gleam_stdlib:identity(nil)).
-file("src/mochi/introspection.gleam", 583).
-spec lookup_root_type(mochi@schema:schema(), binary()) -> gleam@dynamic:dynamic_().
lookup_root_type(Schema_def, Name) ->
_pipe = [erlang:element(2, Schema_def),
erlang:element(3, Schema_def),
erlang:element(4, Schema_def)],
_pipe@2 = gleam@list:find(
_pipe,
fun(Opt) ->
_pipe@1 = gleam@option:map(
Opt,
fun(O) -> erlang:element(2, O) =:= Name end
),
gleam@option:unwrap(_pipe@1, false)
end
),
_pipe@4 = gleam@result:map(
_pipe@2,
fun(Opt@1) ->
_pipe@3 = gleam@option:map(
Opt@1,
fun(_capture) ->
build_object_introspection(Schema_def, _capture)
end
),
gleam@option:unwrap(_pipe@3, gleam_stdlib:identity(nil))
end
),
gleam@result:unwrap(_pipe@4, build_meta_type_introspection(Name)).
-file("src/mochi/introspection.gleam", 693).
-spec build_interface_introspection(
mochi@schema:schema(),
mochi@schema:interface_type()
) -> gleam@dynamic:dynamic_().
build_interface_introspection(Schema_def, Iface) ->
Fields = build_fields_introspection(
Schema_def,
erlang:element(4, Iface),
false
),
Fields_all = build_fields_introspection(
Schema_def,
erlang:element(4, Iface),
true
),
Possible_types = begin
_pipe = maps:values(erlang:element(5, Schema_def)),
gleam@list:filter_map(_pipe, fun(Type_def) -> case Type_def of
{object_type_def, Obj} ->
case gleam@list:any(
erlang:element(5, Obj),
fun(I) ->
erlang:element(2, I) =:= erlang:element(
2,
Iface
)
end
) of
true ->
{ok,
gleam_stdlib:identity(
maps:from_list(
[{<<"kind"/utf8>>,
gleam_stdlib:identity(
<<"OBJECT"/utf8>>
)},
{<<"name"/utf8>>,
gleam_stdlib:identity(
erlang:element(2, Obj)
)},
{<<"ofType"/utf8>>,
gleam_stdlib:identity(nil)}]
)
)};
false ->
{error, nil}
end;
_ ->
{error, nil}
end end)
end,
make_type_object(
<<"INTERFACE"/utf8>>,
erlang:element(2, Iface),
gleam@option:unwrap(erlang:element(3, Iface), <<""/utf8>>),
{some, Fields},
{some, Fields_all},
none,
none,
none,
none,
{some, Possible_types}
).
-file("src/mochi/introspection.gleam", 595).
-spec build_type_def_introspection(
mochi@schema:schema(),
mochi@schema:type_definition()
) -> gleam@dynamic:dynamic_().
build_type_def_introspection(Schema_def, Type_def) ->
case Type_def of
{object_type_def, Obj} ->
build_object_introspection(Schema_def, Obj);
{scalar_type_def, Scalar} ->
make_type_object(
<<"SCALAR"/utf8>>,
erlang:element(2, Scalar),
gleam@option:unwrap(erlang:element(3, Scalar), <<""/utf8>>),
none,
none,
none,
none,
none,
none,
none
);
{enum_type_def, Enum} ->
build_enum_introspection(Enum);
{interface_type_def, Iface} ->
build_interface_introspection(Schema_def, Iface);
{union_type_def, Union} ->
build_union_introspection(Schema_def, Union);
{input_object_type_def, Input} ->
build_input_introspection(Schema_def, Input)
end.
-file("src/mochi/introspection.gleam", 576).
-spec lookup_type_introspection(mochi@schema:schema(), binary()) -> gleam@dynamic:dynamic_().
lookup_type_introspection(Schema_def, Name) ->
case gleam_stdlib:map_get(erlang:element(5, Schema_def), Name) of
{ok, Type_def} ->
build_type_def_introspection(Schema_def, Type_def);
{error, _} ->
lookup_root_type(Schema_def, Name)
end.
-file("src/mochi/introspection.gleam", 537).
-spec build_type_introspection(mochi@schema:schema(), binary()) -> gleam@dynamic:dynamic_().
build_type_introspection(Schema_def, Name) ->
case Name of
<<"String"/utf8>> ->
build_scalar_introspection(Name);
<<"Int"/utf8>> ->
build_scalar_introspection(Name);
<<"Float"/utf8>> ->
build_scalar_introspection(Name);
<<"Boolean"/utf8>> ->
build_scalar_introspection(Name);
<<"ID"/utf8>> ->
build_scalar_introspection(Name);
_ ->
lookup_type_introspection(Schema_def, Name)
end.
-file("src/mochi/introspection.gleam", 287).
-spec build_schema_introspection(mochi@schema:schema()) -> gleam@dynamic:dynamic_().
build_schema_introspection(Schema_def) ->
gleam_stdlib:identity(
maps:from_list(
[{<<"queryType"/utf8>>,
build_type_ref(Schema_def, erlang:element(2, Schema_def))},
{<<"mutationType"/utf8>>,
build_type_ref(Schema_def, erlang:element(3, Schema_def))},
{<<"subscriptionType"/utf8>>,
build_type_ref(Schema_def, erlang:element(4, Schema_def))},
{<<"types"/utf8>>,
gleam_stdlib:identity(
gleam@list:map(
get_all_type_names(Schema_def),
fun(_capture) ->
build_type_introspection(Schema_def, _capture)
end
)
)},
{<<"directives"/utf8>>,
build_directives_introspection(Schema_def)}]
)
).