Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Amazon web services AppSync GraphQL映射1-1到现有GraphQL API_Amazon Web Services_Graphql_Aws Appsync - Fatal编程技术网

Amazon web services AppSync GraphQL映射1-1到现有GraphQL API

Amazon web services AppSync GraphQL映射1-1到现有GraphQL API,amazon-web-services,graphql,aws-appsync,Amazon Web Services,Graphql,Aws Appsync,我有一个现有的GraphQL API,它公开了如下模式: type AType { id: Int! name: String! children: [BType] } type BType { id: Int! name: String! } type Query { a(id: ID): A as: [A] } #** Make an arbitrary HTTP call when this field is listed in

我有一个现有的GraphQL API,它公开了如下模式:

type AType {
    id: Int!
    name: String!
    children: [BType]
}

type BType {
    id: Int!
    name: String!
}

type Query {
    a(id: ID): A
    as: [A]
}
#**
Make an arbitrary HTTP call when this field is listed in a query selection set.
The "relativePath" is the resource path relative to the root URL provided when you
created the HTTP data source. Pass a "params" object to forward headers, body,
and query parameters to the HTTP endpoint.
*#
#if($context.identity.sub == $context.args.userId) 
#set($payload = "query ListOrders {
  listOrders(
    userId: ""$context.args.userId""
    orderDateTimeStatus: {
        le : {
            orderDateTime: ""$context.args.orderDateTime""
        }
    }
    limit: 10
    
  ) {
    items {
      userId
      status
      orderDateTime
      details
      orderId
    }
    nextToken
  }
}")

{
    "version": "2018-05-29",
    "method": "POST",
    "resourcePath": "/graphql",
    "params":{
        "body": {
            "query": "$util.escapeJavaScript($payload)"
        },
        "headers":{
            "Content-Type": "application/json",
            "x-access-token" : "$context.request.headers.x-access-token"

        }
    }
}
#else 
  $utils.unauthorized() 
#end
加上这两个字段中省略的一些其他标量字段。有两个这样的API端点,我想将它们聚合在一个AppSync实例下,这样前端就可以用一个模式查询一个端点,以获得它们所需的所有数据

我想做的是,如果前端发送一个查询

as {
    id,
    name,
    children {
      id,
      name
    }
}
它将被准确地中继到我现有的GraphQL端点。AppSync页面上链接的AWS示例讨论GraphQL端点,但唯一链接的代码示例是,它显示了如下解析程序:

type AType {
    id: Int!
    name: String!
    children: [BType]
}

type BType {
    id: Int!
    name: String!
}

type Query {
    a(id: ID): A
    as: [A]
}
#**
Make an arbitrary HTTP call when this field is listed in a query selection set.
The "relativePath" is the resource path relative to the root URL provided when you
created the HTTP data source. Pass a "params" object to forward headers, body,
and query parameters to the HTTP endpoint.
*#
#if($context.identity.sub == $context.args.userId) 
#set($payload = "query ListOrders {
  listOrders(
    userId: ""$context.args.userId""
    orderDateTimeStatus: {
        le : {
            orderDateTime: ""$context.args.orderDateTime""
        }
    }
    limit: 10
    
  ) {
    items {
      userId
      status
      orderDateTime
      details
      orderId
    }
    nextToken
  }
}")

{
    "version": "2018-05-29",
    "method": "POST",
    "resourcePath": "/graphql",
    "params":{
        "body": {
            "query": "$util.escapeJavaScript($payload)"
        },
        "headers":{
            "Content-Type": "application/json",
            "x-access-token" : "$context.request.headers.x-access-token"

        }
    }
}
#else 
  $utils.unauthorized() 
#end
这只使用传递到查询中的参数,而不使用查询结构。如果front请求
a
的字段子集,我只想请求该字段子集,而不是请求AppSync削减的所有字段。而且它甚至不包含嵌套对象——我是否每次都必须提取所有子对象,以便它们稍后被AppSync忽略

假设有4-5个微服务具有自己的GraphQL端点,这些端点在其模式中具有不同的查询。我想把请求1-1映射到它们。我如何编写这样一个解析器?AppSync并没有一个好的游乐场环境,在那里我可以调试解析器,所以我不能只查看
$ctx
对象并对原始查询的结构进行反向工程(AFAIK)

我发现这就是问题所在,但解决方案并没有像作者所说的那样起到预期的作用,而且它似乎已经死了