Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions lib/absinthe/phase/schema/validation/names_must_be_valid.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ defmodule Absinthe.Phase.Schema.Validation.NamesMustBeValid do
use Absinthe.Phase
alias Absinthe.Blueprint

@valid_name_regex ~r/^[_A-Za-z][_0-9A-Za-z]*$/

def run(bp, _) do
bp = Blueprint.prewalk(bp, &validate_names/1)
Expand All @@ -30,7 +29,7 @@ defmodule Absinthe.Phase.Schema.Validation.NamesMustBeValid do
end

defp valid_name?(name) do
Regex.match?(@valid_name_regex, name)
Regex.match?(valid_name_regex(), name)
end

defp error(object, data) do
Expand All @@ -42,23 +41,20 @@ defmodule Absinthe.Phase.Schema.Validation.NamesMustBeValid do
}
end

@description """
Name does not match possible #{inspect(@valid_name_regex)} regex.

> Names in GraphQL are limited to this ASCII subset of possible characters to
> support interoperation with as many other systems as possible.

Reference: https://graphql.github.io/graphql-spec/June2018/#sec-Names

"""
defp valid_name_regex(), do: ~r/^[_A-Za-z][_0-9A-Za-z]*$/

def explanation(%{artifact: artifact, value: value}) do
artifact_name = String.capitalize(artifact)

"""
#{artifact_name} #{inspect(value)} has invalid characters.

#{@description}
Name does not match possible #{inspect(valid_name_regex())} regex.

> Names in GraphQL are limited to this ASCII subset of possible characters to
> support interoperation with as many other systems as possible.

Reference: https://graphql.github.io/graphql-spec/June2018/#sec-Names
"""
end
end
Loading