GraphQL Schema Type with no fields, or scalar type with arguments

Viewed 478

I have the following situation, my data look like this:

Product
    _id: ID
    name
        en_US: String
        nl_NL: String
    weight: Number

Now I'd like to make the following GraphQL query:

{
  products {
    _id
    name(locale:"nl_NL")
  }
}

This works when adding a resolver to the productType, which returns the right locale based on the given argument. I'd rather not repeat this type + resolver all the time everytime I use this locale structure in my database. So it seems logical to create a localeType, and pass the right argument (locale) to this type, to then resolve the locale there.

For this I'd imagine to need either a Schema Type with no fields (which is not possible afaik):

const localeType = new GraphQLObjectType({
    name: 'Locale',
    fields: {
        resolve: (locale, args) => this[args.locale],
    },
});

Or a Scalar Type which accepts arguments.

Are either of these possible in GraphQL currently? And what would the syntax be?

Or any other way to solve this issue?

0 Answers
Related