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

Auto-detection of used types not working #6395

Open
jvanderwee opened this issue Feb 25, 2025 · 11 comments
Open

Auto-detection of used types not working #6395

jvanderwee opened this issue Feb 25, 2025 · 11 comments

Comments

@jvanderwee
Copy link
Contributor

jvanderwee commented Feb 25, 2025

Version

4.1.1

Summary

We've added isADependencyOf as documented here however we're still seeing all schema types are being generated.

Steps to reproduce the behavior

Follow setup and auto-detection of used types as per docs

@martinbonnin
Copy link
Contributor

Can you try setting alwaysGenerateTypesMatching.set(emptyList()) in your schema build.gradle[.kts] file?

@jvanderwee
Copy link
Contributor Author

Hey @martinbonnin. All types are still generated with alwaysGenerateTypesMatching.set(emptyList()) set

@martinbonnin
Copy link
Contributor

Oh well, that is surprising. You don't happen to have a reproducer around, do you?
If not, I might have something around, let me see if I can find it...

@martinbonnin
Copy link
Contributor

So I did try here and looks like it's working as expected:

$ ./gradlew generateApolloSources
$ ls schema/build/generated/source/apollo/service/com/example/type/User.kt
ls: schema/build/generated/source/apollo/service/com/example/type/User.kt: No such file or director

@jvanderwee
Copy link
Contributor Author

thanks for checking! and you're absolutely right, not all types are generated, however it does seem that unused types which implement our Relay-style Node are 🤔

@martinbonnin
Copy link
Contributor

Are you using a custom directive maybe? Like @typePolicy ?

@jvanderwee
Copy link
Contributor Author

we are yes, @typePolicy and @fieldPolicy

@martinbonnin
Copy link
Contributor

That might be it, although it's hard to tell without more details. Can you share more about your project?

@martinbonnin
Copy link
Contributor

Another option might be data builders. Those also generate extra code.

@jvanderwee
Copy link
Contributor Author

// schema module
apollo {
    service("service") {
        packageName.set("com.foo")

        generateApolloMetadata.set(true)

        isADependencyOf(projects.feature)

        schemaFiles.from(schemaPath, "$schemaDir/extra.graphqls")
        mapScalar(
            graphQLName = "Decimal",
            targetName = "com.apollographql.adapter.core.BigDecimal",
            expression = "com.apollographql.adapter.core.BigDecimalAdapter",
        )
        mapScalarToUpload("FileUpload")
        introspection {
           ...
        }
        generateDataBuilders.set(true)
    }
}

// feature module
apollo {
    service("service") {
        packageName.set("com.foo")

        dependsOn(projects.schema)

        generateAsInternal.set(true)
        warnOnDeprecatedUsages.set(true)
        failOnWarnings.set(true)
        addTypename.set("always")
    }
}

we are using a type which implements Node - could it be that if one implementation of an interface is used then all implementations of the interface are generated?

@martinbonnin
Copy link
Contributor

could it be that if one implementation of an interface is used then all implementations of the interface are generated?

With data builders, it's the case indeed. That's because we can't build interfaces, we have to build concrete object types. So its building the data builders code for all the implementations. If everything extends from Node then everything is generated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants