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

Add a method TranslateType<T>(string path) to translate types globally #36

Open
gmiserez opened this issue Apr 5, 2023 · 1 comment
Labels
Translations This concerns the Translations Package

Comments

@gmiserez
Copy link
Collaborator

gmiserez commented Apr 5, 2023

To avoid having to add the Translate directive on every enum/class that we want to translate, it would be interesting to be able to translate them globally.
A Method TranslateType<T>(string path) could be added to achieve this:

new ServiceCollection()
  .AddGraphQLServer()
  .AddQueryType<Query>()
  .AddTranslation(
    c => c.TranslateType<Country>("Refs/Countries")
  );

Now every field in our schema that is of type Country or [Country] would be translated.

Example:

public class Query 
{
    public IReadOnlyList<Country> GetAvailableCountries()
    {
         return new []{ Country.Usa, Country.Fr, Country.De };
    }
}

This would now generate the following GraphQL schema:

type Query {
   availableCountries: [TranslatedResourceOfCountry!]!
}

type TranslatedResourceOfCountry {
   key: Country!
   label: String
}
@gmiserez gmiserez added the Translations This concerns the Translations Package label Apr 5, 2023
@Carael
Copy link
Contributor

Carael commented Apr 5, 2023

That would be really nice. I would say either this or attribute. Not like now that we need to do both.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Translations This concerns the Translations Package
Projects
None yet
Development

No branches or pull requests

2 participants