Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix exception when field name contains all invalid characters #1096

Conversation

aaronrenner
Copy link
Contributor

This exception is raised when the entire artifact name is invalid (like "1").

== Compilation error in file lib/my_app/schema.ex ==
** (MatchError) no match of right hand side value: nil
    lib/absinthe/phase/schema/validation/names_must_be_valid.ex:34: Absinthe.Phase.Schema.Validation.NamesMustBeValid.valid_name?/1
    lib/absinthe/phase/schema/validation/names_must_be_valid.ex:20: Absinthe.Phase.Schema.Validation.NamesMustBeValid.validate_names/1
    lib/absinthe/blueprint/transform.ex:16: anonymous fn/3 in Absinthe.Blueprint.Transform.prewalk/2
    lib/absinthe/blueprint/transform.ex:109: Absinthe.Blueprint.Transform.walk/4
    (elixir 1.10.2) lib/enum.ex:1520: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
    lib/absinthe/blueprint/transform.ex:145: anonymous fn/4 in Absinthe.Blueprint.Transform.walk_children/5
    (elixir 1.10.2) lib/enum.ex:2111: Enum."-reduce/3-lists^foldl/2-0-"/3
    lib/absinthe/blueprint/transform.ex:114: Absinthe.Blueprint.Transform.walk/4
    (elixir 1.10.2) lib/enum.ex:1520: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
    (elixir 1.10.2) lib/enum.ex:1520: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
    lib/absinthe/blueprint/transform.ex:145: anonymous fn/4 in Absinthe.Blueprint.Transform.walk_children/5
    (elixir 1.10.2) lib/enum.ex:2111: Enum."-reduce/3-lists^foldl/2-0-"/3
    lib/absinthe/blueprint/transform.ex:114: Absinthe.Blueprint.Transform.walk/4
    (elixir 1.10.2) lib/enum.ex:1520: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
    lib/absinthe/blueprint/transform.ex:145: anonymous fn/4 in Absinthe.Blueprint.Transform.walk_children/5
    (elixir 1.10.2) lib/enum.ex:2111: Enum."-reduce/3-lists^foldl/2-0-"/3
    lib/absinthe/blueprint/transform.ex:114: Absinthe.Blueprint.Transform.walk/4
    lib/absinthe/blueprint/transform.ex:15: Absinthe.Blueprint.Transform.prewalk/2
    lib/absinthe/phase/schema/validation/names_must_be_valid.ex:11: Absinthe.Phase.Schema.Validation.NamesMustBeValid.run/2
    lib/absinthe/pipeline.ex:369: Absinthe.Pipeline.run_phase/3

This fixes that exception by simplifying the code by using Regex.match?/2 together with beginning and end of line anchors.

It also adds a new kind: "enum value".

This exception is raised when the entire artifact name is invalid (like "1").

    == Compilation error in file lib/my_app/schema.ex ==
    ** (MatchError) no match of right hand side value: nil
        lib/absinthe/phase/schema/validation/names_must_be_valid.ex:34: Absinthe.Phase.Schema.Validation.NamesMustBeValid.valid_name?/1
        lib/absinthe/phase/schema/validation/names_must_be_valid.ex:20: Absinthe.Phase.Schema.Validation.NamesMustBeValid.validate_names/1
        lib/absinthe/blueprint/transform.ex:16: anonymous fn/3 in Absinthe.Blueprint.Transform.prewalk/2
        lib/absinthe/blueprint/transform.ex:109: Absinthe.Blueprint.Transform.walk/4
        (elixir 1.10.2) lib/enum.ex:1520: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
        lib/absinthe/blueprint/transform.ex:145: anonymous fn/4 in Absinthe.Blueprint.Transform.walk_children/5
        (elixir 1.10.2) lib/enum.ex:2111: Enum."-reduce/3-lists^foldl/2-0-"/3
        lib/absinthe/blueprint/transform.ex:114: Absinthe.Blueprint.Transform.walk/4
        (elixir 1.10.2) lib/enum.ex:1520: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
        (elixir 1.10.2) lib/enum.ex:1520: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
        lib/absinthe/blueprint/transform.ex:145: anonymous fn/4 in Absinthe.Blueprint.Transform.walk_children/5
        (elixir 1.10.2) lib/enum.ex:2111: Enum."-reduce/3-lists^foldl/2-0-"/3
        lib/absinthe/blueprint/transform.ex:114: Absinthe.Blueprint.Transform.walk/4
        (elixir 1.10.2) lib/enum.ex:1520: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
        lib/absinthe/blueprint/transform.ex:145: anonymous fn/4 in Absinthe.Blueprint.Transform.walk_children/5
        (elixir 1.10.2) lib/enum.ex:2111: Enum."-reduce/3-lists^foldl/2-0-"/3
        lib/absinthe/blueprint/transform.ex:114: Absinthe.Blueprint.Transform.walk/4
        lib/absinthe/blueprint/transform.ex:15: Absinthe.Blueprint.Transform.prewalk/2
        lib/absinthe/phase/schema/validation/names_must_be_valid.ex:11: Absinthe.Phase.Schema.Validation.NamesMustBeValid.run/2
        lib/absinthe/pipeline.ex:369: Absinthe.Pipeline.run_phase/3

This fixes that exception by simplifying the code by using `Regex.match?/2`
together with beginning and end of line anchors.

It also adds a new kind: "enum value"
@benwilson512 benwilson512 merged commit 5d41e37 into absinthe-graphql:master Aug 12, 2021
@benwilson512
Copy link
Contributor

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants