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

Exception when exposing Mailjet::Resource in GraphQL Type #262

Open
BrahimDahmani opened this issue Sep 13, 2024 · 0 comments · May be fixed by #263
Open

Exception when exposing Mailjet::Resource in GraphQL Type #262

BrahimDahmani opened this issue Sep 13, 2024 · 0 comments · May be fixed by #263

Comments

@BrahimDahmani
Copy link

When attempting to expose Mailjet::Resource in a GraphQL Type, the following exception is raised:

GraphQL::Backtrace::TracedError - Unhandled error during GraphQL execution:
                Failed to implement MessageHistory.event_at, tried:
              - `Types::ResourceTypes::MessageHistoryType#event_at`, which did not exist
              - `Mailjet::Messagehistory#event_at`, which did not exist
              - Looking up hash key `:event_at` or `"event_at"` on `#<Mailjet::Messagehistory:0x00005622b03ad6e8>`, but it wasn't a Hash
              To implement this field, define one of the methods above (and check for typos), or supply a `fallback_value`.

Root cause:
The issue stems from GraphQL's field resolution mechanism. GraphQL checks if a field exists using .respond_to?(field). However, Mailjet uses method_missing to dynamically handle attribute access, which causes .respond_to?(field) to always return false.

Proposed solution:
To resolve this, Mailjet::Resource should implement .respond_to_missing?. This will ensure that .respond_to?(field) returns the correct value for dynamically generated attribute methods, allowing GraphQL to properly resolve fields on Mailjet resources.

I'll make a PR!

Thank you 🙂

@BrahimDahmani BrahimDahmani linked a pull request Sep 13, 2024 that will close this issue
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 a pull request may close this issue.

1 participant