1

I'm trying to add the internationalization feature to my database. It would be quite difficult to maintain a schema graphql if I needed to duplicate all translatable fields

type Quest {
    name @i18n  # simple
} 

type Quest {
    nameEn
    nameJa
    nameFr
    ...  # omg
}

The problem I'm facing is that field directives are only executed during a query (or, once a mutation has finished, to return the result).

I do not see how I could do something similar with resolvers. For any possible mutation, I want to check if any field has the @i18n directive, and execute it (so that it fetches my user's language locale from the context and modify the field with the locale as suffix.

In other words, I would like to make a directive to modify the key of a field, not its value.

How would you accomplish that ?

My question was purposefully made general, but if there's a platform specific solution, I'm using the GRANDstack with Neo4j as db and neo4j-graphql-js with Apollo server at the API level.

EDIT: Asked another question for a different way to solve my problem by modifying the schema at build time.

Adrien Lemaire
  • 1,744
  • 2
  • 20
  • 29
  • strange requirement ... field name? really? it will hurt client ... directive can pass info about translating requirement into context making this info accessible to resolver ... or add field resolver parameter (args)? ... more general ... shouldn't it be implemented on a ORM layer (make datasources in context i18n/lang aware)? – xadm Dec 11 '20 at 11:14

0 Answers0