The ability to represent empty objects
Based on this: https://github.com/graphql/graphql-js/issues/937#issuecomment-432857507 Currently we can't represent an empty object type: ```graphql type Mutation { createUser(email: String!, password: String!): CreateUserPayload! } type UserWithEmailAlreadyExists type WeakPassword type AuthPayload { user: User! token: AccessToken! } union CreateUserPayload = UserWithEmailAlreadyExists | WeakPassword | AuthPayload ``` This fails with `graphql-js` with the following error: ``` Error: Type UserWithEmailAlreadyExists must define one or more fields. Type WeakPassword must define one or more fields. at assertValidSchema (/Users/skainswo/dev/kumo/newer-world/api/node_modules/graphql/type/validate.js:71:11) at Object.validate (/Users/skainswo/dev/kumo/newer-world/api/node_modules/graphql/validation/validate.js:55:35) at doRunQuery (/Users/skainswo/dev/kumo/newer-world/api/node_modules/apollo-server-core/src/runQuery.ts:181:30) at /Users/skainswo/dev/kumo/newer-world/api/node_modules/apollo-server-core/src/runQuery.ts:80:39 at process._tickCallback (internal/process/next_tick.js:68:7) ``` The usecase is legit though. There is an explicit check to disallow types with zero fields at `graphql-js`: https://github.com/graphql/graphql-js/blob/4116e2fc4fe36688f683258388f4a2d52076d199/src/type/validate.js#L273-L278 How about explicitly allowing empty fields in the spec? It's super useful for implementing algebraic types.
Posted by MOZGIII on Feb 28, 2019, 5:11 PM
Tags
Related issues
- Custom games stuck on "finding server" for all european servers
- Feature request: add ACP (Agent Client Protocol) stdio JSON-RPC mode
- Forza Horizon 6 (2483190)
- Turn off integrated browser for default
- Weekly updates are too frequent
- [BUG] Max 20x plan: 100% usage after 2 hours of light work (5 commits, no agents)
Raise real-world problems, find people facing the same issue, and discuss solutions.4,000 issues0 comments
github (Sysadmin)
Custom games stuck on "finding server" for all european servers
Feature request: add ACP (Agent Client Protocol) stdio JSON-RPC mode
Forza Horizon 6 (2483190)
Turn off integrated browser for default
Weekly updates are too frequent
[BUG] Max 20x plan: 100% usage after 2 hours of light work (5 commits, no agents)
Add gemini-3.1-pro-preview
[TF2] Feature request: Bring Back Quickplay
The ability to represent empty objects
Based on this: https://github.com/graphql/graphql-js/issues/937#issuecomment-432857507 Currently we can't represent an empty object type: ```graphql type Mutation { createUser(email: String!, password: String!): CreateUserPayload! } type UserWithEmailAlreadyExists type WeakPassword type AuthPayload { user: User! token: AccessToken! } union CreateUserPayload = UserWithEmailAlreadyExists | WeakPassword | AuthPayload ``` This fails with `graphql-js` with the following error: ``` Error: Type UserWithEmailAlreadyExists must define one or more fields. Type WeakPassword must define one or more fields. at assertValidSchema (/Users/skainswo/dev/kumo/newer-world/api/node_modules/graphql/type/validate.js:71:11) at Object.validate (/Users/skainswo/dev/kumo/newer-world/api/node_modules/graphql/validation/validate.js:55:35) at doRunQuery (/Users/skainswo/dev/kumo/newer-world/api/node_modules/apollo-server-core/src/runQuery.ts:181:30) at /Users/skainswo/dev/kumo/newer-world/api/node_modules/apollo-server-core/src/runQuery.ts:80:39 at process._tickCallback (internal/process/next_tick.js:68:7) ``` The usecase is legit though. There is an explicit check to disallow types with zero fields at `graphql-js`: https://github.com/graphql/graphql-js/blob/4116e2fc4fe36688f683258388f4a2d52076d199/src/type/validate.js#L273-L278 How about explicitly allowing empty fields in the spec? It's super useful for implementing algebraic types.
Comments (0)
No comments yet. Start the discussion.