我有一个请求映射模板如下:这映射到一个名为 getPost 的 GraphQL 查询
{
"version": "2018-05-29",
"method": "GET",
## E.G. if full path is https://api.xxxxxxxxx.com/posts then resourcePath would be /posts **
"resourcePath": "/event1/wp-json/wp/v2/posts",
"params":{
## "query":$util.toJson($ctx.args),
"query":{
"slug": "$ctx.args.slug",
"lang": "$ctx.args.lang"
},
"headers": {
"Authorization": "$ctx.request.headers.Authorization"
}
}
}
一个有效的 JSON 响应 URL 是这样的:
http://my_domain/wp-json/wp/v2/posts?slug=new-post-en&lang=zh-hant
但是当我使用这个在“查询”中进行测试时:
query MyQuery {
getPost(slug: "new-post-en", lang: "zh-hant") {
id
}
}
不返回结果,但至少返回一条记录。
你能告诉我我的请求有什么问题吗?
谢谢。
更新添加架构:
type Post {
id: ID!
date: String!
slug: String!
type: String!
link: AWSURL
title: AWSJSON!
content: AWSJSON!
excerpt: AWSJSON!
}
type Query {
getPost(slug: String!, lang: String): Post
getPosts: [Post]
}
schema {
query: Query
}
答案 0 :(得分:0)
我找到了解决方案:
http://my_domain/wp-json/wp/v2/posts?slug=new-post-en&lang=zh-hant
发出请求时,它会返回一个 JSON 格式的数组getPost(slug: String!, lang: String): Post
Post
,它不是数组getPost(slug: String!, lang: String): Post
到getPost(slug: String!, lang: String): [Post]
你好~它有效!