How to handle hyphens in GraphQL schema definitions

My mongoose pattern is as follows

var ImageFormats = new Schema({
     svg        : String,
     png-xlarge : String,
     png-small  : String
});

When I translated this into GraphQL schema, this is what I am trying

export var GQImageFormatsType: ObjectType = new ObjectType({
     name: 'ImageFormats',

     fields: {
          svg        : { type: GraphQLString },
         'png-xlarge': { type: GraphQLString },
         'png-small' : { type: GraphQLString }
 }
});

GraphQL Returns the following error: Error: Names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/ but "png-xlarge" does not.

If I try to simulate GraphQL after my Mongoose model, how can I reconcile fields? Is there a way to create an alias?

(I searched on the graffiti and stackoverflow forums, but couldn't find a similar question)

+1
source share
1 answer

GraphQL Returns the following error: Error: Names must match / ^ [_ a-zA-Z] [_ a-zA-Z0-9] * $ /, but "png-xlarge" does not.

GraphQL , 'png-xlarge' . , . . , -, '. , . GraphQL.

GraphQL Mongoose, ? ?

resolve :

pngXLarge: { 
    type: GraphQLString,
    resolve: (imageFormats) => {
        // get the value `xlarge` from the passed mongoose object 'imageFormats'
        const xlarge = imageFormats['png-xlarge'];
        return xlarge;
    },
},
+2

Source: https://habr.com/ru/post/1665457/


All Articles