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

Question: TypeModifcation - Replace field with context #112

Open
pLeminoq opened this issue Nov 16, 2020 · 0 comments
Open

Question: TypeModifcation - Replace field with context #112

pLeminoq opened this issue Nov 16, 2020 · 0 comments

Comments

@pLeminoq
Copy link

Hello,

we have the issue, that we want to replace a field in our protobuf types depending on the context (the DateFetchingEnvironment). The use case for this is that our type contains a map of languages to labels.
We want to resolve the label as a string depending on the Accept-Language Header sent by the client and thus need the context of the request for the type modification.
As far as I understand it, if we use Type.find(...).replaceField(...) we need to implement type coercing which does not have access to the context.
Our approach was to implement two SchemaModifications:

  1. Remove the label field:
@SchemaModification
TypeModification removeMultiLanguageLabel = Type.find(....).removeField("label");
  1. Re-add the label field as a String
@SchemaModification(addField = "label", onType = ...)
String addLabel(... type, DataFetchingEnvironment env) {
    return LabelProcessor.getBestMatch(env.getContext().getLanguageCode(), type.getLabel());  
}

However, it seems we cannot guarantee the order in which the modifications are executed.

Is there a solution to this problem that we overlook?
Otherwise, would it be possible to add a parameter to the SchemaModifcation Annotation that ensures the order in which they are applied?

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

No branches or pull requests

1 participant