apollographql / apollo-ios

📱  A strongly-typed, caching GraphQL client for iOS, written in Swift.
https://www.apollographql.com/docs/ios/
MIT License
3.85k stars 707 forks source link

Giant schema codegen when using Relay GraphQL Global Object Identification Specification (Node interface) #2967

Open jimisaacs opened 1 year ago

jimisaacs commented 1 year ago

Summary

Apologies if this was addressed somehow but I can't seem to find an issue. It was most likely something raised off GitHub, not something addressed that I can find.

The issue which continues to plague us is that our supergraph uses the Relay "GraphQL Global Object Identification Specification". Because of this, our schema generated code is becoming less and less manageable by the day. Every new type that adheres to the Node interface, which is basically every entity type in the federation spec, gets generated schema types in the client, regardless of whether they are actually used in an operation/fragment.

Version

1.0.7

Steps to reproduce the behavior

Make a query to a graph that utilizes the Relay GraphQL Global Object Identification Specification, i.e. GetSomeTypeThatImplementsNode.graphql:

query GetSomeTypeThatImplementsNode($id: ID!) {
    node(id: $id) {
        id
        ... on SomeTypeThatImplementsNode {
            someField
        }
    }
}

The expectation is that only the types needed to fulfill this query, i.e. Query and SomeTypeThatImplementsNode, should be generated. Not every type in the graph that implements Node. To make this work you'll need a schema that looks something like this, schema.graphqls:

interface Node {
    id: ID!
}

type Foo implements Node {
    id: ID!
}

type Bar implements Node {
    id: ID!
}

type SomeTypeThatImplementsNode implements Node {
    id: ID!
    someField: String
}

type Query {
    node(id: ID!): Node
}

So as you can see, considering the above query, I would NOT expect there to be anything generated for Foo and Bar, but I would expect types to be generated for SomeTypeThatImplementsNode.

Logs

No response

Anything else?

See the files I've included in the attached ReducedCase.zip archive ReducedCase.zip

calvincestari commented 1 year ago

I'm pretty sure had an issue for this but can't seem to find it yet, I'll keep digging. @AnthonyMDev - does this ring any bells?

AnthonyMDev commented 1 year ago

I don't see an issue for it either, but it is something we are aware of and want to fix. I know you and I have chatted about this specific issue in the past @jimisaacs. While we somehow didn't have a GitHub issue for this yet, it is the focus of this roadmap item.

Thanks for officially making an issue for this one @jimisaacs.

jimisaacs commented 1 year ago

Yeah, I do vaguely remember a discussion 🤔, but nice to see it officially on the milestone! Thank you!

jimisaacs commented 1 year ago

The reduced case zip I just added here also applies to this issue https://github.com/apollographql/apollo-ios/issues/2969#issuecomment-1533375074

jimisaacs commented 9 months ago

Would like to understand the new date for this, as the last time I communicated this to my team, it was July, 1.3.

jimisaacs commented 8 months ago

@AnthonyMDev @calvincestari @BobaFetters any word on this by chance? The more we expand, the more of an issue this is becoming.

AnthonyMDev commented 8 months ago

Yeah, I'm sorry this got pushed back so much. I'm actively working on getting support for disabling fragment field merging finished. I anticipate I'll finally have that done in November. With the holidays in December, my goal is to develop a solution for this issue in January.

tmgsca commented 3 weeks ago

Hi @AnthonyMDev, any news on this item? It's been a while since the last update. We have a huge schema and we need only a tiny fraction of it in our use case. We're getting hit with 1k+ files when performing codegen for just a few queries 😅

AnthonyMDev commented 3 weeks ago

Honestly not sure still. We've been working through our roadmap, and this is still on it, but a lot of features we've approached have been more complicated than anticipated. I will definitely update this issue as soon as we have anything to update you with.

But I totally understand your pain here. We want to improve on this. The current state of this is not what we want to be seeing.