Skip to content

Commit e932378

Browse files
authored
[3.x.x/docs] fixing documentation on adding types to generator (#961)
1 parent ea8265f commit e932378

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

docs/schema-generator/customizing-schemas/advanced-features.md

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,24 @@ title: Advanced Features
88
There are a couple ways you can add more types to the schema without having them be directly consumed by a type in your schema.
99
This may be required for [Apollo Federation](federated/apollo-federation), or maybe adding other interface implementations that are not picked up.
1010

11+
### `SchemaGenerator::generateSchema`
12+
13+
When generating a schema you can optionally specify additional types and input types to be included in the schema. This will
14+
allow you to link to those types from your custom `SchemaGeneratorHooks` implementation using GraphQL reference instead of
15+
manually creating the underlying GraphQL type.
16+
17+
```kotlin
18+
val myConfig = SchemaGeneratorConfig(supportedPackages = listOf("com.example"))
19+
val generator = SchemaGenerator(myConfig)
20+
21+
val schema = generator.generateSchema(
22+
queries = myQueries,
23+
additionalTypes = setOf(MyCustomObject::class.createType()),
24+
additionalInputTypes = setOf(MyCustomInputObject::class.createType())
25+
)
26+
```
1127

1228
### `SchemaGenerator::addAdditionalTypesWithAnnotation`
1329

1430
This method is protected so if you override the `SchemaGenerator` used you can call this method to add types that have a specific annotation.
1531
You can see how this is used in `graphql-kotlin-federation` as [an example](https://github.com/ExpediaGroup/graphql-kotlin/blob/master/graphql-kotlin-federation/src/main/kotlin/com/expediagroup/graphql/federation/FederatedSchemaGenerator.kt).
16-
17-
### `SchemaGenerator::generateAdditionalTypes`
18-
19-
This method is called by `SchemaGenerator::get` after all the queries, mutations, and subscriptions have been generated and it is going to add all the types saved in an internal set that were not generated by reflection.
20-
To change the behaviour, you can update the set and then call the super method with the new value.
21-
22-
Example:
23-
24-
```kotlin
25-
class CustomSchemaGenerator(config: SchemaGeneratorConfig) : SchemaGenerator(config) {
26-
27-
override fun generateAdditionalTypes(types: Set<KType>): Set<GraphQLType> {
28-
val newTypes = types.toMutableSet().add(MyNewType()::class.createType())
29-
return super.generateAdditionalTypes(newTypes)
30-
}
31-
}
32-
```

0 commit comments

Comments
 (0)