Skip to content

Commit 76f34b9

Browse files
smyrickbrennantaylor
authored andcommitted
update annotation docs (#5)
1 parent c1f3934 commit 76f34b9

File tree

1 file changed

+46
-16
lines changed

1 file changed

+46
-16
lines changed

README.md

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -187,17 +187,17 @@ TBD
187187

188188
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.
189189

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

192192
Simply add `@GraphQLContext` to any argument to a field, and the GraphQL context for the environment will be injected. These arguments will be omitted by the schema generator.
193193

194194
```kotlin
195195
class Query {
196196
fun doSomething(
197-
@GraphQLDescription("A value") value: Int,
197+
value: Int,
198198
@GraphQLContext context: MyGraphQLContextImpl
199-
): Boolean! {
200-
doSomething(context.getResult());
199+
): Boolean {
200+
doSomething(context.getResult())
201201
return true
202202
}
203203
}
@@ -217,11 +217,11 @@ type TopLevelQuery {
217217

218218
Note that the `@GraphQLContext` annotated argument is not reflected in the GraphQL schema.
219219

220-
### @GraphQLIgnore
220+
### `@GraphQLIgnore`
221221

222222
There are two ways to ensure the GraphQL schema generation omits fields when using Kotlin reflection:
223223

224-
The first is by marking the field as `private` scope. The second method is by annotating the field with `@GraphQLIgnore`:
224+
The first is by marking the field as `private` scope. The second method is by annotating the field with `@GraphQLIgnore`.
225225

226226
```kotlin
227227
class Query {
@@ -230,7 +230,7 @@ class Query {
230230

231231
fun doSomething(
232232
value: Int
233-
): Boolean! {
233+
): Boolean {
234234
return true
235235
}
236236
}
@@ -257,16 +257,16 @@ Since Javadocs are not available at runtime for introspection, `graphql-kotlin`
257257
```kotlin
258258
@GraphQLDescription("A useful widget")
259259
data class Widget(
260-
@property:GraphQLDescription("The widget's value")
261-
val value: Boolean?
260+
@property:GraphQLDescription("The widget's value that can be null")
261+
val value: Int?
262262
)
263263

264264
class Query {
265265
@GraphQLDescription("Does something very special")
266266
fun doSomething(
267-
@GraphQLDescription("The special ingredient") value: Int
268-
): Widget! {
269-
return Widget(value !== 1)
267+
@GraphQLDescription("The special ingredient") value: Int?
268+
): Widget {
269+
return Widget(value)
270270
}
271271
}
272272
```
@@ -280,21 +280,51 @@ schema {
280280

281281
# A useful widget
282282
type Widget {
283-
# The widget's value
284-
value: Boolean
283+
# The widget's value that can be null
284+
value: Int
285285
}
286286

287287
type TopLevelQuery {
288288
# Does something very useful
289289
doSomething(
290290
# The special ingredient
291-
value: Int!
292-
): Boolean!
291+
value: Int
292+
): Widget!
293293
}
294294
```
295295

296296
Note that the data class property is annotated as `@property:GraphQLDescription`. This is due to the way kotlin [maps back to the java elements](https://kotlinlang.org/docs/reference/annotations.html#annotation-use-site-targets). If you do not add the `property` prefix the annotation is actually on the contructor argument and will not be picked up by the generator.
297297

298+
299+
### `@Deprecated`
300+
301+
GraphQL schemas can have fields marked as deprecated. Instead of creating a custom annotation, `graphql-kotlin` just looks for the `kotlin.Deprecated` annotation and will use the message for the deprecated reason.
302+
303+
```
304+
class Query {
305+
@Deprecated("Do not use this anymore")
306+
val restApi = "example.com/api"
307+
308+
val graphQLApi = "example.com/graphql"
309+
}
310+
```
311+
312+
The above query would produce the following GraphQL schema:
313+
314+
```graphql
315+
schema {
316+
query: TopLevelQuery
317+
}
318+
319+
type TopLevelQuery {
320+
321+
# DEPRECATED: Do not use this anymore
322+
restApi: String!
323+
324+
graphQLApi: String!
325+
}
326+
```
327+
298328
## Configuration
299329

300330
### Documentation Enforcement

0 commit comments

Comments
 (0)