Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use service {} in all messages/docs #4572

Merged
merged 1 commit into from Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 17 additions & 12 deletions design-docs/Scalar adapter configuration.md
Expand Up @@ -83,12 +83,14 @@ requests (in the `executionContext`), and then to the adapters in `HttpNetworkTr
Plugin configuration:

```kotlin
apollo {
mapScalar("MyDate", "com.example.MyDate", "com.example.MyDateAdapter()")
apollo {
service("service") {
mapScalar("MyDate", "com.example.MyDate", "com.example.MyDateAdapter()")

mapScalar("ID", "kotlin.Long", "com.apollographql.apollo3.api.LongAdapter")

mapScalar("MyLong", "kotlin.Long")
mapScalar("ID", "kotlin.Long", "com.apollographql.apollo3.api.LongAdapter")

mapScalar("MyLong", "kotlin.Long")
}
}
```

Expand Down Expand Up @@ -117,16 +119,19 @@ Let's also have convenience shortcuts for the types for which we have built-in a

```kotlin
apollo {
// equivalent to mapScalar("ID", "kotlin.Long", "com.apollographql.apollo3.api.LongAdapter")
mapScalarToKotlinLong("ID")
service("service") {
// equivalent to mapScalar("ID", "kotlin.Long", "com.apollographql.apollo3.api.LongAdapter")
mapScalarToKotlinLong("ID")

// equivalent to mapScalar("ID", "java.lang.Long", "com.apollographql.apollo3.api.LongAdapter")
mapScalarToJavaLong("ID")
// equivalent to mapScalar("ID", "java.lang.Long", "com.apollographql.apollo3.api.LongAdapter")
mapScalarToJavaLong("ID")

// equivalent to mapScalar("Json", "kotlin.Any", "com.apollographql.apollo3.api.AnyAdapter")
mapScalarToKotlinAny("Json")
// equivalent to mapScalar("Json", "kotlin.Any", "com.apollographql.apollo3.api.AnyAdapter")
mapScalarToKotlinAny("Json")

// etc.
// etc.
}
}
```

With this, it is no longer necessary (but still possible) to register the adapters at runtime with `addCustomScalarAdapter`.
Expand Down
4 changes: 3 additions & 1 deletion docs/source/advanced/java.mdx
Expand Up @@ -10,7 +10,9 @@ Apollo Kotlin generates Kotlin code by default, but you can configure it to use

```kotlin title="build.gradle[.kts]"
apollo {
generateKotlinModels.set(false)
service("service") {
generateKotlinModels.set(false)
}
}
```

Expand Down
10 changes: 10 additions & 0 deletions docs/source/advanced/multi-modules.mdx
Expand Up @@ -16,7 +16,9 @@ Configure your schema module to generate Apollo metadata:
```kotlin
// schema/build.gradle.kts
apollo {
service("service") {
generateApolloMetadata.set(true)
}
}
```

Expand Down Expand Up @@ -58,14 +60,18 @@ dependencies {
apolloMetadata(project(":schema"))
}
apollo {
service("service") {
generateApolloMetadata.set(true)
}
}

// schema/build.gradle.kts
// This module is the schema module
// Place the schema in this module
apollo {
service("service") {
generateApolloMetadata.set(true)
}
}
```

Expand Down Expand Up @@ -119,20 +125,24 @@ If that happens, you will need to resolve the type clash manually by forcing gen
```kotlin
// shared/build.gradle.kts
apollo {
service("service") {
// For an example if ReviewInput clashes
alwaysGenerateTypesMatching.set(listOf("ReviewInput"))
// You can also pass Regex patterns
alwaysGenerateTypesMatching.set(listOf(".*Input"))
}
}
```

```groovy
// shared/build.gradle
apollo {
service("service") {
// For an example if ReviewInput clashes
alwaysGenerateTypesMatching.set(["ReviewInput"])
// You can also pass Regex patterns
alwaysGenerateTypesMatching.set([".*Input"])
}
}
```

Expand Down
6 changes: 4 additions & 2 deletions docs/source/advanced/operation-variables.mdx
Expand Up @@ -42,8 +42,10 @@ To disable optional variables globally, update your Gradle config like so:

```kotlin
apollo {
// ...
generateOptionalOperationVariables.set(false)
service("service") {
// ...
generateOptionalOperationVariables.set(false)
}
}
```

Expand Down
38 changes: 22 additions & 16 deletions docs/source/advanced/persisted-queries.mdx
Expand Up @@ -42,9 +42,11 @@ apolloClient.query(myQuery).enableAutoPersistedQueries(false).toFlow()

If your backend uses custom persisted queries, Apollo Kotlin can generate an OperationOutput json from your .graphql queries. They will match what the client is sending exactly so you can persist them on your server.

```
```kotlin
apollo {
generateOperationOutput.set(true)
service("service") {
generateOperationOutput.set(true)
}
}
```

Expand All @@ -58,30 +60,34 @@ Example Md5 hash generator:

```kotlin
apollo {
operationIdGenerator.set(object: com.apollographql.apollo3.compiler.OperationIdGenerator {
override val version = "my-md5-version1"
service("service") {
operationIdGenerator.set(object : com.apollographql.apollo3.compiler.OperationIdGenerator {
override val version = "my-md5-version1"

override fun apply(operationDocument: String, operationName: String): String {
return operationDocument.md5()
}
override fun apply(operationDocument: String, operationName: String): String {
return operationDocument.md5()
}
})
}
}
```

```groovy
import com.apollographql.apollo3.compiler.OperationIdGenerator

apollo {
operationIdGenerator = new OperationIdGenerator() {
String apply(String operationDocument, String operationName) {
return operationDocument.md5()
service("service") {
operationIdGenerator = new OperationIdGenerator() {
String apply(String operationDocument, String operationName) {
return operationDocument.md5()
}

/**
* Use this version override to indicate an update to the implementation.
* This forces gradle to recompile models.
*/
String version = "my-md5-v1"
}

/**
* Use this version override to indicate an update to the implementation.
* This forces gradle to recompile models.
*/
String version = "my-md5-v1"
}
}
```
Expand Down
14 changes: 10 additions & 4 deletions docs/source/advanced/plugin-configuration.mdx
Expand Up @@ -29,7 +29,9 @@ Specify the location of your schema file using the `schemaFile` property:

```kotlin
apollo {
schemaFile.set(file("shared/graphql/schema.graphqls"))
service("service") {
schemaFile.set(file("shared/graphql/schema.graphqls"))
}
}
```

Expand All @@ -43,7 +45,9 @@ If you expand your schema in a separate file, you can instruct Apollo Kotlin to

```kotlin
apollo {
schemaFiles.set(setOf(file("shared/graphql/schema.graphqls"), file("shared/graphql/extra.graphqls")))
service("service") {
schemaFiles.set(setOf(file("shared/graphql/schema.graphqls"), file("shared/graphql/extra.graphqls")))
}
}
```

Expand All @@ -62,8 +66,10 @@ JVM project:

```kotlin
apollo {
outputDirConnection {
connectToKotlinSourceSet("test")
service("service") {
outputDirConnection {
connectToKotlinSourceSet("test")
}
}
}
```
Expand Down
2 changes: 2 additions & 0 deletions docs/source/advanced/response-based-codegen.mdx
Expand Up @@ -18,8 +18,10 @@ To use a particular codegen, configure `codegenModels` in your Gradle scripts:

```kotlin title="build.gradle.kts"
apollo {
service("service") {
// ...
codegenModels.set("responseBased")
}
}
```

Expand Down
12 changes: 8 additions & 4 deletions docs/source/advanced/source-sets.mdx
Expand Up @@ -10,8 +10,10 @@ For an example, you can add them to the "test" source set:

```kotlin
apollo {
outputDirConnection {
connectToKotlinSourceSet("test")
service("service") {
outputDirConnection {
connectToKotlinSourceSet("test")
}
}
}
```
Expand All @@ -20,8 +22,10 @@ On Android, because the generated files are added to the `main` source set, they

```kotlin
apollo {
outputDirConnection {
connectToAndroidSourceSet("demoDebug")
service("service") {
outputDirConnection {
connectToAndroidSourceSet("demoDebug")
}
}
}
```
4 changes: 3 additions & 1 deletion docs/source/advanced/upload.mdx
Expand Up @@ -8,7 +8,9 @@ First, add the following custom scalar mapping to the Apollo Gradle plugin confi

```kotlin title="build.gradle[.kts]"
apollo {
mapScalarToUpload("Upload")
service("service") {
mapScalarToUpload("Upload")
}
}
```

Expand Down
4 changes: 3 additions & 1 deletion docs/source/caching/store.mdx
Expand Up @@ -81,7 +81,9 @@ Apollo Kotlin makes an exception to that rule and allows to read/write individua

```kotlin
apollo {
generateFragmentImplementations.set(true)
service("service") {
generateFragmentImplementations.set(true)
}
}
```

Expand Down
16 changes: 11 additions & 5 deletions docs/source/essentials/custom-scalars.mdx
Expand Up @@ -10,10 +10,12 @@ To interact with custom scalars in your Apollo Kotlin app, you need to define a

```kotlin title="build.gradle[.kts]"
apollo {
mapScalar("GeoPoint", "com.example.GeoPoint")
service("service") {
mapScalar("GeoPoint", "com.example.GeoPoint")

// Shortcuts exist for standard types - equivalent to mapScalar("Long", "kotlin.Long")
mapScalarToKotlinLong("Long")
// Shortcuts exist for standard types - equivalent to mapScalar("Long", "kotlin.Long")
mapScalarToKotlinLong("Long")
}
}
```

Expand Down Expand Up @@ -89,7 +91,9 @@ A third argument can be passed to `mapScalar` to specify the adapter to use:

```kotlin title="build.gradle[.kts]"
apollo {
mapScalar("GeoPoint", "com.example.GeoPoint", "com.example.Adapters.geoPointAdapter")
service("service") {
mapScalar("GeoPoint", "com.example.GeoPoint", "com.example.Adapters.geoPointAdapter")
}
}
```

Expand Down Expand Up @@ -148,6 +152,8 @@ dependencies {
}

apollo {
mapScalar("Date", "java.util.Date", "com.apollographql.apollo3.adapter.DateAdapter")
service("service") {
mapScalar("Date", "java.util.Date", "com.apollographql.apollo3.adapter.DateAdapter")
}
}
```
4 changes: 3 additions & 1 deletion docs/source/index.md
Expand Up @@ -84,7 +84,9 @@ Set the package name to use for the generated models:

```kotlin
apollo {
packageName.set("com.example")
service("service") {
packageName.set("com.example")
}
}
```

Expand Down
32 changes: 20 additions & 12 deletions docs/source/migration/1.3.mdx
Expand Up @@ -78,26 +78,32 @@ sourceSets {
// With:
// highlight-start
apollo {
srcDir("/path/to/your/graphql/queries/dir")
service("service") {
srcDir("/path/to/your/graphql/queries/dir")
}
}
// highlight-end
```

```groovy title="build.gradle"
// Replace
apollo {
sourceSet {
schemaFilePath = "/path/to/your/schema.json"
exclude = "**/*.gql"
service("service") {
sourceSet {
schemaFilePath = "/path/to/your/schema.json"
exclude = "**/*.gql"
}
outputPackageName = "com.example"
}
outputPackageName = "com.example"
}

// With:
apollo {
schemaFile.set(file("/path/to/your/schema.json"))
graphqlSourceDirectorySet.exclude("**/*.gql")
packageName.set("com.example")
service("service") {
schemaFile.set(file("/path/to/your/schema.json"))
graphqlSourceDirectorySet.exclude("**/*.gql")
packageName.set("com.example")
}
}
```

Expand All @@ -111,11 +117,13 @@ you to use the [Property.set](https://docs.gradle.org/current/javadoc/org/gradle

```kotlin title="build.gradle"
apollo {
// Replace:
setGenerateKotlinModels(true)
service("service") {
// Replace:
setGenerateKotlinModels(true)

// With:
generateKotlinModels.set(true) // highlight-line
// With:
generateKotlinModels.set(true) // highlight-line
}
}
```

Expand Down