Encountering an issue while querying the memberList resolver. The expected behavior is to return a membeTypeID, but instead it returns null. Apollo is being used for this operation:
"errors": [
{
"message": "Cannot return null for non-nullable field Member.memberType.",
"locations": [
{
"line": 5,
"column": 3
}
],
"path": [
"memberList",
0,
"memberType"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"stacktrace": [
"Error: Cannot return null for non-nullable field Member.memberType.",
The query in use:
query MemberList {
memberList{
firstName
id
memberType{id}
}
}
Part of Member Entity with typeORM and Graphql:
/** Reference to type of member. */
@ManyToOne(() => MemberType, (memberType) => memberType.memberType, { eager: true })
// @JoinColumn({referencedColumnName: 'testing'})
@Field(() => MemberType)
memberType!: MemberType;
Snippet from member-type entity:
/** ID number of a member type. */
@PrimaryGeneratedColumn('increment')
@Field()
id!: number;
/** Type that a member can be. */
@OneToMany(() => Member, (member) => member.memberType)
@Field()
memberType!: string;
The memberList:
/** Get an array of all members */
@Query(() => [ Member ], { nullable: true })
async memberList(): Promise<Member[] | null>{
const memberList = await Member.find();
return memberList;
}
An error occurs when attempting to run the following mutation:
/** Update a member with new details */
@Mutation(() => Member, {nullable: true })
async memberUpdate(
@Arg('input') input: MemberUpdateInput,
@Ctx() { request }: AppContext
): Promise<Member | null> {
input.throwIfInvalid();
const { userID } = request.session;
const existingUser = await User.findOneBy({ id: userID });
if (!existingUser) {
throw new AuthenticationError;
}
// More code here...
Input provided:
{
"input": {
"id": "48b76f72-1348-4708-8d09-471cc82def13",
"firstName": "foob",
"lastName": "bar",
"memberType": {
"id": 2
},
"photoUrl": "testingPhoto"
}
}
Definition of input type MemberUpdateInput:
@InputType()
export class MemberUpdateInput extends UuidInput {
@Field()
firstName!: string;
// More fields specified...
Troubleshooting steps taken with no success include making the memberType optional and setting the memberType as a number OneToOne relationship in the Member entity.
Issue seems to stem from the memberType not being retrieved during findbyOne or find queries. Sample output of updatedMember is shown below:
Member {
createdAt: 2023-10-07T09:56:27.589Z,
firstName: 'testin',
githubUrl: null,
id: '8c636b7b-4d83-4681-a912-87aee5a95c2e',
lastName: 'bar',
linkedinUrl: null,
personalUrl: null,
photoUrl: 'testThing',
updateAt: 2023-10-07T09:56:27.589Z,
memberType: MemberType {
createdAt: 2023-10-07T09:21:01.670Z,
id: 1,
updateAt: 2023-10-07T09:21:01.670Z
}
}
Result of memberList[0]:
Member {
createdAt: 2023-10-07T09:56:27.589Z,
firstName: 'testin',
githubUrl: null,
id: '8c636b7b-4d83-4681-a912-87aee5a95c2e',
lastName: 'bar',
linkedinUrl: null,
personalUrl: null,
photoUrl: 'testThing',
updateAt: 2023-10-07T09:56:27.589Z,
memberType: MemberType {
createdAt: 2023-10-07T09:21:01.670Z,
id: 1,
updateAt: 2023-10-07T09:21:01.670Z
}
}