Reputation: 675
I have a request mapping template as follow: This is mapped to a GraphQL query called getPost
{
"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"
}
}
}
A valid JSON response URL is this:
http://my_domain/wp-json/wp/v2/posts?slug=new-post-en&lang=zh-hant
But when I tested in "Queries" using this:
query MyQuery {
getPost(slug: "new-post-en", lang: "zh-hant") {
id
}
}
No result return, but it should have at least one record returned.
Can you please tell me what's wrong with my request?
Thank you.
UPDATED Add Schema:
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
}
Upvotes: 0
Views: 928
Reputation: 675
I found the solution:
http://my_domain/wp-json/wp/v2/posts?slug=new-post-en&lang=zh-hant
, it will return an array in terms of JSONgetPost(slug: String!, lang: String): Post
Post
, it is not an arraygetPost(slug: String!, lang: String): Post
togetPost(slug: String!, lang: String): [Post]
And hola~ It works!
Upvotes: 1