Skip to content

Commit b0fa841

Browse files
smyrickbrennantaylor
authored andcommitted
Add nullability documentation (#6)
1 parent 76f34b9 commit b0fa841

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,35 @@ type TopLevelQuery {
165165

166166
#### Nullability
167167

168+
Both GraphQL and Kotin have nullable as a marked typed so we can generated null safe schemas.
169+
170+
```kotlin
171+
class Query {
172+
fun getNullNumber(): Int? {
173+
val num = (0..10).random()
174+
return num < 5 ? num : null
175+
}
176+
177+
fun getNumber(): Int {
178+
return (0..10).random()
179+
}
180+
}
181+
```
182+
183+
The above Kotlin code would produce the following GraphQL schema:
184+
185+
```graphql
186+
schema {
187+
query: TopLevelQuery
188+
}
189+
190+
type TopLevelQuery {
191+
getNullNumber(): Int
192+
193+
getNumber(): Int!
194+
}
195+
```
196+
168197
### Fields
169198

170199
### Arguments
@@ -185,7 +214,7 @@ TBD
185214

186215
### `@GraphQLContext`
187216

188-
All GraphQL servers have a concept of a "context". A GraphQL context contains metadata that is useful to the GraphQL server, but shouldn't necessarily be part of the GraphQL query's API. A prime example of something that is appropriate for the GraphQL context would be trace headers for an OpenTracing system such as Zipkin or Haystack. The GraphQL query itself does not need the information to perform its function, but the server itself needs the information to ensure observability.
217+
All GraphQL servers have a concept of a "context". A GraphQL context contains metadata that is useful to the GraphQL server, but shouldn't necessarily be part of the GraphQL query's API. A prime example of something that is appropriate for the GraphQL context would be trace headers for an OpenTracing system such as [Haystack](https://expediadotcom.github.io/haystack). The GraphQL query itself does not need the information to perform its function, but the server itself needs the information to ensure observability.
189218

190219
The contents of the GraphQL context vary across GraphQL applications. For JVM based applications, `graphql-java` provides a context interface that can be extended.
191220

0 commit comments

Comments
 (0)