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

"Type ... doesn't have any fields" error on GitHub GraphQL schema. #34

Closed
Zimmi48 opened this issue Nov 3, 2019 · 3 comments
Closed

Comments

@Zimmi48
Copy link

Zimmi48 commented Nov 3, 2019

I am using GitHub's GraphQL API. The following query worked fine with ppx_graphql (the __typename were required though) but it does not work with graphql_ppx_re:

  query issueMilestone($owner: String!, $repo: String!, $number: Int!) {
    repository(owner:$owner, name:$repo) {
      issue(number:$number) {
        id
        milestone { id }
        timelineItems(itemTypes:[CLOSED_EVENT],last:1) {
          totalCount
          nodes {
            __typename
            ... on ClosedEvent {
              closer {
                __typename
                ... on PullRequest {
                  id
                  milestone { id }
                }
                ... on Commit {
                  associatedPullRequests(first: 2) {
                    nodes {
                      id
                      milestone { id }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }

The error is:

Fatal error: exception Graphql_ppx_base__Schema.Invalid_type("Type IssueTimelineItems doesn't have any fields")

Given that it is GitHub's GraphQL schema, I am pretty confident that this is a valid schema.

Since this error looks specific to the handling of union types, I think it is the same as mhallin/graphql_ppx#74.

Is it a bug or a known limitation? Is there a known workaround? Thanks!

@baransu
Copy link
Collaborator

baransu commented Nov 4, 2019

When working with union types you only can query on cases and not on whole field. To adjust your example to graphql_ppx_re you only have to remove __typename from the union field. It's added behind scenes as it allows us to parse the result as one of the provided union cases and wrap it into a poly-variant.

Here is an example of a correct query:

module WorkingQuery = [%graphql
  {|
  query issueMilestone($owner: String!, $repo: String!, $number: Int!) {
    repository(owner:$owner, name:$repo) {
      issue(number:$number) {
        id
        milestone { id }
        timelineItems(itemTypes:[CLOSED_EVENT],last:1) {
          totalCount
          nodes {
            ... on ClosedEvent {
              closer {
                ... on PullRequest {
                  id
                  milestone { id }
                }
                ... on Commit {
                  associatedPullRequests(first: 2) {
                    nodes {
                      id
                      milestone { id }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
|}
];

If it doesn't solve your issue please reopen 🙂

@baransu baransu closed this as completed Nov 4, 2019
@baransu
Copy link
Collaborator

baransu commented Nov 4, 2019

@Zimmi48 Added it to the troubleshooting section in README: https://github.com/baransu/graphql_ppx_re#type--doesnt-have-any-fields

@Zimmi48
Copy link
Author

Zimmi48 commented Nov 6, 2019

Thank you so much for the quick answer! If this hadn't been a migration from ppx_graphql, I would never have manually included this __typename field, and I wouldn't have had any trouble 😆

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

No branches or pull requests

2 participants