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

Pass schema into api extension definition #3261

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

sonntag-philipp
Copy link
Contributor

@sonntag-philipp sonntag-philipp commented Dec 5, 2024

Description

See #3165

Breaking changes

As JavaScript behaves this way, no breaking changes should be included:
image

Checklist

📌 Always:

  • I have set a clear title
  • My PR is small and contains a single feature
  • I have checked my own PR

👍 Most of the time:

  • I have added or updated test cases
  • I have updated the README if needed

Copy link

vercel bot commented Dec 5, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview Dec 17, 2024 3:30pm

@sonntag-philipp
Copy link
Contributor Author

Please let me know where to add tests for this. I will add them if necessary.

*/
resolvers?: Array<Type<any>> | (() => Array<Type<any>>);
resolvers?: Array<Type<any>> | ((schema?: GraphQLSchema) => Array<Type<any>>);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not quire sure where the schema can be passed here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a tough one. The resolvers() function is called from here and ultimately the call comes from here:

/**
 * The internal module containing the Shop GraphQL API resolvers
 */
@Module({
    imports: [ApiSharedModule, ...createDynamicGraphQlModulesForPlugins('shop')],
    providers: [...shopResolvers, ...entityResolvers],
    exports: [...shopResolvers],
})
export class ShopApiModule {}

which means at that point we don't have access to the schema object at all. There might be some way to refactor this by using some kind of dynamic module pattern. This would be quite advanced but I think should be possible.

@michaelbromley
Copy link
Member

Hi, thanks for the contribution. This is a good addition.

Is the schema also needed in the resolvers() function because you will be dynamically creating a resolver class/object?

@sonntag-philipp
Copy link
Contributor Author

@michaelbromley thanks for the insights on the resolvers!

I think for my specific use-case it would be sufficient to just pass the current schema to the schema() method, even though passing the schema to the resolvers would be nice to have for the cases you mentioned.

I will remove the changes to the resolvers(), so this can be merged in the near future :)

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