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

Unsure how to troubleshoot "Missing __typename in selection for the <something> interface" error #218

Open
colindean opened this issue Jan 19, 2019 · 4 comments

Comments

@colindean
Copy link

I'm trying out this library and GraphQL for the first time. My usage of graphql-rust is here and the schema is here.

$ cargo test
   Compiling ledger-getquote-blocktap v0.1.0 (/Users/colin/Source/Altangent/ledger-getquote-blocktap)
error: proc-macro derive panicked
 --> src/single_currency.rs:1:10
  |
1 | #[derive(GraphQLQuery)]
  |          ^^^^^^^^^^^^
  |
  = help: message: called `Result::unwrap()` on an `Err` value: ErrorMessage { msg: "Missing __typename in selection for the SingleCurrencyMarkets interface (type: Market)" }

error: aborting due to previous error

or using the CLI tool

RUST_BACKTRACE=1 graphql-client generate schema/single.graphql schema/blocktap.json lol what
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ErrorMessage { msg: "Missing __typename in selection for the SingleCurrencyMarkets interface (type: Market)" }

I don't really understand what's missing or how to figure it out. If it's something missing from the JSON schema, some kind of path to the expected but missing property would really expedite this.

@tomhoule
Copy link
Member

Thanks for using the library and your report, it's an ergonomics problem indeed.

For code generation to work, you need to query for the __typename field (which is guaranteed to be there on all spec-compliant graphql servers, most frameworks implement it automatically) when you select fields on unions or interfaces.

In your case Market is an interface, so this would be solved by adding __typename right before (or after) ticker here.

I will keep this issue open because we should improve the error message, and suggest where to add __typename in the query.

colindean added a commit to colindean/ledger-getquote-blocktap that referenced this issue Jan 19, 2019
@colindean
Copy link
Author

Looks like that was exactly what I needed: colindean/ledger-getquote-blocktap@5bb8eee

Thank you!

@samuela
Copy link

samuela commented Feb 22, 2020

FWIW I came across the same issue. Changing

query RepoUrl($id: ID!) {
  node(id: $id) {
    ... on Repository {
      url
    }
  }
}

to

query RepoUrl($id: ID!) {
  node(id: $id) {
    __typename
    ... on Repository {
      url
    }
  }
}

did the trick. Perhaps a more detailed error message would help out here.

@skeet70
Copy link

skeet70 commented Jan 29, 2025

I'm pretty inexperienced with GraphQL, but it is frustrating having a working query like

query GetIssueOrPr($repo:String!, $owner:String!, $number:Int!) {
  repository(name:$repo, owner:$owner) {
      issueOrPullRequest(number: $number) {
        ... on Issue {
          title
          url
          id
          number
          body
          repository { id name archivedAt owner{ login }}
          projectsV2(first:100) { nodes { id }
          }
        }
        ... on PullRequest {
          title
          url
          id
          number
          body        
          repository { id name archivedAt owner{ login }}
          projectsV2(first:100) { nodes { id }
          }
        }
      }
  }
}

and the error message just saying that __typename is missing generically. I figured it'd be needed to remove the ambiguity of issue/pull request, but nowhere I've put it so far has taken away the error. Improving the error message to state where it's needed would be great.

@tomhoule tomhoule added enhancement New feature or request good first issue Good for newcomers and removed enhancement New feature or request good first issue Good for newcomers labels Jan 31, 2025
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

4 participants