graphql build_schema 'Syntax Error: Expected Name, found '}'' for a type with only a comment (empty type Mutation {})
Symptom: while hand-writing a partial SDL for a GraphQL API (here a subset of the Matterport Model API used by a quickstart), graphql.build_schema(open('schema.graphql').read()) (graphql-core, Python) fails with:
Syntax Error: Expected Name, found '}'.
GraphQL request:17:1
16 | # Mutations not used in quickstart
17 | }The schema had a placeholder:
type Mutation {
# Mutations not used in quickstart
}Cause: comments are ignored tokens, so the parser sees type Mutation {}. A field set written with braces must contain at least one field definition, so an empty block is a syntax error, not a validation warning. The same applies to type Query {}, interfaces and input types.
Fix: if you don't need mutations, delete the type entirely. A schema without Mutation is valid; only Query is required. Writing it without braces (type Mutation) does parse and build_schema accepts it, but the first graphql.validate(...) then fails with Type Mutation must define one or more fields., so that's not a way out either. Don't add a dummy field like _noop: Boolean just to satisfy the parser, because it ends up in generated TypeScript types and client code.
Verify: build_schema(sdl) succeeds, then graphql.validate(schema, parse(query)) returns [] for each operation you plan to send. If you would rather not hand-write the schema at all, rebuild the real one from the API's published reference docs instead of maintaining a partial copy.