Skip to content

GraphQL "Syntax Error: Expected Name, found ...": causes and fixes in SDL

Last checked and updated

Syntax Error: Expected Name, found ... means the GraphQL parser was at a place where the grammar needs a name (a field, type, argument or enum value) and found something else: a }, a ), a !, or the end of the file. Causes in a schema include empty braces, empty parentheses, a missing type after :, or a file that ends mid-definition. The message gives the line and column of the token it found, which is often just after the mistake.

All the outputs below come from apigit lint, which checks .graphql and .gql files offline. A syntax problem is a graphql-syntax error and fails the run (exit code 1). Parsing stops at the first one, so a file with two mistakes reports one.

"Expected Name, found ..."

Empty braces:

type Product {
}

type Query {
  products: [Product!]!
}
$ apigit lint empty-type.graphql
empty-type.graphql
  2:1  error  graphql-syntax  Syntax Error: Expected Name, found "}".

1 problem (1 error, 0 warnings, 0 info, 0 hints)
error: lint failed: findings at severity error or above

The specification's grammar for an object type (the same in the October 2021 and September 2026 editions) is FieldsDefinition : { FieldDefinition list }: braces need at least one field. Either add a field or drop the braces. The same message, with other tokens, for the other cases:

MessageWhat was in the fileFix
Expected Name, found "}".type Product { then }add a field, or remove { }
Expected Name, found "}".name: with nothing after the colonadd the type: name: String!
Expected Name, found "}".a description "All products" as the last thing in type Query { }, with no field after ita description must be followed by the field it describes
Expected Name, found ")".products(): [Product!]!remove (); a field without arguments has no parentheses
Expected Name, found "!".[!Product]! follows the type: [Product!]
Expected Name, found <EOF>.the file ends inside product(id: finish the definition; often a cut-off paste
Expected Name, found "=".name: String! = "x" on an object fieldobject fields have no defaults; defaults belong to arguments and input fields

"Expected ":", found Name ..."

A missing colon between a field and its type:

type Product {
  id: ID!
  name String!
}

type Query {
  products: [Product!]!
}
$ apigit lint missing-colon.graphql
missing-colon.graphql
  3:8  error  graphql-syntax  Syntax Error: Expected ":", found Name "String".

1 problem (1 error, 0 warnings, 0 info, 0 hints)
error: lint failed: findings at severity error or above

The same message appears for a missing closing brace, but on the wrong line:

type Product {
  id: ID!
  name: String!

type Query {
  products: [Product!]!
}
$ apigit lint missing-brace.graphql
missing-brace.graphql
  5:6  error  graphql-syntax  Syntax Error: Expected ":", found Name "Query".

1 problem (1 error, 0 warnings, 0 info, 0 hints)
error: lint failed: findings at severity error or above

Because Product was never closed, the parser read type on line 5 as the name of another field of Product, and then wanted a colon after it. When the error points at the start of a definition, look for the } that is missing above it.

"Unexpected character" and other lexical errors

MessageWhat was in the fileWhyFix
Unexpected character: ";".id: ID!;; is not a GraphQL punctuator; the list is ! $ & ( ) ... : = @ [ ] { | }remove it; separate fields with line breaks or commas
Invalid number, expected digit but got: "n".first-name: String!a name is letters, digits and _ only, so the parser read -n... as a negative numberfirstName or first_name
Unterminated string."The name with no closing quotea one-line description must close on the same lineclose it, or use """ for several lines
Unexpected Name "Entity".type Product implements Node, Entity {interfaces are joined with &; the comma is ignored and two names follow each otherimplements Node & Entity

A trailing comma after a field is not an error: products: [Product!]!, linted clean. The specification: commas "are used to improve the legibility of source text and separate lexical tokens but are otherwise syntactically and semantically insignificant".

Schema problems are warnings

After the syntax is right, the schema itself is checked, and those findings are graphql-schema warnings, not errors:

$ apigit lint unknown-type.graphql
unknown-type.graphql
  3:10  warn   graphql-schema  Unknown type "Money".

1 problem (0 errors, 1 warning, 0 info, 0 hints)
$ apigit lint duplicate.graphql
duplicate.graphql
  1:6  warn   graphql-schema  There can be only one type named "Product".

1 problem (0 errors, 1 warning, 0 info, 0 hints)

The exit code for both is 0. The CLI documentation gives the reason: schema problems are warnings "because a file may be part of a larger schema". If your schema is one file, make them fail too:

$ apigit lint --fail-severity warn unknown-type.graphql
...
error: lint failed: findings at severity warn or above

A file with types but no Query type also lints clean, for the same reason; a mock server refuses it (see schema-first GraphQL).

In CI

$ apigit lint --format github-actions missing-colon.graphql
::error file=missing-colon.graphql,line=3,col=8,title=graphql-syntax::Syntax Error: Expected ":", found Name "String".
error: lint failed: findings at severity error or above

On GitHub Actions each such line becomes an annotation on that line of the file; Lint an OpenAPI file in GitHub Actions has a complete workflow. The rendered reference shows the same message when a schema does not parse (GraphQL schema documentation).

Sources

Related pages

Try it with your own API

Create a free workspace, add an OpenAPI file, and publish its documentation and a mock server from the same repository.

Free for individuals. No credit card.

$ npm install -g @apigit/cli$ apigit auth login$ apigit doc publish