0

My schema and queries are working fine on amplify console but throwing a type mismatch error on the client side. This happens only when there are more than one records in the object returned

Data successfully returned when there's only one record

enter image description here

Error when object contains more than one record

enter image description here

Schema:

type Member {
    Id: ID
    PartyId: String
    Status: MemberStatus
    PersonName: MemberName
    Email: String
    UniformId: String
    Name: String
}

type MemberName {
    FirstName: String
    LastName: String
    FullName: String
    InformalName: String
}

type MemberStatus {
    PartyStatusId: String
    Name: String
    Description: String
    ActiveStatus: Int
}

type Query {
    listMembers(id: ID, firstName: String, lastName: String): [Member]
}

My query on the frontend

// Single Record 
const [isLoading, state, error] = useGraphql(queries.listMembers, {
    firstName: "BlaBle",
    lastName: "Blu",
})

// Multiple Records
const [isLoading, state, error] = useGraphql(queries.listMembers, {
    firstName: "blee",
})

Resolver

enter image description here

Am I missing something or doing something wrong here? Let me know if more info is required.

Thanks!

Shawn Yap
  • 969
  • 7
  • 12
  • May I ask what kind of DB you are using and how does your resolver look like? – Myz Aug 21 '20 at 16:45
  • It's connected to a lambda as datasource and that lambda does http request to a third party api. Let me edit the post real quick to include the resolvers – Shawn Yap Aug 21 '20 at 16:48
  • Thanks for sharing. It is really strange that the same thing is working on console but not on the client side. Have to tried to change the response template to just `$ctx.result.body`? – Myz Aug 21 '20 at 17:02
  • I know! My hair is almost gone because of this. I have not tried that, I'll do that and see what the results are. – Shawn Yap Aug 21 '20 at 17:04
  • Also, I would double check what data is being returned from the Lambda function and how is its structure. – Myz Aug 21 '20 at 17:12
  • Hmm, the lambda returns the same structure as the object in the first Image. – Shawn Yap Aug 21 '20 at 17:19
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/220230/discussion-between-myz-and-shawn-yap). – Myz Aug 21 '20 at 17:21

1 Answers1

0

If anyone is wonder, I was able to solve this because the lambda datasource did not have guards against empty arguments. Data started flowing as expected once that was fixed. Thanks, Myz.

Shawn Yap
  • 969
  • 7
  • 12