It seems like there is no way to earlyReturn null. Both runtime.earlyReturn(null) and runtime.earlyReturn() throws an ErrorType: "Code", "message": "Runtime Error".
type Object {
value: String!
}
type Query {
getObject(skip: Boolean!): Object
}
schema {
query: Query
}
And a query:
query MyQuery {
getObject(skip: true) {
value
}
}
The getObject resolver uses a NONE data source:
import {util, runtime} from "@aws-appsync/utils";
export function request(ctx) {
if (ctx.args.skip) {
runtime.earlyReturn();
}
return {
version : "2018-05-29",
payload: {value: "test"},
};
}
export function response(ctx) {
if (ctx.error) {
return util.error(ctx.error.message, ctx.error.type);
}
return ctx.result;
}
What I want to achieve is to return null for the field if some condition is true:
{
"data": {
"getObject": null
}
}
runtime.earlyReturn() and runtime.earlyReturn(null) both throws a Code exception. runtime.earlyReturn({}) complains that the Object.value is null. I tried runtime.earlyReturn(undefined) but that also throws a runtime error.
Strangely, if I use runtime.earlyReturn("") then I get a response that looks like a memory address:
This appears to have been fixed now. Both runtime.earlyReturn(null) and runtime.earlyReturn() work for me and just return null without throwing any errors.
It seems like there is no way to earlyReturn null. Both
runtime.earlyReturn(null)
andruntime.earlyReturn()
throws anErrorType: "Code"
,"message": "Runtime Error"
.I made a very simple reproduction available here: https://github.com/sashee/appsync-earlyreturn-bug . Use
terraform init
andterraform apply
to deploy.Here, I have a very simple schema:
And a query:
The
getObject
resolver uses a NONE data source:What I want to achieve is to return
null
for the field if some condition is true:runtime.earlyReturn()
andruntime.earlyReturn(null)
both throws a Code exception.runtime.earlyReturn({})
complains that the Object.value is null. I triedruntime.earlyReturn(undefined)
but that also throws a runtime error.Strangely, if I use
runtime.earlyReturn("")
then I get a response that looks like a memory address:What is the correct way to return null for a field using
earlyReturn
?