Skip to content

Commit 4dc57c9

Browse files
chore(spec): Add HINT when gql query use snake_case (#3353)
## Description I have spent a few minutes understanding why my code didn't work and it turned out that I used `bcc_emails` instead of `bccEmail`. I remember doing the same mistake a while back. We directly access `res["data"]` so the error is pretty cryptic. I think we could add nicer error message for next time.
1 parent 78c3830 commit 4dc57c9

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

spec/rails_helper.rb

+6
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,9 @@ def pp(*args)
77
ap arg, {sort_vars: false, sort_keys: false, indent: -2}
88
end
99
end
10+
11+
def pps(*args)
12+
pp "--------------------------------------"
13+
pp(*args)
14+
pp "--------------------------------------"
15+
end

spec/support/graphql_helper.rb

+9-1
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,18 @@ def execute_graphql(current_user: nil, query: nil, current_organization: nil, cu
3030
}
3131
)
3232

33-
LagoApiSchema.execute(
33+
res = LagoApiSchema.execute(
3434
query,
3535
**args
3636
)
37+
38+
res["errors"]&.each do |e|
39+
if e.dig("extensions", "code") == "undefinedField" && e.dig("extensions", "fieldName").match?(/_/)
40+
pps "HINT: GraphQL field name should use camelCase even if its declaration is snake_case."
41+
end
42+
end
43+
44+
res
3745
end
3846

3947
def expect_graphql_error(result:, message:)

0 commit comments

Comments
 (0)