Skip to content

Commit 3d59a12

Browse files
smyrickShane Myrick
andauthored
Add note on interface as arguments (#1017)
* Add note on interface as arguments * Add note to unions docs Co-authored-by: Shane Myrick <[email protected]>
1 parent 8edf458 commit 3d59a12

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

docs/schema-generator/writing-schemas/interfaces.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ id: interfaces
33
title: Interfaces
44
---
55

6-
Functions returning interfaces will automatically expose all the types implementing this interface that are available on
7-
the classpath. Due to the GraphQL distinction between interface and a union type, interfaces need to specify at least
6+
Any Kotlin interfaces will be mapped to a GraphQL interface. Due to the GraphQL distinction between interface and a [union type](./unions.md), Kotlin interfaces need to specify at least
87
one common field (property or a function).
98

10-
Abstract and sealed classes will also be converted to a GraphQL Interface.
9+
Abstract and sealed classes will also be converted to a GraphQL interface.
10+
11+
> NOTE: [The GraphQL spec](http://spec.graphql.org/June2018/#sec-Interfaces) does not allow interfaces to be used as input.
12+
> This means that while it is valid Kotlin code to have an inteface as an argument, upon schema generation, an exception will be thrown.
1113
1214
```kotlin
1315
interface Animal {
@@ -78,7 +80,7 @@ type TopLevelQuery {
7880
```
7981

8082
## Abstract and Sealed Classes
81-
[Abstract](https://kotlinlang.org/docs/reference/classes.html#abstract-classes) and [sealed](https://kotlinlang.org/docs/reference/sealed-classes.html) classes can also be used for interface types.
83+
[Abstract](https://kotlinlang.org/docs/reference/classes.html#abstract-classes) and [sealed](https://kotlinlang.org/docs/reference/sealed-classes.html) classes can also be used for GraphQL interface types.
8284

8385
```kotlin
8486
abstract class Shape(val area: Double)

docs/schema-generator/writing-schemas/unions.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ title: Unions
44
---
55

66
Marker interfaces (i.e. interfaces without any common fields or methods) are exposed as GraphQL union types. All the
7-
types that are implementing this marker interface and are available on the classpath will be automatically exposed as
8-
objects in the target schema.
7+
types that implement the marker interface, and are available on the classpath, will be automatically exposed as
8+
objects in the schema.
9+
10+
> NOTE: [The GraphQL spec](http://spec.graphql.org/June2018/#sec-Unions) does not allow unions to be used as input.
11+
> This means that while it is valid Kotlin code to have a marker inteface as an argument, upon schema generation, an exception will be thrown.
912
1013
```kotlin
1114
interface BodyPart

0 commit comments

Comments
 (0)