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.

No code generated for interface inline fragments

See original GitHub issue

I can use objects as inline fragments, but for interface fragments no code is generated. Shouldn’t this be possible?

{
... on ClosedEvent {
        # object, works
    }  
... on IssueEvent {
        # interface, no code is generated
    }
}

(Using Swift, but saw similar results with the other targets.)

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
gergely-ujvaricommented, Mar 9, 2017

I have an example for this:

Schema: zoo.graphql

interface Feedable {
    _id: ID!,
    kind: String!
    feedWith: String!
}


interface Reptile {
    scaleSkin: String!
}

type Crocodile implements Feedable, Reptile {
    _id: ID!,
    kind: String!
    feedWith: String!
    scaleSkin: String!

    victims: Int!
}

type Iguana implements Feedable, Reptile {
    _id: ID!,
    kind: String!
    feedWith: String!
    scaleSkin: String!

    age: Int!
}

root.graphql

type Query {
    getZoo: [Feedable!]!
}

schema {
    query: Query
}

And now I setup a very simple query with some fragments: zooQuery.graphql

query getZoo {
    getZoo {
        ...FeedableFragment
    }
}

FeedableFragment.graphql

fragment ReptileFragment on Reptile {
    scaleSkin
}

fragment CrocodileFragment on Crocodile {
    victims
}

fragment IguanaFragment on Iguana {
    age
}

fragment FeedableFragment on Feedable {
    _id
    kind,
    feedWith

    ... on Reptile {
        ... ReptileFragment
    }

    ... on Crocodile {
        ... CrocodileFragment
    }

    ... on Iguana {
        ... IguanaFragment
    }
}

And now I check the generated interfaces and I have this:

export interface FeedableFragment {
  _id: string;
  kind: string;
  feedWith: string;
  _id: string;
  kind: string;
  feedWith: string;
  _id: string;
  kind: string;
  feedWith: string;
}

Notice the property duplication and the fact that all inline fragment information is missing.

1reaction
csillagcommented, Mar 9, 2017

I can confirm that using the TypeScript code generation, the fields coming from inline fragments with type conditions are missing from the interface that is supposed to describe the results of the query.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[typescript-operations] operation type not restricted to inline ...
Describe the bug typescript-operations does not appear to take into account the specific inline fragments used, instead generating a type ...
Read more >
Fragments - Apollo GraphQL Docs
A GraphQL fragment is a piece of logic that can be shared between multiple queries and mutations. Here's the declaration of a NameParts...
Read more >
How resolve the right type in GraphQL when using interface ...
2) Yes, after struggling with the above interface + inline fragment solution, I tried to make a single type Entity. The query will...
Read more >
Queries and Mutations - GraphQL
That's why GraphQL includes reusable units called fragments. Fragments let you construct sets of fields, and then include them in queries where you...
Read more >
GraphQL Codegen deep-dive - Christian Budde Christensen
If the field type is a concrete type, we'll inline the fragment. In this case, since the intersection is not empty, we know...
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