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

Unable to retrieve federated types with apollo federation v1 #1933

Closed
Jasper-ui opened this issue Feb 29, 2024 · 1 comment
Closed

Unable to retrieve federated types with apollo federation v1 #1933

Jasper-ui opened this issue Feb 29, 2024 · 1 comment

Comments

@Jasper-ui
Copy link

Jasper-ui commented Feb 29, 2024

Hi guys, I am unable to retrieve federated types with apollo federation v1. I am gettign this error with the below classes

end_time {
  seconds: 1709241684
  nanos: 935868841
}
start_time {
  seconds: 1709241684
  nanos: 902215362
}
duration_ns: 33656653
root {
  child {
    response_name: "_entities"
    type: "[_Entity]!"
    start_time: 19058924
    end_time: 32150362
    error {
      message: "Unable to resolve federated type, representation={__typename=Property, primaryKey=8db0b295-e4c5-48c8-8dc6-84d79853f7f0}"
      location {
        line: 4294967295
        column: 4294967295
      }
    }
    parent_type: "Query"
  }
}

Resolver

class PropertyResolver(
    private val control: IApartmentGraphqlControl
) : FederatedTypeSuspendResolver<PropertyResolver.Property> {
    override val typeName = "Property"
    override suspend fun resolve(
        environment: DataFetchingEnvironment,
        representation: Map<String, Any>
    ): Property? =
        representation["primaryKey"]?.toString()?.let { id -> Property(id, control) }

    @KeyDirective(fields = FieldSet("primaryKey"))
    @ExtendsDirective
    data class Property(
        @ExternalDirective val primaryKey: String,
        private val control: IApartmentGraphqlControl
    ) {
        fun apartments(): List<GraphqlApartmentOutput> = control.findAllApartmentsForProperty(UUID.fromString(primaryKey))

    }

}
graphql:
  schema:
    registry:
      enabled: ${GRAPHQL_SCHEMA_REGISTRY_ENABLED}
      url: ${GRAPHQL_SCHEMA_REGISTRY_URL}
      token: ${GRAPHQL_SCHEMA_REGISTRY_API_TOKEN}
      servlet: "/graphql"
      service:
        port: ${server.port}
        serverName: localhost
        name: "{microservice.name}"
        version: "1.0.0"
  federation:
    optInV2: false
    enabled: true
    tracing:
      enabled: true
      debug: true
  maxPageSize: 32
  packages:
    - "com.example.apartment"
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
	id("org.springframework.boot") version "3.1.4"
	id("io.spring.dependency-management") version "1.1.3"
	id("com.expediagroup.graphql") version "7.0.2"
	kotlin("jvm") version "1.8.22"
	kotlin("plugin.spring") version "1.8.22"
}

group = "com.example"
version = "0.0.1-SNAPSHOT"

java {
	sourceCompatibility = JavaVersion.VERSION_19
}

repositories {
	mavenCentral()
	maven("https://jitpack.io")
	maven {
		url = uri("https://plugins.gradle.org/m2/")
	}
}

dependencies {
	implementation("org.springframework.boot:spring-boot-starter")
	implementation("org.springframework.boot:spring-boot-starter-actuator")
	implementation("org.jetbrains.kotlin:kotlin-reflect")
	implementation("software.amazon.awssdk:dynamodb:2.20.153")
	implementation("software.amazon.awssdk:auth:2.20.153")
	implementation ("com.github.oharaandrew314:dynamodb-kotlin-module:0.3.0")
	implementation ("io.github.oshai:kotlin-logging-jvm:5.1.0")
	implementation("com.expediagroup:graphql-kotlin-schema-generator:7.0.2")
	implementation("com.expediagroup:graphql-kotlin-federation:7.0.2")
	implementation("com.expediagroup:graphql-kotlin-federated-hooks-provider:7.0.2")
	implementation("com.expediagroup:graphql-kotlin-spring-server:7.0.2")
	implementation("javax.validation:validation-api:2.0.0.Final")
	implementation("org.json:json:20230618")
	graphqlSDL("com.expediagroup", "graphql-kotlin-federated-hooks-provider")
	testImplementation("com.graphql-java-kickstart:graphql-spring-boot-starter-test:15.0.0")
	testImplementation("org.springframework.boot:spring-boot-starter-test")
	testImplementation ("io.kotest:kotest-runner-junit5:5.7.2")
	testImplementation ("io.kotest:kotest-assertions-core:5.7.2")
	testImplementation("org.http4k:http4k-connect-amazon-dynamodb-fake:5.2.0.0")
	testImplementation ("org.junit.jupiter:junit-jupiter-api:5.8.1")
	testRuntimeOnly ("org.junit.jupiter:junit-jupiter-engine:5.8.1")
}

tasks.named("build") {
	dependsOn("bootJar")
	dependsOn("graphqlGenerateSDL")
}

apply(plugin = "com.expediagroup.graphql")


tasks.withType<KotlinCompile> {
	kotlinOptions {
		freeCompilerArgs += "-Xjsr305=strict"
		jvmTarget = "19"
	}
}

tasks.withType<Test> {
	useJUnitPlatform()
}

property class in property MS

@GraphQLName("Property")
@KeyDirective(fields = FieldSet("primaryKey"))
data class GraphqlPropertyOutput(
        val primaryKey: String,
        val name: String,
        val landlordName: String,
        val createdAt: String,
        val updatedAt: String
)
@Jasper-ui
Copy link
Author

Forgot to add @component to the resolver 🤦

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

No branches or pull requests

1 participant