How can one attach parse
and serialize
functions to a scalar type in a schema, when instead of the Absinthe DSL, the graphql SDL format is used to define the schema? (The schema is imported with import_sdl
. I can add resolvers to queries, but I get (BadFunctionError) expected a function, got: nil (absinthe 1.7.1) lib/absinthe/type/scalar.ex:49: Absinthe.Type.Scalar.serialize/2
when querying data with type scalar.)
OK, I figured out how to do it:
import_sdl "/path/to/schema/file"
...
def hydrate(%Absinthe.Blueprint.Schema.ScalarTypeDefinition{name: MyType}, _) do
[
serialize: &AppWeb.Schema.MyType.serialize/1,
parse: &AppWeb.Schema.MyType.parse/1
]
end