Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: only optimistically resolve nested entities #298

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions src/graphql/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,29 +194,28 @@ export async function querySingle(
const returnType = getNonNullType(info.returnType) as GraphQLObjectType;
const jsonFields = getJsonFields(returnType);

const currentValue = parent?.[info.fieldName];
const parentResolvedValue = parent?.[info.fieldName];

if (currentValue === null) return null;
const alreadyResolvedInParent = typeof currentValue === 'object';
if (parentResolvedValue === null) return null;
const alreadyResolvedInParent = typeof parentResolvedValue === 'object';
if (alreadyResolvedInParent) {
return {
...formatItem(currentValue, jsonFields),
...formatItem(parentResolvedValue, jsonFields),
_args: { block }
};
}

const id = currentValue || args.id;

const parsed = parseResolveInfo(info);
if (parsed) {
if (parsed && parentResolvedValue) {
// @ts-ignore
const simplified = simplifyParsedResolveInfoFragmentWithType(parsed, returnType);

if (Object.keys(simplified.fields).length === 1 && simplified.fields['id']) {
return { id, _args: { block } };
return { id: parentResolvedValue, _args: { block } };
}
}

const id = parentResolvedValue || args.id;
const items = await context.getLoader(returnType.name.toLowerCase(), 'id', block).load(id);
if (items.length === 0) {
throw new Error(`Row not found: ${id}`);
Expand Down
Loading