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

feat(handler-graphql): add support for resolver decoration #4199

Merged
merged 4 commits into from
Oct 1, 2024

Conversation

Pavel910
Copy link
Collaborator

@Pavel910 Pavel910 commented Jul 11, 2024

Changes

This PR adds support for GraphQL resolver decoration., and improves GraphQL related types (mostly typeDefs and resolvers).

// Decorator #1
const lowerCaseName = createResolverDecorator<any, any, Context>(
  (resolver) => async (parent, args, context, info) => {
    // Run the original resolver
    const name = await resolver(parent, args, context, info);

    // Return a modified value.
    return name.toLowerCase();
  }
);

// Decorator #2
const listBooks = createResolverDecorator(() => async () => {
  return [{ name: "Article 1" }];
});

// Target fields to decorate
const decorator1 = createGraphQLSchemaPlugin({
  resolverDecorators: {
    "Query.books": [listBooks],
    "Book.name": [lowerCaseName],
  },
});

How Has This Been Tested?

Jest tests.

@Pavel910 Pavel910 self-assigned this Jul 11, 2024
@Pavel910 Pavel910 added this to the 5.41.0 milestone Jul 11, 2024
@Pavel910 Pavel910 requested review from brunozoric and adrians5j July 11, 2024 08:22
@Pavel910 Pavel910 requested a review from adrians5j July 11, 2024 08:49
@Pavel910 Pavel910 merged commit c4892c6 into next Oct 1, 2024
94 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