sid88in / serverless-appsync-plugin

serverless plugin for appsync
MIT License
950 stars 186 forks source link

Access nested arguments? #548

Closed gel-hidden closed 1 year ago

gel-hidden commented 1 year ago

Lets say I have a query like this:

extend type Query {
    streets(number: Int): [Street]
}

type People {
   name: String
}

type Street {
    number: Int
    name: String
    people(name: String): [People]
}

And would then send a query like:

query  { streets(number: 1) { name, people(name: "Hello world") { name } } }

I don't see to be able to fetch the name argument of people. The $ctx.arguments just gives me:

 arguments: { number: 1 }

Is there no way to access both the number argument as well as the name argument?

bboure commented 1 year ago

Hi,

This is by (AppSync) design (not this plugin specifically) The resolver attached to the Query.street will receive the number argument. The name argument, will be passed to the resolver attached to Street.people

gel-hidden commented 1 year ago

Oh, sorry. I'm lacking quite a bit of knowledge in this area.

I have the same resolver, I think, for both Street and People given it is only one query. But I should configure it so it should be two revolvers for the same query? So one single query is calling multiple lambda resolvers?

bboure commented 1 year ago

I'd say you have two options:

gel-hidden commented 1 year ago

And by using another resolver it also means I have another query? Or could one query use multiple resolvers?

bboure commented 1 year ago

you can attach a resolver on Street.People it will be executed and you will receive the result ctx.source from the previous resolver.

I suggest you read the doc and guides and learn more about GraphQL in general first.

gel-hidden commented 1 year ago

Thank you so much!