GraphQLParser
A Julia package to parse and validate GraphQL executable documents
Documentation for GraphQLParser.
Installation
The package can be installed with Julia's package manager, either by using the Pkg REPL mode (press ]
to enter):
pkg> add GraphQLParser
or by using Pkg functions
julia> using Pkg; Pkg.add("GraphQLParser")
Use
This package can be used to check whether a document is valid
using GraphQLParser
document = """
query myQuery{
findDog
}
"""
is_valid_executable_document(document)
# true
Or return a list of validation errors
using GraphQLParser
document = """
query myQuery{
findDog
}
query myQuery{
findCat
}
"""
errors = validate_executable_document(document)
errors[1]
# GQLError
# message: There can only be one Operation named "myQuery".
# location: Line 1 Column 1
errors[2]
# GQLError
# message: There can only be one Operation named "myQuery".
# location: Line 5 Column 1
Validation
validate_executable_document
performs validation that does not require the schema and therefore does not fully validate the document as per the GraphQL specification. The validation performed includes:
- 5.2.1.1 Named operation uniqueness
- 5.2.2.1 Lone anonymous operation
- 5.4.2 Argument Uniqueness
- 5.5.1.1 Fragment name uniqueness
- 5.5.1.4 Fragments must be used
- 5.5.2.1 Fragment spread target defined
- 5.6.3 Input Object Field Uniqueness
- 5.7.3 Directives Are Unique Per Location
- 5.8.1 Variable Uniqueness
- 5.8.3 All Variable Uses Defined
- 5.8.4 All Variables Used