简体   繁体   English

Apollo Vue (using AWS Amplify/AppSync) Graphql 查询不拉父数据

[英]Apollo Vue (using AWS Amplify/AppSync) Graphql query does not pull parent data

I am using AWS AppSync (via Apollo Vue) and I have the following graphql model.我正在使用 AWS AppSync(通过 Apollo Vue)并且我有以下 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: Session 表解析器:

{
  "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?由于我建模了子-父@connection(keyName: "ServiceSessionConnection")关系,我不应该期望查询结果中有父数据吗? Am I missing anything?我错过了什么吗? What else needs to be configured to have relationship data in the query result?还需要配置什么才能在查询结果中包含关系数据?

Further dissecting the resolver code, issue resolved by setting both serviceSessionsId and sessionServiceId to Id1 when creating child record createSession()进一步剖析解析器代码,通过在创建子记录createSession()时将serviceSessionsIdsessionServiceId都设置为 Id1 来解决问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM