John Davis
John Davis

Reputation: 413

Hypen is not supporting GraphQL

I am new to graphQL, When I am trying to define a schema with hyphen/dash it shows error. But underscore is not making any issues.

# Type of Hello
enum HowAreYou{
  Hello-Hello
  Hai-Hai
}



throw (0, _error.syntaxError)(source, position, 'Invalid number,         expected digit but got: ' + printCharCode(code) + '.');
 ^
GraphQLError: Syntax Error GraphQL request (176:9) Invalid number,     expected digit but got: "H".

175: enum HowAreYou{
176:   Hello-Hello
         ^
177:   Hai-Hai

Upvotes: 0

Views: 2280

Answers (2)

John Davis
John Davis

Reputation: 413

We can specify the required enum in our schema part and write the corresponding custom in our resolver part.

const typeDefs = `
  enum Color {
    RED
  };
`

const resolvers = {
  Color: {
    RED: '#FF0000',
  }
};

Upvotes: 1

Daniel Rearden
Daniel Rearden

Reputation: 84737

That's intentional -- per the specification, hyphens are not a valid character when naming entities in GraphQL. Names are supposed to meet this pattern:

/[_A-Za-z][_0-9A-Za-z]*/

That means only letters, numbers and underscores are allowed, and names cannot begin with a number.

Upvotes: 1

Related Questions