-
Notifications
You must be signed in to change notification settings - Fork 121
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
[Feature Request] Add ContextEntries
to requests that can be retrieved in custom gql
Link
#575
Comments
yes, a contributiuon would be great.
Links can access access and edit context entries already! |
Hello @knaeckeKami !
|
One way would be to add a This would already allow users to add the context and modify Contexts via the built_value builders;
A challenge is the serialization of the OperationRequest; Since the context is not serializable (it's a map of <Type, ContextEntry>, we would have to exclude it like |
Ok got it. So:
|
sounds good to me! |
@tpucci This is a life saver, thank you! Would it be possible to also have a I understand it was asked not to include it because we already have the |
Hey @bawahakim If you want to set your context per request: client.request(GSomeOperation((b) {
b
..context = const Context().withEntry(YourEntry());
}) If you want to set your context before all your existing links, create a link and put it first in your client link chain: class YourLink extends Link {
@override
Stream<Response> request(Request request, [NextLink? forward]) {
return forward(request.withContextEntry(YourEntry()));
}
}
...
Client(
link: Link.from([
YourLink(),
OtherLink(),
HttpLink(
const String.fromEnvironment('GRAPHQL_ENDPOINT'),
httpClient: httpClient,
)
]),
) What do you think? |
@tpucci Thank you! Let me explain a bit more my use case. The main issue I have is logging. Handling any error within a chain does not give me a clear stack track, only the trace of the links, so I lose information about the original caller. What I do is I inject the current stack trace in a wrapper method to ensure I can always know who the original calls was. I then use an extension method to handle any errors and use the original stack trace for my logger
This way, my stack trace bypasses anything related to the links and I immediately get the stack from the original caller, making debugging easier. This works so far. Now I also need to send a unique I can see 3 solutions, for which I have not found a way to implement:
If the abstract Appreciate your help! |
Ha, got it 👍 |
In order to create advanced
Link
s that can execute custom logic per request, we need a way to extend request withContextEntries
.Currently, generated code for a request is:
gql_exec
has a method.withContextEntry
onOperation
that we could use.I'd be happy to contribute if you think it is a good issue 🙂
(😅 Hope I did not miss something in the API that already allows us to create context entries)
Reference: #556
The text was updated successfully, but these errors were encountered: