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

generateApolloSources fails with 4.0.1 and federation sub-graph graphqls #6221

Open
xcq1 opened this issue Oct 25, 2024 · 1 comment
Open

Comments

@xcq1
Copy link

xcq1 commented Oct 25, 2024

Version

4.0.1

Summary

I'm using Apollo client to run tests against one of my federation sub-graph servers. For this the server's .graphqls looks like this:

extend schema
@link(url: "https://specs.apollo.dev/federation/v2.4",
    import: ["@key", "@extends", "@external"])

type Query {
...
}

type Mutation {
...
}

This worked fine with 4.0.0, but it suddenly throws an error in 4.0.1. According to all the docs I can find, this is the way you're supposed to include federation directives. The server works perfectly fine with the Apollo Gateway, so I don't think there is an error in the rest of the schema. Using the SDL also seems to be the preferred schema definition.

Steps to reproduce the behavior

Bump dependency version from 4.0.0 to 4.0.1

Logs

Caused by: com.apollographql.apollo.ast.SourceAwareException: e: /home/runner/_work/my-service/service/server/src/main/resources/graphql/schema.graphqls: (2, 1): Apollo: unknown foreign schema 'federation/v2.4'
----------------------------------------------------
[1]:extend schema
[2]:@link(url: "https://specs.apollo.dev/federation/v2.4",
[3]:    import: ["@key", "@extends", "@external"])
----------------------------------------------------
	at com.apollographql.apollo.ast.IssueKt.checkEmpty(Issue.kt:162)
	at com.apollographql.apollo.compiler.ApolloCompiler.buildCodegenSchema(ApolloCompiler.kt:133)
	at com.apollographql.apollo.gradle.internal.GenerateSources.execute(SourceFile:19)
	at org.gradle.workers.internal.DefaultWorkerServer.execute(DefaultWorkerServer.java:63)
	at org.gradle.workers.internal.AbstractClassLoaderWorker$1.create(AbstractClassLoaderWorker.java:54)
	at org.gradle.workers.internal.AbstractClassLoaderWorker$1.create(AbstractClassLoaderWorker.java:48)
	at org.gradle.internal.classloader.ClassLoaderUtils.executeInClassloader(ClassLoaderUtils.java:100)
	at org.gradle.workers.internal.AbstractClassLoaderWorker.executeInClassLoader(AbstractClassLoaderWorker.java:48)
	at org.gradle.workers.internal.IsolatedClassloaderWorker.run(IsolatedClassloaderWorker.java:49)
	at org.gradle.workers.internal.IsolatedClassloaderWorker.run(IsolatedClassloaderWorker.java:30)
	at org.gradle.workers.internal.IsolatedClassloaderWorkerFactory$1.lambda$execute$0(IsolatedClassloaderWorkerFactory.java:57)
	at org.gradle.workers.internal.AbstractWorker$1.call(AbstractWorker.java:44)
	at org.gradle.workers.internal.AbstractWorker$1.call(AbstractWorker.java:41)
	at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:209)
	at org.gradle.internal.operations.DefaultBuildOperationRunner$CallableBuildOperationWorker.execute(DefaultBuildOperationRunner.java:204)
	at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
	at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
	at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:166)
	at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
	at org.gradle.internal.operations.DefaultBuildOperationRunner.call(DefaultBuildOperationRunner.java:53)
	at org.gradle.workers.internal.AbstractWorker.executeWrappedInBuildOperation(AbstractWorker.java:41)
	at org.gradle.workers.internal.IsolatedClassloaderWorkerFactory$1.execute(IsolatedClassloaderWorkerFactory.java:49)
	at org.gradle.workers.internal.DefaultWorkerExecutor.lambda$submitWork$0(DefaultWorkerExecutor.java:174)
	at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.runExecution(DefaultConditionalExecutionQueue.java:195)
	at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.access$700(DefaultConditionalExecutionQueue.java:128)
	at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner$1.run(DefaultConditionalExecutionQueue.java:170)
	at org.gradle.internal.Factories$1.create(Factories.java:31)
	at org.gradle.internal.work.DefaultWorkerLeaseService.withLocks(DefaultWorkerLeaseService.java:267)
	at org.gradle.internal.work.DefaultWorkerLeaseService.runAsWorkerThread(DefaultWorkerLeaseService.java:131)
	at org.gradle.internal.work.DefaultWorkerLeaseService.runAsWorkerThread(DefaultWorkerLeaseService.java:136)
	at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.runBatch(DefaultConditionalExecutionQueue.java:165)
	at org.gradle.internal.work.DefaultConditionalExecutionQueue$ExecutionRunner.run(DefaultConditionalExecutionQueue.java:134)
	... 2 more

@martinbonnin
Copy link
Contributor

martinbonnin commented Oct 25, 2024

Thanks for sending this 🙏 . This a side effect of #6164. Apollo Kotlin is now more strict about schema validation and throws on unknown directives.

Since federation is transparent from a client point of view, I didn't add builtin support for the federation directives (unlike the nullability directives for an example).

The immediate fix for this issue is to use the API schema SDL instead of the supergraph schema SDL.

Something else we could consider is to ignore the federation directives altogether but that might become an issue the day we want to use @key to auto-configure the normalized cache for an example (we are very far from that but this has been mentioned before). I'll discuss this with the team.

In the meantime, can you try using the API schema? Is it an option for you?

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