Skip to content

Commit 251ab6d

Browse files
committed
Move regex out of module attribute to support OTP 28
OTP 28 changes the implementation of the regex module, and as a result you can no longer use regexes as module attributes.
1 parent f88c226 commit 251ab6d

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

lib/absinthe/phase/schema/validation/names_must_be_valid.ex

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ defmodule Absinthe.Phase.Schema.Validation.NamesMustBeValid do
44
use Absinthe.Phase
55
alias Absinthe.Blueprint
66

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

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

3231
defp valid_name?(name) do
33-
Regex.match?(@valid_name_regex, name)
32+
Regex.match?(valid_name_regex(), name)
3433
end
3534

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

45-
@description """
46-
Name does not match possible #{inspect(@valid_name_regex)} regex.
47-
48-
> Names in GraphQL are limited to this ASCII subset of possible characters to
49-
> support interoperation with as many other systems as possible.
50-
51-
Reference: https://graphql.github.io/graphql-spec/June2018/#sec-Names
52-
53-
"""
44+
defp valid_name_regex(), do: ~r/^[_A-Za-z][_0-9A-Za-z]*$/
5445

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

5849
"""
5950
#{artifact_name} #{inspect(value)} has invalid characters.
6051
61-
#{@description}
52+
Name does not match possible #{inspect(valid_name_regex())} regex.
53+
54+
> Names in GraphQL are limited to this ASCII subset of possible characters to
55+
> support interoperation with as many other systems as possible.
56+
57+
Reference: https://graphql.github.io/graphql-spec/June2018/#sec-Names
6258
"""
6359
end
6460
end

0 commit comments

Comments
 (0)