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

Camelcasing => ClientError between 0.3.3 & 0.3.7 #76

Open
ATMartin opened this issue May 3, 2020 · 4 comments
Open

Camelcasing => ClientError between 0.3.3 & 0.3.7 #76

ATMartin opened this issue May 3, 2020 · 4 comments

Comments

@ATMartin
Copy link

ATMartin commented May 3, 2020

When updating from graphlient v0.3.3 to v0.3.7, I'm seeing an odd error:

Graphlient::Errors::ClientError: Field 'image_raw' doesn't exist on type 'Resource'

Here's a rough cut of the code resulting in this error:

def query_for(user)
    @client = Graphlient::Client.new(my_cool_service_url)
    @client.query(my_query, { email: user.email })
end

def my_query
  <<~'GRAPHQL'
      query($email: String!) {
        user(email: $email) {
          registrations(first: 10) {
            edges {
              node {
                resource {
                  name
                  slug
                  image_raw
                }
                path {
                  progress
                  points {
                    total
                    earned
                  }
                }
              }
            }
          }
        }
      }
  GRAPHQL
end

Nothing's changed in our API & I can duplicate this error by changing nothing but the gem version.

I poked around a bit in IRB and found that I get back a generic Class from @client.schema in 0.3.7, whereas I see a much richer Graphlient::Schema object in 0.3.3. Has something changed in schema parsing that might cause this error? Am I missing a syntactic change I need to make? I did see the new schema_path option, but that appears to be optional.

Interestingly, if I switch to the image property (which returns a URL to a compressed version of image_raw), everything works fine. Maybe this property name is breaking a new rule? Our implementation includes a handful of other queries with similar failures in 0.3.7 that work on 0.3.3 & when directly posted via Insomnia.

I looked through the diff between these versions, as well as related issues/PRs, and didn't see anything right away that would cause this. Since most of it is delegated, I also browsed through graphql-clients changes with no luck. That said, I'm frustrated so my comprehension may be compromised.

Regardless, thanks for this client!

@ATMartin ATMartin changed the title ClientError between 0.3.3 & 0.3.7 Camelcasing => ClientError between 0.3.3 & 0.3.7 May 3, 2020
@ATMartin
Copy link
Author

ATMartin commented May 3, 2020

Fresh eyes this morning have led me down the "camelCase" path. In 0.3.7, my schema resolves to looking for an imageRaw field - which our API rejects as a non-existent field. This doesn't happen in 0.3.3.

It looks like this may be caused by things down in graphql itself, in which case we're pinning graphlient versions until I can convince the API team to do some work! Is there any way to disable this auto-camelcasing behavior at the Graphlient level?

@dblock
Copy link
Collaborator

dblock commented May 3, 2020

It looks like this may be caused by things down in graphql itself, in which case we're pinning graphlient versions until I can convince the API team to do some work! Is there any way to disable this auto-camelcasing behavior at the Graphlient level?

AFAIK no, if you find a way to do this in the graphql-ruby client we should be able to expose it.

@ashkan18
Copy link
Owner

ashkan18 commented May 6, 2020

Graphql Ruby is camelCaseing by default to match GraphQL recommended naming approach, in our case, when you get response back it should already be snake_cased for you to access it in the response. So I would change image_raw in your query to imageRaw but when reading it from response you would still use image_raw.

@ATMartin
Copy link
Author

ATMartin commented May 6, 2020

@ashkan18 I appreciate the suggestion! I believe the issue is that the API we're hitting does not camelCase their fields, so imageRaw is rejected by the server as an invalid field.

I'd love to submit a PR for this! I've got finding a fix in graphql-ruby (or graphql-client) on my TODO list.

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

No branches or pull requests

3 participants