Skip to content

Commit 7412260

Browse files
committed
Replace regex with pattern as string 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. By changing the regex to a pattern as a string it can still be used in the error message, and just needs to be compiled before usage.
1 parent f88c226 commit 7412260

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ 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]*$/
7+
@valid_name_regex "^[_A-Za-z][_0-9A-Za-z]*$"
88

99
def run(bp, _) do
1010
bp = Blueprint.prewalk(bp, &validate_names/1)
@@ -30,7 +30,9 @@ defmodule Absinthe.Phase.Schema.Validation.NamesMustBeValid do
3030
end
3131

3232
defp valid_name?(name) do
33-
Regex.match?(@valid_name_regex, name)
33+
@valid_name_regex
34+
|> Regex.compile!()
35+
|> Regex.match?(name)
3436
end
3537

3638
defp error(object, data) do
@@ -43,7 +45,7 @@ defmodule Absinthe.Phase.Schema.Validation.NamesMustBeValid do
4345
end
4446

4547
@description """
46-
Name does not match possible #{inspect(@valid_name_regex)} regex.
48+
Name does not match possible #{@valid_name_regex} regex.
4749
4850
> Names in GraphQL are limited to this ASCII subset of possible characters to
4951
> support interoperation with as many other systems as possible.

0 commit comments

Comments
 (0)