-
Notifications
You must be signed in to change notification settings - Fork 519
/
strict_language_conventions.ex
62 lines (49 loc) · 1.42 KB
/
strict_language_conventions.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
defmodule Absinthe.Adapter.StrictLanguageConventions do
@moduledoc """
Strict version of `Absinthe.Adapter.LanguageConventions` that will reject
improperly formatted external names.
For example, this document:
```graphql
{
create_user(user_id: 2) {
first_name
last_name
}
}
```
Would result in name-mismatch errors returned to the client.
The client should instead send the camelcase variant of the names:
```graphql
{
createUser(userId: 2) {
firstName
lastName
}
}
```
See `Absinthe.Adapter.LanguageConventions` for more information.
"""
use Absinthe.Adapter
@doc """
Converts a camelCase to snake_case
Returns `nil` if the converted internal name does not match the converted external name.
See `Absinthe.Adapter.LanguageConventions.to_internal_name/2`
"""
@impl Absinthe.Adapter
def to_internal_name(external_name, role) do
internal_name = Absinthe.Adapter.LanguageConventions.to_internal_name(external_name, role)
if external_name == Absinthe.Adapter.LanguageConventions.to_external_name(internal_name, role) do
internal_name
else
nil
end
end
@doc """
Converts a snake_case to camelCase
See `Absinthe.Adapter.LanguageConventions.to_external_name/2`
"""
@impl Absinthe.Adapter
def to_external_name(internal_name, role) do
Absinthe.Adapter.LanguageConventions.to_external_name(internal_name, role)
end
end