keystonejs / keystonejs/keystone

Improve error when providing a value for an option in the select field using type: ‘enum’ that isn’t a valid GraphQL and Prisma identifier

Open
#7,879 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
10k
Forks
1.3k
Avg merge
19h 14m
Merged PRs (30d)
19

Description

Using invalid enum values in `select` field options throws an error while starting the server.

```js
external: select({
type: 'enum',
options: [
{ label: '-', value: '-' },
{ label: 'Dev.to', value: 'dev' },
{ label: 'Medium', value: 'medium' },
{ label: 'Twitter', value: 'twitter' },
],
defaultValue: '-',
ui: {
displayMode: 'segmented-control',
description: 'Link to an external post written in some other platform.',
},
}),
```

Error:
```
:sparkles: Generating GraphQL and Prisma schemas
SyntaxError: Syntax Error: Invalid number, expected digit but got: "\n". (139:4)
137 |
138 | enum PostExternalType {
> 139 | -
| ^
140 | dev
141 | medium
142 | twitter
at i (/Users/dineshpandiyan/workspace/keystone-static-blog/node_modules/prettier/parser-graphql.js:1:713)
at Le (/Users/dineshpandiyan/workspace/keystone-static-blog/node_modules/prettier/parser-graphql.js:15:20811)
at Object.xe [as parse] (/Users/dineshpandiyan/workspace/keystone-static-blog/node_modules/prettier/parser-graphql.js:15:21020)
at Object.parse (/Users/dineshpandiyan/workspace/keystone-static-blog/node_modules/prettier/index.js:7334:23)
at coreFormat (/Users/dineshpandiyan/workspace/keystone-static-blog/node_modules/prettier/index.js:8645:18)
at formatWithCursor2 (/Users/dineshpandiyan/workspace/keystone-static-blog/node_modules/prettier/index.js:8837:18)
at /Users/dineshpandiyan/workspace/keystone-static-blog/node_modules/prettier/index.js:37229:12
at Object.format (/Users/dineshpandiyan/workspace/keystone-static-blog/node_modules/prettier/index.js:37243:12)
at getFormattedGraphQLSchema (/Users/dineshpandiyan/workspace/keystone-static-blog/node_modules/@keystone-6/core/dist/artifacts-92b7719e.cjs.dev.js:389:19)
at getCommittedArtifacts (/Users/dineshpandiyan/workspace/keystone-static-blog/node_modules/@keystone-6/core/dist/artifacts-92b7719e.cjs.dev.js:397:14) {
loc: { start: { line: 139, column: 4 } },
codeFrame: '\x1B[0m \x1B[90m 137 |\x1B[39m\x1B[0m\n' +
'\x1B[0m \x1B[90m 138 |\x1B[39m \x1B[36menum\x1B[39m \x1B[33mPostExternalType\x1B[39m {\x1B[0m\n' +
'\x1B[0m\x1B[31m\x1B[1m>\x1B[22m\x1B[39m\x1B[90m 139 |\x1B[39m \x1B[33m-\x1B[39m\x1B[0m\n' +
'\x1B[0m \x1B[90m |\x1B[39m \x1B[31m\x1B[1m^\x1B[22m\x1B[39m\x1B[0m\n' +
'\x1B[0m \x1B[90m 140 |\x1B[39m dev\x1B[0m\n' +
'\x1B[0m \x1B[90m 141 |\x1B[39m medium\x1B[0m\n' +
'\x1B[0m \x1B[90m 142 |\x1B[39m twitter\x1B[0m'
}
error Command failed with exit code 1.
```

Contributor guide

Open the contributing guide

Research direction

Start by tracing the select field's enum option handling from the Keystone configuration that generates the GraphQL schema, using the failing PostExternalType example as the reproduction. Check how invalid GraphQL or Prisma identifiers are reported, then add coverage for the '-' value and verify that startup produces a clear validation error instead of the formatter SyntaxError.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, typescript
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.