0

I am using AWS AppSync (via Apollo Vue) and I have the following graphql model.

type Service @model
{
  id: ID!
  name: String!
  description: String!
}

type Session @model
{
  id: ID!
  service: Service @connection(keyName: "ServiceSessionConnection")
}

Service table resolver:

#set( $limit = $util.defaultIfNull($context.args.limit, 10) )
#set( $query = {
  "expression": "#connectionAttribute = :connectionAttribute",
  "expressionNames": {
      "#connectionAttribute": "serviceSessionsId"
  },
  "expressionValues": {
      ":connectionAttribute": {
          "S": "$context.source.id"
    }
  }
} )
{
  "version": "2017-02-28",
  "operation": "Query",
  "query":   $util.toJson($query),
  "scanIndexForward":   #if( $context.args.sortDirection )
    #if( $context.args.sortDirection == "ASC" )
true
    #else
false
    #end
  #else
true
  #end,
  "filter":   #if( $context.args.filter )
$util.transform.toDynamoDBFilterExpression($ctx.args.filter)
  #else
null
  #end,
  "limit": $limit,
  "nextToken":   #if( $context.args.nextToken )
$util.toJson($context.args.nextToken)
  #else
null
  #end,
  "index": "gsi-Service.sessions"
}

Session table resolver:

{
  "version": "2017-02-28",
  "operation": "GetItem",
  "key": {
      "id": $util.dynamodb.toDynamoDBJson($util.defaultIfNullOrBlank($ctx.source.sessionServiceId, "___xamznone____"))
  }
}

I am creating the following records:

mutation createService {
   createService {
     id: "Id1",
     name: "name",
     description: "desc"
   }
}
mutation createSession {
   createSession {
     id: "Id2",
     serviceSessionsId: "Id1" //note: serviceSessionsId created part of relationship (it is part of the resolved code above!), and I am setting that to parent ID (in this case serviceId value "Id1")
   }
} 

I am trying to run following child table (Session) query with parent (Service) data:

query listSessions {
  listSessions {
    items {
      id,
      serviceId,
      service {        //retuns null data
        id,            //retuns null data
        name,          //retuns null data
        description.   //retuns null data
      }
    }
  }
}

I am not getting parent (Service object) data. Since I am modeled child-parent @connection(keyName: "ServiceSessionConnection") relationship, shouldn't I expect parent data in the query result? Am I missing anything? What else needs to be configured to have relationship data in the query result?

bizready
  • 139
  • 3
  • 14

1 Answers1

0

Further dissecting the resolver code, issue resolved by setting both serviceSessionsId and sessionServiceId to Id1 when creating child record createSession()

bizready
  • 139
  • 3
  • 14