Skip to content

Conversation

@captbaritone
Copy link
Owner

@captbaritone captbaritone commented Dec 10, 2025

Summary

This PR adds support for derived context functions that return Promise<T>, enabling async operations in derived context resolution.

Example

/** @gqlContext */
type Ctx = { db: DB };

type UserContext = { user: User };

/** @gqlContext */
export async function getUserContext(ctx: Ctx): Promise<UserContext> {
  const user = await ctx.db.getCurrentUser();
  return { user };
}

/** @gqlQueryField */
export function me(userCtx: UserContext): User {
  return userCtx.user;
}

Generates:

async resolve(_source, _args, context) {
  return queryMeResolver(await getUserContext(context));
}

@netlify
Copy link

netlify bot commented Dec 10, 2025

Deploy Preview for grats ready!

Name Link
🔨 Latest commit ee603ef
🔍 Latest deploy log https://app.netlify.com/projects/grats/deploys/6939b6b8249c4e0008b181b6
😎 Deploy Preview https://deploy-preview-207--grats.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@captbaritone
Copy link
Owner Author

Fixes #204

- Add support for derived context functions that return Promise<T>
- Unwrap Promise types in recordDerivedContext and track async flag
- Generate async resolver methods with await expressions when using async derived contexts
- Add maybeUnwrapPromiseType helper to share Promise unwrapping logic
- Add async property to DerivedResolverDefinition, DerivedContextArgument, and DerivedContextResolverArgument types
- Update codegen to generate async modifier on methods and await on derived context calls
- Preserve async modifiers when applying semantic null runtime checks
- Add comprehensive unit tests for Promise error cases
- Add integration test with function fields, static methods, and instance methods
- Update changelog
@captbaritone captbaritone merged commit 65fe40a into main Dec 10, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants