Closed ivan-kolmychek closed 8 years ago
Ok, I've redefined my schema to
defmodule BlogSchema do
def schema do
%GraphQL.Schema{
query: %GraphQL.ObjectType{
name: "RootQueryType",
fields: %{
post: %GraphQL.FieldDefinition{name: :post, type: "String", resolve: &post/3}
}
}
}
end
def post(_, _, _) do
"test"
end
end
and now I do receive the correct response
iex(8)> GraphQL.execute(BlogSchema.schema, "{post}")
{:ok, %{"post" => "test"}}
Was it intended for the resolve function to have three arguments exactly?
Ok, found how args are defined and passed.
defmodule BlogSchema do
def schema do
%GraphQL.Schema{
query: %GraphQL.ObjectType{
name: "RootQueryType",
fields: %{
post: %GraphQL.FieldDefinition{
name: :post,
type: "String",
args: %{ id: "String" },
resolve: &post/3}
}
}
}
end
def post(_, args, _) do
"test"
end
end
I think, documentation should really be updated. :)
Thanks for picking this up, I've fixed the docs in the plug, I'll make sure all other docs are updated! Sorry for any inconvenience. :(
@joshprice not a problem, I'm just messing around, so, just wanted to report my findings.
I'm not sure it's convinient for devs to have resolving function with arity 3. At least we should put args as a first argument, I guess.
Also, in what format should arguments be defined in schema? I mean, what should be the respecing values set to, just "String", or any type, or something completely different?
@joshprice if I understand correctly, type is ignored currently. Am I right?
I guess, this should be included in docs too, at least as a "checkbox"-like thing (like [WIP] arguments type validation/coercion
or something like that).
Docs updated, that should be all of it I think
Types will be the next thing I'll be working, thanks for the feedback!
Thanks.
I'm trying to reproduce the example from docs with some small changes, but I get an error when I try to execute sample request.
My schema:
Request:
Trace
I'm not sure, but it looks like executor.ex:79 expects
fields
to be a map, but gets an array instead.But when I change my schema to
I get this error
So now resolve function we've got from field definition is called with three arguments.
What am I doing wrong?