Add location fields to type definitions #454
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Addresses #444
Overview
This change adds a
Loc: errors.Location
field to all definition structs defined in thetypes
package. These struct fields are populated when the schema is parsed; theLine
andColumn
fields inerrors.Location
represents the first character of the identifier for that definition.For example:
This change strictly adds the
Loc: errors.Location
field to definitions that don't already have it. Definitions that already have location fields such asInputValueDefinition
were not touched.Motiviation and Examples
Tools built against a schema will most certainly need line/column source mapping as an additional form of identification when the
name
of a definition isn't enough.For a specific example: as explained in #444, location data is important in our usage of graphql-go because a majority of schema validation occurs after parsing the schema (i.e. the schema syntax is valid, but there are other issues that aren't caught by the parser). Without location data on definitions, we won't be able to surface the lines and columns of domain-specific schema issues in our error messages.
Below are a few examples that I hope can showcase the importance of location data in definitions
Loc on ObjectTypeDefinition
Given the syntax-valid schema below:
The
Loc
field inObjectTypeDefinition
will allow us to produce the following error:Loc on FieldDefinition
The
Loc
field inFieldDefinition
will allow us to produce the following error: