Open oe-bayram opened 1 month ago
Hey👋 thanks for raising this! I'm going to transfer this over to our API repository for better assistance 🙂
Hi @oe-bayram , thanks for raising this issue. Could you also share the CognitoUser
type in your schema so we can better reproduce the issue?
Also, regarding the error message:
Property X does not exist on type 'RefType<RefTypeArgFactory<"CognitoUser">, never, undefined>'.
is that the actual error message? As in, is X
an actual field name on the CognitoUser
customType or was that a redaction?
Lastly, can you confirm when exactly the error is occuring? Is it when modifying the schema and the sandbox attempts to redeploy? Or is it at runtime when you try to use the query?
We tried to reproduce with the same schema but the sandbox was able to redeploy.
Another point of failure might be the lambda handler if you are importing and trying use the returnType
like so:
type AddCognitoUser = Schema["addCognitoUser"]["returnType"]
If so, could you please share the lambda handler code as well?
The CognitoUser
type has the following schema:
CognitoUserGroup: a.customType({
GroupName: a.string().required(),
Description: a.string().required(),
UserPoolId: a.string().required(),
CreationDate: a.string().required(),
LastModifiedDate: a.string().required(),
Precedence: a.integer().required(),
}),
CognitoUser: a.customType({
username: a.string().required(),
createDate: a.string().required(),
enabled: a.boolean().required(),
userStatus: a.string().required(),
emailVerified: a.boolean().required(),
gender: a.string().required(),
firstName: a.string().required(),
lastName: a.string().required(),
phone: a.string().required(),
fax: a.string().required(),
email: a.string().required(),
groups: a.ref("CognitoUserGroup").required().array().required(),
}),
The deployment runs successfully. However, during development when using the client to run the query and trying to access the response fields, a TypeScript error occurs indicating that the type User does not have a property X
.
const { data, errors } = await client.queries.addCognitoUser({
...
});
// eg. can't access firstName here as `user` has only props `array`, `authorization`, `mutations` and `required`.
const firstName = data?.user.firstName;
The function handler for addCognitoUser
looks like this:
export const handler: Schema["addCognitoUser"]["functionHandler"] = async (
event,
) => {
const { user, error } = await addNewUser(event.arguments);
return {
user: user as any, // Using `any` here as TypeScript complains otherwise about the return type of the handler
error,
};
};
Hi @oe-bayram apologies for the delay. Are you still running into this issue?
In trying to reproduce this issue it seems that user
in your function handler is being returned from a addNewUser
function but the logic and return type is not clear from the shared code. If you're still experiencing this issue, please share the addNewUser
function as well.
Environment information
Description
In the return type of my function
addCognitoUser
I need a customType with a ref to another customTypeCognitoUser
and an error field for handling errors.However when acessing the ref field
user
I only get the following properties as suggestion:array
,authorization
,mutations
andrequired
and the following error message:This is the definition of my function: