From 5c5b34f3ff41f0b2e8aabef7e37c6a9c28ebaa08 Mon Sep 17 00:00:00 2001 From: mitjade Date: Mon, 8 Apr 2024 14:01:53 +0200 Subject: [PATCH 1/5] Fix boken link, add selectionSet info for DataFetchingEnvironment --- .../execution/data-fetching-environment.md | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/website/docs/schema-generator/execution/data-fetching-environment.md b/website/docs/schema-generator/execution/data-fetching-environment.md index 6e2845ef29..df1aef37d9 100644 --- a/website/docs/schema-generator/execution/data-fetching-environment.md +++ b/website/docs/schema-generator/execution/data-fetching-environment.md @@ -44,4 +44,30 @@ Then the following query would return `"The parentField was foo and the childFie ``` You can also use this to retrieve arguments and query information from higher up the query chain. You can see a working -example in the `graphql-kotlin-spring-example` module [[link](https://github.com/ExpediaGroup/graphql-kotlin/blob/master/examples/spring/src/main/kotlin/com/expediagroup/graphql/examples/query/EnvironmentQuery.kt)]. +example in the `graphql-kotlin-spring-example` module [[link]([https://github.com/ExpediaGroup/graphql-kotlin/blob/master/examples/spring/src/main/kotlin/com/expediagroup/graphql/examples/query/EnvironmentQuery.kt](https://github.com/ExpediaGroup/graphql-kotlin/blob/master/examples/server/spring-server/src/main/kotlin/com/expediagroup/graphql/examples/server/spring/query/EnvironmentQuery.kt))]. + +```kotlin +class ProductQueryService : Query { + + fun products(environment: DataFetchingEnvironment): Product { + environment.selectionSet.fields.forEach { println("field: ${it.name}") } + + return Product(1, "Product title", 100) + } +} + +``` + +```graphql +{ + product { + id + title + price + } +} +``` + +You can also use `selectionSet` to retrieve sub field information a client wants. It can be useful to know +what selection has been asked for so the data fetcher can optimise the data access queries. +For example an SQL backed system may be able to use the field selection to only retrieve the columns that have been asked for. From cfd4865a920c24203402d722b35dddf9e074ef84 Mon Sep 17 00:00:00 2001 From: mitjade Date: Mon, 8 Apr 2024 14:04:00 +0200 Subject: [PATCH 2/5] fix link --- .../schema-generator/execution/data-fetching-environment.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/schema-generator/execution/data-fetching-environment.md b/website/docs/schema-generator/execution/data-fetching-environment.md index df1aef37d9..04fadc6e53 100644 --- a/website/docs/schema-generator/execution/data-fetching-environment.md +++ b/website/docs/schema-generator/execution/data-fetching-environment.md @@ -44,7 +44,7 @@ Then the following query would return `"The parentField was foo and the childFie ``` You can also use this to retrieve arguments and query information from higher up the query chain. You can see a working -example in the `graphql-kotlin-spring-example` module [[link]([https://github.com/ExpediaGroup/graphql-kotlin/blob/master/examples/spring/src/main/kotlin/com/expediagroup/graphql/examples/query/EnvironmentQuery.kt](https://github.com/ExpediaGroup/graphql-kotlin/blob/master/examples/server/spring-server/src/main/kotlin/com/expediagroup/graphql/examples/server/spring/query/EnvironmentQuery.kt))]. +example in the `graphql-kotlin-spring-example` module [[link]([https://github.com/ExpediaGroup/graphql-kotlin/blob/master/examples/spring/src/main/kotlin/com/expediagroup/graphql/examples/query/EnvironmentQuery.kt])]. ```kotlin class ProductQueryService : Query { From 647fcc81b0ba923de405a5b36e0d17207f21f383 Mon Sep 17 00:00:00 2001 From: mitjade Date: Mon, 8 Apr 2024 14:07:54 +0200 Subject: [PATCH 3/5] fix links --- .../schema-generator/execution/data-fetching-environment.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/website/docs/schema-generator/execution/data-fetching-environment.md b/website/docs/schema-generator/execution/data-fetching-environment.md index 04fadc6e53..0e35c1cccd 100644 --- a/website/docs/schema-generator/execution/data-fetching-environment.md +++ b/website/docs/schema-generator/execution/data-fetching-environment.md @@ -3,7 +3,7 @@ id: data-fetching-environment title: Data Fetching Environment --- Each resolver has access to a `DataFetchingEnvironment` that provides additional information about the currently executed query including information about what data is requested -as well as details about current execution state. For more details on the `DataFetchingEnvironment` please refer to [graphql-java documentation](https://www.graphql-java.com/documentation/v14/data-fetching/) +as well as details about current execution state. For more details on the `DataFetchingEnvironment` please refer to [graphql-java documentation](https://www.graphql-java.com/documentation/data-fetching/) You can access this info by including the `DataFetchingEnvironment` as one of the arguments to a Kotlin function. This argument will be automatically populated and injected during the query execution but will not be included in the schema definition. @@ -44,7 +44,7 @@ Then the following query would return `"The parentField was foo and the childFie ``` You can also use this to retrieve arguments and query information from higher up the query chain. You can see a working -example in the `graphql-kotlin-spring-example` module [[link]([https://github.com/ExpediaGroup/graphql-kotlin/blob/master/examples/spring/src/main/kotlin/com/expediagroup/graphql/examples/query/EnvironmentQuery.kt])]. +example in the `graphql-kotlin-spring-example` module [[link](https://github.com/ExpediaGroup/graphql-kotlin/blob/master/examples/spring/src/main/kotlin/com/expediagroup/graphql/examples/query/EnvironmentQuery.kt)]. ```kotlin class ProductQueryService : Query { From 9b8d450509d2de46f4dec2a04f884794554735b8 Mon Sep 17 00:00:00 2001 From: mitjade Date: Mon, 8 Apr 2024 14:08:52 +0200 Subject: [PATCH 4/5] fix links --- .../schema-generator/execution/data-fetching-environment.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/schema-generator/execution/data-fetching-environment.md b/website/docs/schema-generator/execution/data-fetching-environment.md index 0e35c1cccd..745e250d84 100644 --- a/website/docs/schema-generator/execution/data-fetching-environment.md +++ b/website/docs/schema-generator/execution/data-fetching-environment.md @@ -44,7 +44,7 @@ Then the following query would return `"The parentField was foo and the childFie ``` You can also use this to retrieve arguments and query information from higher up the query chain. You can see a working -example in the `graphql-kotlin-spring-example` module [[link](https://github.com/ExpediaGroup/graphql-kotlin/blob/master/examples/spring/src/main/kotlin/com/expediagroup/graphql/examples/query/EnvironmentQuery.kt)]. +example in the `graphql-kotlin-spring-example` module [[link](https://github.com/ExpediaGroup/graphql-kotlin/blob/master/examples/server/spring-server/src/main/kotlin/com/expediagroup/graphql/examples/server/spring/query/EnvironmentQuery.kt)]. ```kotlin class ProductQueryService : Query { From 5f40b0e90f460f1caad99c43bac601b4c72813fa Mon Sep 17 00:00:00 2001 From: mitjade Date: Fri, 12 Apr 2024 08:46:34 +0200 Subject: [PATCH 5/5] Update website/docs/schema-generator/execution/data-fetching-environment.md Co-authored-by: Samuel Vazquez --- .../schema-generator/execution/data-fetching-environment.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/schema-generator/execution/data-fetching-environment.md b/website/docs/schema-generator/execution/data-fetching-environment.md index 745e250d84..eb8eddba7c 100644 --- a/website/docs/schema-generator/execution/data-fetching-environment.md +++ b/website/docs/schema-generator/execution/data-fetching-environment.md @@ -68,6 +68,6 @@ class ProductQueryService : Query { } ``` -You can also use `selectionSet` to retrieve sub field information a client wants. It can be useful to know +You can also use `selectionSet` to access the selected fields of the current field. It can be useful to know which selections have been requested so the data fetcher can optimize the data access queries. For example, in an SQL-backed system, the data fetcher can access the database and use the field selection criteria to specifically retrieve only the columns that have been requested by the client. what selection has been asked for so the data fetcher can optimise the data access queries. For example an SQL backed system may be able to use the field selection to only retrieve the columns that have been asked for.