繁体   English   中英

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

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

我正在使用 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")
}

服务表解析器:

#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 表解析器:

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

我正在创建以下记录:

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")
   }
} 

我正在尝试使用父(服务)数据运行以下子表(会话)查询:

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

我没有得到父(服务对象)数据。 由于我建模了子-父@connection(keyName: "ServiceSessionConnection")关系,我不应该期望查询结果中有父数据吗? 我错过了什么吗? 还需要配置什么才能在查询结果中包含关系数据?

进一步剖析解析器代码,通过在创建子记录createSession()时将serviceSessionsIdsessionServiceId都设置为 Id1 来解决问题

暂无
暂无

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

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