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

Nested type fields with arguments don't seem to work #9

Open
acburdine opened this issue Feb 12, 2019 · 1 comment
Open

Nested type fields with arguments don't seem to work #9

acburdine opened this issue Feb 12, 2019 · 1 comment

Comments

@acburdine
Copy link

acburdine commented Feb 12, 2019

Ran into this case with a graphql schema I'm currently working on and have racked my brain for a bit to think up a good solution. Thought I'd post an issue here to see if there's any ideas on how to solve this problem without creating a custom fork 😄

Say you have this GraphQL schema (not the schema I'm using, but it's enough to show the problem):

type Query {
  users: [User]
}

type User {
  id ID!
  name String!
  role(company: ID!): String!
}

type Role {
  id: ID!
  name: String!
}

The users field on the Query type returns a list of User types. However, the User type also has a role field that can take a company arg. Currently, the role field cannot be mapped to a lambda function using this library, which is due to (as best I can tell) these lines: https://github.com/sbstjn/appsync-resolvers/blob/master/invocation.go#L15-L25 . The payload function appears to only return either the Source field or the Arguments field exclusively, meaning that the role resolver wouldn't be able to access the company arg at all.

I could solve this by making a more custom appsync resolver, i.e.

{
  "version" : "2017-02-28",
  "operation": "Invoke",
  "payload": {
    "resolve": "query.users.role",
    "context": {
      "source": null,
      "arguments": $utils.toJson($context)
    }
  }
}

and then making my event structure parse out those properties, i.e.

type User struct {
  ID   string `json:"id"`
  Name string `json:"name"`
}

type roleArgs struct {
  Company string `json:"company"`
}

type event struct {
  Source    User     `json:"source"`
  Arguments roleArgs `json:"arguments"`
}

However, this does seem a bit more complicated than it needs to be, and I was wondering if there's a better way to solve combining the source & arguments together. I'm totally willing to work on implementing whatever solution is decided on (if any) 😄

@matzhouse
Copy link

Yeah I've just run into this!

I think it should always pass the arguments otherwise the above example of field arguments will never work and it's a pretty nice thing to be able to use. @sbstjn any thoughts?

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