Automatic parsing of `ISO8601Date` and other custom types
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Bắt đầu bằng cách áp dụng thiết lập tải lại schema trong test/test_query_result.rb và chạy bundle exec rake test TEST=test/test_query_result.rb để tái hiện ba lỗi ép kiểu. Kiểm tra GraphQL::Client.load_schema và cách xử lý các kiểu dựng sẵn; công việc được xem là hoàn tất khi ISO8601Date, ISO8601DateTime và các giá trị scalar tùy chỉnh liên quan được ép kiểu chính xác mà không monkey-patching GraphQL::Schema::BUILT_IN_TYPES.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
We use graphql-ruby and graphql-client to talk to each other. The graphql-ruby library defines a few extra types beyond the standard GraphQL types, e.g. ISO8601Date, ISO8601DateTime, etc, which we make use of.
In the client we've found that the values of these fields are not getting automatically cast back to Date / Time objects, like they do for other types of object.
I was wondering what might be the best way to get automatic casting for these types. At the moment the only way I can see it might work is by monkey-patching the GraphQL::Schema::BUILT_IN_TYPES hash, which is a bit 🤢 .
module GraphQL
class Schema
BUILT_IN_TYPES['ISO8601Date'] = GraphQL::Types::ISO8601Date
BUILT_IN_TYPES['ISO8601DateTime'] = GraphQL::Types::ISO8601DateTime
end
end
Is there a better way of managing this? I can imagine that other GraphQL schemas might have other sorts of custom types, but then how should they be re-interpreted by the client?
Incidentally the tests don't tickle this situation, as the schema is defined using the DSL. To get the datetime/date parsing tests to fail, change test/test_query_result.rb to dump/reload the schema:
ReloadedSchema = GraphQL::Client.load_schema(Schema.execute(GraphQL::Introspection.query(include_deprecated_args: true, include_schema_description: true, include_specified_by_url: true, include_is_repeatable: true)))
def setup
@client = GraphQL::Client.new(schema: ReloadedSchema, execute: Schema, enforce_collocated_callers: true)
end
Then the test fails:
bundle exec rake test TEST=test/test_query_result.rb
Run options: --seed 9819
# Running:
F.........F.......F...................
Finished in 0.077330s, 491.4005 runs/s, 1551.7910 assertions/s.
1) Failure:
TestQueryResult#test_interface_within_union_values [test/test_query_result.rb:592]:
Expected: 1970-01-01 00:00:01 UTC
Actual: "1970-01-01T01:00:01+01:00"
2) Failure:
TestQueryResult#test_date_scalar_casting [test/test_query_result.rb:628]:
--- expected
+++ actual
@@ -1 +1,3 @@
-#<Date: 1970-01-01 ((2440588j,0s,0n),+0s,2299161j)>
+# encoding: US-ASCII
+# valid: true
+"1970-01-01"
3) Failure:
TestQueryResult#test_datetime_scalar_casting [test/test_query_result.rb:610]:
Expected: 1970-01-01 01:00:00 +0100
Actual: "1970-01-01T01:00:00+01:00"
38 runs, 120 assertions, 3 failures, 0 errors, 0 skips
rake aborted!
Adding the "monkey patch" above then re-fixes the tests as the casting happens automatically.
This all feels a bit gross! Is there a better way?
Thanks!
- Ngôn ngữ chính
- Ruby
- Star
- 78
- Fork
- 228
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của github-community-projects/graphql-client
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 45/100
github-community-projects/graphql-client#78 · 1 bình luận ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
github-community-projects/graphql-client#77 · 2 bình luận ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
github-community-projects/graphql-client#76 · 4 bình luận · 1 reaction ·
-
Errors not populating correctlyĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
github-community-projects/graphql-client#75 · 1 bình luận · 1 reaction ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
github-community-projects/graphql-client#67 · 2 bình luận ·
Tất cả issue của github-community-projects/graphql-client
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
misa.G should not be definedĐang mởdata error
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
riscv/riscv-unified-db#2648 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
P2 testing
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
Maintainer thường phản hồi trong vòng 1 ngày