Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve Should Accept a Map of String Keys #54

Closed
AdamBrodzinski opened this issue Feb 1, 2016 · 8 comments
Closed

Resolve Should Accept a Map of String Keys #54

AdamBrodzinski opened this issue Feb 1, 2016 · 8 comments

Comments

@AdamBrodzinski
Copy link
Member

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
    }
  }
}
@joshprice
Copy link
Member

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

@AdamBrodzinski
Copy link
Member Author

@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.

@AdamBrodzinski AdamBrodzinski changed the title Can I Return a Map of String Keys Resolve Should Accept a Map of String Keys Feb 1, 2016
@AdamBrodzinski
Copy link
Member Author

@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}}}}

@joshprice
Copy link
Member

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

@AdamBrodzinski
Copy link
Member Author

@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.

@joshprice
Copy link
Member

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.

@AdamBrodzinski
Copy link
Member Author

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.

@joshprice
Copy link
Member

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)
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants