You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
I would like to map a custom context type on a type-level (Subscription in this case) and all fields under that type should inherit the mapped context type.
Apollo Server v3 has decoupled the subscription server entirely and because of that, I cannot create the subscription resolver's context from ApolloServer's class constructor anymore and therefore could not pass the Express req and res objects so I decided not to pass it for subscriptions since I'm not using it anyway. I wouldn't want to make the req and res objects to become optional from the original context type either as that'd mean extra checks for those that are using it.
With that said, the context type for my Subscriptions are now different compared to those in Queries and Mutations and I would like codegen to use the appropriate type based on a simple mapping in the config. Simplified example of the interfaces' shape below:
// For Queries and MutationsinterfaceIGraphQLContext{req: Express.Request;res: Express.Response;readonlyuserId: UniqueID|null;}// For SubscriptionsinterfaceIGraphQLSubscriptionContext{readonlyuserId: UniqueID|null;}
#3052 is similar to my case but the merged solution just limits itself to the defined fields of the type in the codegen config. Having n subscription resolvers would mean having n entries in the config as well to achieve the end goal. I wouldn't want the config to grow for every new subscription resolver added. Would be nice if we can just define the type, in this case Subscription, and all fields under it would use the mapped context type.
Describe the solution you'd like
I would like all fields under the type to use the mapped context type on that type rather than the current supported feature where I would need to define each field using fieldContextTypes to achieve the end goal.
config:
fieldContextTypes:
- Subscription.readMessageFromChat#path/to/context#IGraphQLSubscriptionContext
- Subscription.listenForNotifications#path/to/context#IGraphQLSubscriptionContext
- Subscription.channelAdded#path/to/context#IGraphQLSubscriptionContext# list grows for every new subscription resolver
Describe alternatives you've considered
Maybe wildcards or pattern matching for other advanced use cases (e.g. different context type for different domains based on a substring in the field)? Not sure if this will have any big impact or even possible but just throwing ideas.
Is your feature request related to a problem? Please describe.
I would like to map a custom context type on a type-level (
Subscription
in this case) and all fields under that type should inherit the mapped context type.Apollo Server v3 has decoupled the subscription server entirely and because of that, I cannot create the subscription resolver's context from
ApolloServer
's class constructor anymore and therefore could not pass the Expressreq
andres
objects so I decided not to pass it for subscriptions since I'm not using it anyway. I wouldn't want to make thereq
andres
objects to become optional from the original context type either as that'd mean extra checks for those that are using it.With that said, the context type for my Subscriptions are now different compared to those in Queries and Mutations and I would like codegen to use the appropriate type based on a simple mapping in the config. Simplified example of the interfaces' shape below:
#3052 is similar to my case but the merged solution just limits itself to the defined fields of the type in the codegen config. Having
n
subscription resolvers would mean havingn
entries in the config as well to achieve the end goal. I wouldn't want the config to grow for every new subscription resolver added. Would be nice if we can just define the type, in this caseSubscription
, and all fields under it would use the mapped context type.Describe the solution you'd like
I would like all fields under the type to use the mapped context type on that type rather than the current supported feature where I would need to define each field using
fieldContextTypes
to achieve the end goal.rather than
Describe alternatives you've considered
Maybe wildcards or pattern matching for other advanced use cases (e.g. different context type for different domains based on a substring in the field)? Not sure if this will have any big impact or even possible but just throwing ideas.
The text was updated successfully, but these errors were encountered: