Search code examples
javascriptnode.jsgraphqlapollo-serverkeystonejs

GraphQL Error when parsing "ç": Cannot parse the unexpected character "\u00E7"


I'm using KeystoneJS with GraphQL. In my setup I'm preparing a drop-down menu field (Selectin KeystoneJS)

    language: {type:Select, options: ['English','Français', 'Deutsch'], defaultValue: 'English'},

but when I start the KeystoneJS app I get

GraphQLError: Syntax Error: Cannot parse the unexpected character "\u00E7".
    at syntaxError (/Users/user0/Documents/sandbox/keystone-blank/node_modules/graphql/error/syntaxError.js:15:10)
at readToken (/Users/user0/Documents/sandbox/keystone-blank/node_modules/graphql/language/lexer.js:270:38)
at Object.lookahead (/Users/user0/Documents/sandbox/keystone-blank/node_modules/graphql/language/lexer.js:54:43)
at Object.advanceLexer [as advance] (/Users/user0/Documents/sandbox/keystone-blank/node_modules/graphql/language/lexer.js:44:33)
at Parser.expectToken (/Users/user0/Documents/sandbox/keystone-blank/node_modules/graphql/language/parser.js:1399:19)
at Parser.parseName (/Users/user0/Documents/sandbox/keystone-blank/node_modules/graphql/language/parser.js:94:22)
at Parser.parseEnumValueDefinition (/Users/user0/Documents/sandbox/keystone-blank/node_modules/graphql/language/parser.js:1014:21)
at Parser.optionalMany (/Users/user0/Documents/sandbox/keystone-blank/node_modules/graphql/language/parser.js:1497:28)
at Parser.parseEnumValuesDefinition (/Users/user0/Documents/sandbox/keystone-blank/node_modules/graphql/language/parser.js:1002:17)
at Parser.parseEnumTypeDefinition (/Users/user0/Documents/sandbox/keystone-blank/node_modules/graphql/language/parser.js:986:23)
at Parser.parseTypeSystemDefinition (/Users/user0/Documents/sandbox/keystone-blank/node_modules/graphql/language/parser.js:705:23)
at Parser.parseDefinition (/Users/user0/Documents/sandbox/keystone-blank/node_modules/graphql/language/parser.js:146:23)
at Parser.many (/Users/user0/Documents/sandbox/keystone-blank/node_modules/graphql/language/parser.js:1518:26)
at Parser.parseDocument (/Users/user0/Documents/sandbox/keystone-blank/node_modules/graphql/language/parser.js:111:25)
at parse (/Users/user0/Documents/sandbox/keystone-blank/node_modules/graphql/language/parser.js:36:17)
at parseDocument (/Users/user0/Documents/sandbox/keystone-blank/node_modules/graphql-tag/lib/graphql-tag.umd.js:135:16)
at gql (/Users/user0/Documents/sandbox/keystone-blank/node_modules/graphql-tag/lib/graphql-tag.umd.js:176:10)
at /Users/user0/Documents/sandbox/keystone-blank/node_modules/@keystonejs/keystone/lib/Keystone/index.js:508:23
at Array.map (<anonymous>)
    at Keystone.getTypeDefs (/Users/user0/Documents/sandbox/keystone-blank/node_modules/@keystonejs/keystone/lib/Keystone/index.js:508:8)
    at Keystone.getAdminSchema (/Users/user0/Documents/sandbox/keystone-blank/node_modules/@keystonejs/keystone/lib/Keystone/index.js:520:27)
    at createApolloServer (/Users/user0/Documents/sandbox/keystone-blank/node_modules/@keystonejs/app-graphql/lib/apolloServer.js:147:17) {
        message: 'Syntax Error: Cannot parse the unexpected character "\\u00E7".',
        locations: [ { line: 4, column: 13 } ]
    }

When I change 'Français' to 'Francais', it works fine. It would seem that GraphQL (or Keystone) doesn't like non-standard characters. Does anyone know exactly what's going on here, and how I might fix it so I can use the proper form, 'Français' ? Thanks!


Solution

  • According to the spec, characters inside strings are limited to the following characters:

    /[\u0009\u000A\u000D\u0020-\uFFFF]/
    

    This includes the character "ç". However, names of things in the schema (types, fields, arguments, etc.) are constrained to a much smaller set of valid characters and must follow this pattern:

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

    If KeystoneJS converts the above options to a set of enum values, this will result in the syntax error you're seeing because an enum value has to be a valid name.

    Normally, the workaround here is to just map the enum values to their correct equivalents client-side.