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

How to handle object input types in mutations #22

Open
DaveDeCaprio opened this issue Jun 2, 2017 · 1 comment
Open

How to handle object input types in mutations #22

DaveDeCaprio opened this issue Jun 2, 2017 · 1 comment
Labels

Comments

@DaveDeCaprio
Copy link

In the relay-playground, the mutation only accepts primitive types as arguments. I'm trying to have a mutation parameter which is an object. The issue is that in mutateAndGetPayload, the input object is a Map and the input object comes through as a nested Map rather than the correct type. I'm currently handling this using:

val myObj = fromMap[MyInputType](input("myObj").asInstanceOf[Map[String, Any]])

where "fromMap" is a function that instantiates a case class from a Map that I got from https://stackoverflow.com/questions/20684572/scala-convert-map-to-case-class.

This works in my current case but feels wrong and I think will break down if I get to nested objects.

In there a correct pattern for this.

@OlegIlyenko
Copy link
Member

I would suggest you to check this example:

https://github.com/sangria-graphql/sangria-relay/blob/master/src/test/scala/sangria/relay/MutationSpec.scala#L52

It works with scala case classes (wich have a JsonFormat) instead of Maps. More docs on this topic: http://sangria-graphql.org/learn/#frominput-type-class

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

No branches or pull requests

2 participants