I want to return a single object(not array).The graphql server is returning null when i try to return single object.But seems to work fine while trying to return an array.
Here is my schema example:
type Author{
authorID: String
label: String
posts: [Post]
}
type Post {
postID: String
label: String
author: Author
}
type Query {
getAuthorById (authorID: String!): Author #-> this does not work
getAuthorById (authorID: String!): [Author] #-> this works
}
But when I try to run this query "getAuthorById (authorID: String!)",I am getting the following result:
{
"data": {
"getAuthorById": {
"label": null,
"authorID": null
}
}
However,it seems to work only if i try to return an array (when I try to change the schema for type query like this):
type Query {
getAuthorById (authorID: String!): [Author]
}
Here is my resolver.js:
Query: {
getAuthorById(_, params) {
let session = driver.session();
let query = `MATCH (a:Author{ authorID: $authorID}) RETURN a ;`
return session.run(query, params)
.then( result => {
return result.records.map( record => {
return record.get("a").properties
}
)
}
)
},
}
What I need is to return a single object like this: getAuthorById (authorID: String!): Author
// Instead of array like this-> getAuthorById (authorID: String!): [Author]
so,could someone let me know what am i doing wrong here ? All I need is to return single object and not array .... Thanks in Advance