-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update graphql-kotlin example to fed 2.3 schema (#370)
- Loading branch information
1 parent
da09ba3
commit 549517d
Showing
7 changed files
with
97 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
implementations/graphql-kotlin/src/main/kotlin/com/example/demo/CustomSchema.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.example.demo | ||
|
||
import com.expediagroup.graphql.generator.annotations.GraphQLDirective | ||
import com.expediagroup.graphql.generator.federation.directives.ComposeDirective | ||
import com.expediagroup.graphql.generator.federation.directives.LinkDirective | ||
import com.expediagroup.graphql.server.Schema | ||
import graphql.introspection.Introspection | ||
import org.springframework.stereotype.Component | ||
|
||
@LinkDirective(url = "https://myspecs.dev/myCustomDirective/v1.0", import = ["@custom"]) | ||
@ComposeDirective("@custom") | ||
@Component | ||
class CustomSchema : Schema | ||
|
||
@GraphQLDirective(name = "custom", locations = [Introspection.DirectiveLocation.OBJECT]) | ||
annotation class CustomDirective |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
implementations/graphql-kotlin/src/main/kotlin/com/example/demo/model/Inventory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.example.demo.model | ||
|
||
import com.expediagroup.graphql.generator.federation.directives.ExtendsDirective | ||
import com.expediagroup.graphql.generator.federation.directives.ExternalDirective | ||
import com.expediagroup.graphql.generator.federation.directives.FieldSet | ||
import com.expediagroup.graphql.generator.federation.directives.InterfaceObjectDirective | ||
import com.expediagroup.graphql.generator.federation.directives.KeyDirective | ||
import com.expediagroup.graphql.generator.federation.execution.FederatedTypeResolver | ||
import com.expediagroup.graphql.generator.scalars.ID | ||
import graphql.schema.DataFetchingEnvironment | ||
import org.springframework.stereotype.Component | ||
|
||
/* | ||
NOTE: @extends and @external are only required in graphql-kotlin v6, this was fixed in v7 | ||
type Inventory @extends @interfaceObject @key(fields: "id") { | ||
id: ID! @external | ||
deprecatedProducts: [DeprecatedProduct!]! | ||
} | ||
*/ | ||
@ExtendsDirective | ||
@KeyDirective(fields = FieldSet("id")) | ||
@InterfaceObjectDirective | ||
data class Inventory(@ExternalDirective val id: ID) { | ||
fun deprecatedProducts(): List<DeprecatedProduct> = listOf(DEPRECATED_PRODUCT) | ||
} | ||
|
||
@Component | ||
class InventoryResolver : FederatedTypeResolver<Inventory> { | ||
override val typeName: String = "Inventory" | ||
|
||
override suspend fun resolve( | ||
environment: DataFetchingEnvironment, | ||
representations: List<Map<String, Any>> | ||
): List<Inventory?> { | ||
return representations.map { | ||
if (it["id"] == "apollo-oss") { | ||
Inventory(ID("apollo-oss")) | ||
} else { | ||
null | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters