-
Notifications
You must be signed in to change notification settings - Fork 662
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate Cache class from @CacheControl directives
- Loading branch information
Showing
59 changed files
with
2,765 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1035,6 +1035,7 @@ final fun (kotlin/String).com.apollographql.apollo.ast/toGQLValue(com.apollograp | |
final fun (okio/Path).com.apollographql.apollo.ast/parseAsGQLDocument(com.apollographql.apollo.ast/ParserOptions = ...): com.apollographql.apollo.ast/GQLResult<com.apollographql.apollo.ast/GQLDocument> // com.apollographql.apollo.ast/parseAsGQLDocument|[email protected](com.apollographql.apollo.ast.ParserOptions){}[0] | ||
final fun (okio/Path).com.apollographql.apollo.ast/toGQLDocument(com.apollographql.apollo.ast/ParserOptions = ..., kotlin/Boolean = ...): com.apollographql.apollo.ast/GQLDocument // com.apollographql.apollo.ast/toGQLDocument|[email protected](com.apollographql.apollo.ast.ParserOptions;kotlin.Boolean){}[0] | ||
final fun com.apollographql.apollo.ast/builtinDefinitions(): kotlin.collections/List<com.apollographql.apollo.ast/GQLDefinition> // com.apollographql.apollo.ast/builtinDefinitions|builtinDefinitions(){}[0] | ||
final fun com.apollographql.apollo.ast/cacheDefinitions(kotlin/String): kotlin.collections/List<com.apollographql.apollo.ast/GQLDefinition> // com.apollographql.apollo.ast/cacheDefinitions|cacheDefinitions(kotlin.String){}[0] | ||
final fun com.apollographql.apollo.ast/kotlinLabsDefinitions(kotlin/String): kotlin.collections/List<com.apollographql.apollo.ast/GQLDefinition> // com.apollographql.apollo.ast/kotlinLabsDefinitions|kotlinLabsDefinitions(kotlin.String){}[0] | ||
final fun com.apollographql.apollo.ast/linkDefinitions(): kotlin.collections/List<com.apollographql.apollo.ast/GQLDefinition> // com.apollographql.apollo.ast/linkDefinitions|linkDefinitions(){}[0] | ||
final fun com.apollographql.apollo.ast/nullabilityDefinitions(kotlin/String): kotlin.collections/List<com.apollographql.apollo.ast/GQLDefinition> // com.apollographql.apollo.ast/nullabilityDefinitions|nullabilityDefinitions(kotlin.String){}[0] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...r/src/main/kotlin/com/apollographql/apollo/compiler/codegen/kotlin/schema/CacheBuilder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.apollographql.apollo.compiler.codegen.kotlin.schema | ||
|
||
import com.apollographql.apollo.compiler.codegen.ResolverKeyKind | ||
import com.apollographql.apollo.compiler.codegen.cachePackageName | ||
import com.apollographql.apollo.compiler.codegen.kotlin.CgFile | ||
import com.apollographql.apollo.compiler.codegen.kotlin.CgFileBuilder | ||
import com.apollographql.apollo.compiler.codegen.kotlin.KotlinSchemaContext | ||
import com.apollographql.apollo.compiler.codegen.kotlin.KotlinSymbols | ||
import com.squareup.kotlinpoet.ClassName | ||
import com.squareup.kotlinpoet.CodeBlock | ||
import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy | ||
import com.squareup.kotlinpoet.PropertySpec | ||
import com.squareup.kotlinpoet.TypeSpec | ||
|
||
internal class CacheBuilder( | ||
private val context: KotlinSchemaContext, | ||
private val maxAges: Map<String, Int>, | ||
) : CgFileBuilder { | ||
private val layout = context.layout | ||
private val packageName = layout.cachePackageName() | ||
private val simpleName = layout.cacheName() | ||
|
||
override fun prepare() { | ||
context.resolver.register(ResolverKeyKind.Cache, "", ClassName(packageName, simpleName)) | ||
} | ||
|
||
override fun build(): CgFile { | ||
return CgFile( | ||
packageName = packageName, | ||
fileName = simpleName, | ||
typeSpecs = listOf(typeSpec()) | ||
) | ||
} | ||
|
||
private fun typeSpec(): TypeSpec { | ||
return TypeSpec.objectBuilder(simpleName) | ||
.addProperty(maxAgesPropertySpec()) | ||
.build() | ||
} | ||
|
||
private fun maxAgesPropertySpec(): PropertySpec { | ||
val builder = CodeBlock.builder().apply { | ||
add("mapOf(\n") | ||
indent() | ||
add( | ||
maxAges.map {(k, v) -> | ||
CodeBlock.of("%S to %L", k, v) | ||
}.joinToString(",\n", postfix = ",\n") | ||
) | ||
unindent() | ||
add(")") | ||
} | ||
|
||
return PropertySpec.builder("maxAges", KotlinSymbols.Map.parameterizedBy(KotlinSymbols.String, KotlinSymbols.Int)) | ||
.initializer(builder.build()) | ||
.build() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
libraries/apollo-compiler/src/test/graphql/com/example/max_age/TestOperation.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# maxAge: 0 | ||
# Query.book doesn't set a maxAge and it's a root field (default 0). | ||
query GetBookTitle { | ||
book { # 0 | ||
cachedTitle # 30 | ||
} | ||
} | ||
|
||
# maxAge: 60 | ||
# Query.cachedBook has a maxAge of 60, and Book.title is a scalar, so it | ||
# inherits maxAge from its parent by default. | ||
query GetCachedBookTitle { | ||
cachedBook { # 60 | ||
title # inherits | ||
} | ||
} | ||
|
||
# maxAge: 30 | ||
# Query.cachedBook has a maxAge of 60, but Book.cachedTitle has | ||
# a maxAge of 30. | ||
query GetCachedBookCachedTitle { | ||
cachedBook { # 60 | ||
cachedTitle # 30 | ||
} | ||
} | ||
|
||
# maxAge: 40 | ||
# Query.reader has a maxAge of 40. Reader.Book is set to | ||
# inheritMaxAge from its parent, and Book.title is a scalar | ||
# that inherits maxAge from its parent by default. | ||
query GetReaderBookTitle { | ||
reader { # 40 | ||
book { # inherits | ||
title # inherits | ||
} | ||
} | ||
} |
Oops, something went wrong.