I’m trying to work with and external schema in Absinthe.
How can I attach a resolve
functions to a specific field of a type in a schema, that was imported with import_sdl
? In the Absinthe schma DSL I could just do something like this:
object :some_object do
...
field(:name, :string) do
resolve(fn _, _, _ -> {:ok, "HELLOO"} end)
end
...
end
But when the scema is loaded using import_sdl
, I can only rely on the hydrate
function to somehow add a field specific resolver. I tried something like this, but for some reason it messed up my entire schema, and Graphiql was no longer able to give info about the schema after I added this function clause:
def hydrate(%Absinthe.Blueprint.Schema.FieldDefinition{name: "name"}, _ancestors) do
[
resolve: {Some.Module, :resolve_name_field}
]
end
It actually works, and it can rewrite the name
field, but it also changes something that messes up schema introspection. (Maybe it redefines the name
field of some internal object?)
How do I do this properly, without screwing up the schema?
How do I pattern match in hydrate
to select that I only want to resolve on some_object
s name
field?