graphql-elixir/graphql

Resolve Should Accept a Map of String Keys

Closed this issue · 8 comments

When I return a database document in the resolve function it only works if the map has symbol keys. Currently you have to convert them after every database query or the GraphQL response is null for each string key.

For example this works:

%{
  type: App.Types.User.get(),
  resolve: fn(_, _, _) ->
    %{id: "123", name: "Bob"}
  end
}

# returns
{
  "data": {
    "user": {
      "name": "Bob",
      "id": "123"
    }
  }
}

however this doesn't work

%{
  type: App.Types.User.get(),
  resolve: fn(_, _, _) ->
    %{"id" => "123", "name" => "Bob"}
  end
}

#returns
{
  "data": {
    "user": {
      "name": null,
      "id": null
    }
  }
}

Should be possible either way. Feel free to rephrase this as a bug and I'll take a look at it.

@joshprice ok will do. I have dead time tomorrow so i'll work on making a reproduction and will re-edit this as a bug.

@joshprice I just uploaded a reproduction repo that has a working and notWorking query.
https://github.com/AdamBrodzinski/elixir-graphql-issue-54

These can both be executed with:

GraphQL.execute(TestSchema.schema, "{working {name}}")
GraphQL.execute(TestSchema.schema, "{notWorking {name}}")

and the meat of it is here in web/graphql/test.ex:

        fields: %{
          working: %{
            type: User.type,
            resolve: %{name: "Ted"}
          },
          # should return map with "Bob", instead it returns map with null
          notWorking: %{
            type: User.type,
            resolve: %{"name" => "Bob"}
          }
        }

notWorking should return {:ok, %{data: %{"notWorking" => %{"name" => "Bob"}}}} instead of {:ok, %{data: %{"notWorking" => %{"name" => nil}}}}

Thanks Adam! I've got a fix for this that I should be able to push up later today.

@joshprice if there's anything I can do to help test just let me know!

BTW thanks so much for working on this! I'm working on a GraphQL-RethinkDB example app to show how one can use it with RethinkDB and Phoenix.

The example app looks great! Is it deployed anywhere? Any chance of linking to it or using as an example in http://playground.graphql-elixir.org/

I didn't manage to get that fix in the last release I'm afraid, still had a couple of things to confirm. Will push something up asap.

Thanks! I'll deploy it to Heroku and ad to the playground list once I get the mutations finished.
No worries on the fix, i'm not using it in prod yet anyway.

Awesome will let you know when I've made the fix. Thanks again!

On Mon, Feb 15, 2016 at 4:11 AM, Adam Brodzinski notifications@github.com
wrote:

Thanks! I'll deploy it to Heroku and ad to the playground list once I get
the mutations finished.
No worries on the fix, i'm not using it in prod yet anyway.


Reply to this email directly or view it on GitHub
#54 (comment)
.