question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ability to query interfaces that a union implements

See original GitHub issue

We’re using genql’s typings on an upcoming app and its been working really well! It fits right in, and typed queries and mutations are awesome!

There’s one area where type support is limited though, and that has to do with interfaces and unions. When querying against a resource that returns a union, you should also be able to query interfaces that the union’s types implement. Currently, it is only possible to query individual types within the union.

Perhaps an example will make this clearer.

So assume this (part of) GraphQL schema

interface ClientError {
  message: String!
}

type ClientErrorNameAlreadyTaken implements ClientError {
  message: String!
}

type ClientErrorNameInvalid implements ClientError {
  message: String!
}

union GenericError =
    ClientErrorNameAlreadyTaken
  | ClientErrorNameInvalid

type Query {
  error: GenericError
}

Here, this query is currently possible:

query q {
  error {
    ... on ClientErrorNameAlreadyTaken { message }
    ... on ClientErrorNameInvalid { message }
  }
}

as

client.query({
  error: {
    on_ClientErrorNameAlreadyTaken: { message: true }
    on_ClientErrorNameInvalid: { message: true }
  }
})

However, the following is also a valid query in GraphQL that genql disallows:

query q {
  error {
    ... on ClientError { message }
  }
}

It’d be awesome if genql could let me query it this way:

client.query({
  error: {
    on_ClientError: { message: true }
  }
})

If I’m being unclear, please let me know!

I’m more than happy to send a PR your way to support this if you like 😃

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
remorsescommented, Feb 8, 2021

Released in 2.4.0

2reactions
remorsescommented, Feb 5, 2021

I will work on this, I already know what to change, i also need to clean up tests because now it’s a mess

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unions and interfaces - Apollo GraphQL Docs
Unions and interfaces are abstract GraphQL types that enable a schema field to return ... The SearchResult union enables Query.search to return a...
Read more >
[RFC] Union types can implement interfaces #518 - GitHub
A union should be considered an implementation of an interface if and only if each member type in the union implements said interface....
Read more >
GraphQL Tour: Interfaces and Unions - Medium
Let's take a closer look at them and how they are used in GraphQL-JS. Problem They Solve. Imagine we're implementing some kind of...
Read more >
GraphQL: Union vs. Interface - Artsy Engineering
Unions are useful when we are trying to group different types together in one field. Now let's think of the case where we...
Read more >
GraphQL Interfaces vs Unions - Thread Engineering
Feed items must be able to have radically different formats, without losing type ... With an interface: query {. ideasFeed {. ideas {....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found