graphql – AppSync resolvers – get attributes from a related table

I am new to AppSync and trying to understand/debug Resolvers.

I have the following schema:

type AccessManager {
    ProfileId: ID!
    userProfile: UserProfile //this resolver is returning null
    ResourceId: ID! //Can reference multiple table within DynamoDB
    ResourceType: String
    RoleType: String
    UserId: String 
}

type UserProfile {
    id: ID!
    userName: String!
    userId: String
    users: User //End Goal- to see the User Details directly in AccessManager query
    ...
    access: [AccessManager]
}

type User {
    id: ID!
    email: String!
    profiles: [UserProfile]
    ...
}

I have the following resolvers on AccessManager.userProfile (however it does not seem to be right- as it returns- “Null”) :

request-

{
    "version": "2018-05-29",
    "operation": "GetItem",
    "key": {
        "id": $util.dynamodb.toDynamoDBJson($ctx.source.ProfileId)
    }
}

response-

#if($ctx.error)
    $util.error($ctx.error.message, $ctx.error.type)
#end
$util.toJson($ctx.result)

For right now, I am trying to retrieve the “UserProfile” record itself (currently the AccessManager table has the ProfileId, which should equal the “id” of the user profile).

Once I can figure that out- I figure I can use the same mechanism to update the User on the UserProfile itself (my ultimate goal is to query for a Table (aka ResourceId) and return the “AcessManager” table with the appropriate UserProfile (and User details, i.e. Name, Email, etc).

It feels like I am missing something fairly basic, so apologies again if this is a “newb” question. Any responses are appreciated.

Read more here: Source link