Skip to content

Migration v4 - context & DataSource #7096

Answered by glasser
RemyMachado asked this question in Q&A
Discussion options

You must be logged in to vote

There's an example of how to do this in the migration guide, specifically under "If you want to access your entire context's value within your DataSource". (It takes advantage of the fact that you can access this inside a class's constructor even before the class is fully constructed.)

On the other hand, if there's only one thing like this that you want to pull off the context (eg userJwtPayload), another alternative would be to not pass the entire context into your class and instead just pass the userJwtPayload itself in, which removes the circular dependency (and also means that when writing tests for your data source class you don't have to mock out the entire context object!).

Replies: 1 comment 9 replies

Comment options

You must be logged in to vote
9 replies
@glasser
Comment options

@simplecommerce
Comment options

@trevor-scheer
Comment options

@simplecommerce
Comment options

@trevor-scheer
Comment options

Answer selected by RemyMachado
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants