├── .gitattributes ├── .gitignore ├── README.md ├── chromatophore-core ├── build.gradle.kts └── src │ ├── main │ └── kotlin │ │ └── com │ │ └── xuorig │ │ └── chromatophore │ │ ├── ChromatophoreStore.kt │ │ ├── ClientVersionIndex.kt │ │ ├── InMemoryStore.kt │ │ ├── SchemaVersionTransformVisitor.kt │ │ ├── SchemaVersionTransformer.kt │ │ └── instrumentation │ │ ├── ClientIdContextExtractor.kt │ │ ├── SchemaTransformInstrumentation.kt │ │ └── VersionCollectionInstrumentation.kt │ └── test │ └── kotlin │ └── com │ └── xuorig │ └── chromatophore │ ├── InMemoryStoreTest.kt │ ├── SchemaVersionTransformerTest.kt │ ├── VersionCollectorTest.kt │ └── helpers.kt ├── chromatophore-spring-boot-autoconfigure ├── build.gradle.kts └── src │ └── main │ ├── kotlin │ └── com │ │ └── xuorig │ │ └── chromatophore │ │ └── autoconfig │ │ ├── ChromatophoreAutoConfiguration.kt │ │ ├── ChromatophoreConfigurationProperties.kt │ │ └── ClientIdHeaderInterceptor.kt │ └── resources │ └── META-INF │ └── spring.factories ├── chromatophore-spring-boot-example ├── .gitignore ├── build.gradle.kts ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle.kts └── src │ ├── main │ ├── kotlin │ │ └── com │ │ │ └── xuorig │ │ │ └── chromatophore │ │ │ └── example │ │ │ ├── ExampleApplication.kt │ │ │ ├── chromatophore │ │ │ ├── ChromatophoreClient.kt │ │ │ ├── ChromatophoreClientRepository.kt │ │ │ ├── ChromatophoreFieldTransform.kt │ │ │ ├── ChromatophoreFieldTransformRepository.kt │ │ │ └── ChromatophoreMysqlStore.kt │ │ │ └── shows │ │ │ └── ShowsController.kt │ └── resources │ │ ├── application.properties │ │ └── graphql │ │ └── schema.graphqls │ └── test │ └── kotlin │ └── com │ └── xuorig │ └── chromatophore │ └── example │ └── ExampleApplicationTests.kt ├── chromatophore-spring-boot-starter └── build.gradle.kts ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle.kts /.gitattributes: -------------------------------------------------------------------------------- 1 | # 2 | # https://help.github.com/articles/dealing-with-line-endings/ 3 | # 4 | # Linux start script should use lf 5 | /gradlew text eol=lf 6 | 7 | # These are Windows script files and should use crlf 8 | *.bat text eol=crlf 9 | 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore Gradle project-specific cache directory 2 | .gradle 3 | 4 | # Ignore Gradle build output directory 5 | build 6 | 7 | .idea 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Chromatophore 2 | 3 | > Some species can rapidly change colour through mechanisms that translocate pigment and reorient reflective plates within chromatophores. This process, often used as a type of camouflage, is called physiological colour change or metachrosis 4 | 5 | Chromatophore is a graphql-java compatible library that helps schema designers to evolve the schema and deprecate field 6 | without impacting new clients. 7 | 8 | **Note: This is mostly a POC and is in development right now.** 9 | 10 | ## How it works 11 | 12 | When your GraphQL server receives at request, it pins every requested field to the requesting client. Going forward, 13 | this client will always be served that version of the field. 14 | 15 | When a field needs to be deprecated, we can simply deprecate it as usual: 16 | 17 | ```graphql 18 | type Product { 19 | price: Int @deprecated(reason: "Price as a Int was a terrible idea!") 20 | } 21 | ``` 22 | 23 | Usually, we'd introduce a field like `priceV2` or `priceObject` because `price` is already taken. However, 24 | it sucks to make new clients pay the cost of our mistakes. Chromatophore lets you introduce new fields, 25 | and expose them as an old name for new clients: 26 | 27 | ```graphql 28 | type Product { 29 | price: Int @deprecated(reason: "Price as a Int was a terrible idea!") 30 | 31 | """ 32 | Only you sees `priceV2`, for new clients, priceV2 will actually 33 | be exposed as `price`. 34 | """ 35 | priceV2: Price @supersedesField(field: "price", version: 1) 36 | } 37 | 38 | type Price { 39 | cents: Int 40 | } 41 | ``` 42 | 43 | ## Client Upgrade 44 | 45 | > TODO -------------------------------------------------------------------------------- /chromatophore-core/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * This file was generated by the Gradle 'init' task. 3 | * 4 | * This generated file contains a sample Kotlin library project to get you started. 5 | * For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle 6 | * User Manual available at https://docs.gradle.org/7.5.1/userguide/building_java_projects.html 7 | * This project uses @Incubating APIs which are subject to change. 8 | */ 9 | 10 | plugins { 11 | // Apply the org.jetbrains.kotlin.jvm Plugin to add support for Kotlin. 12 | id("org.jetbrains.kotlin.jvm") version "1.6.21" 13 | 14 | // Apply the java-library plugin for API and implementation separation. 15 | `java-library` 16 | } 17 | 18 | repositories { 19 | // Use Maven Central for resolving dependencies. 20 | mavenCentral() 21 | } 22 | 23 | dependencies { 24 | // Align versions of all Kotlin components 25 | implementation(platform("org.jetbrains.kotlin:kotlin-bom")) 26 | 27 | // Use the Kotlin JDK 8 standard library. 28 | implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") 29 | 30 | implementation("com.graphql-java:graphql-java:18.3") 31 | } 32 | 33 | testing { 34 | suites { 35 | // Configure the built-in test suite 36 | val test by getting(JvmTestSuite::class) { 37 | // Use Kotlin Test test framework 38 | useKotlinTest() 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /chromatophore-core/src/main/kotlin/com/xuorig/chromatophore/ChromatophoreStore.kt: -------------------------------------------------------------------------------- 1 | package com.xuorig.chromatophore 2 | 3 | /** 4 | * Chromophore needs to persist state about the field versions a client expects to see. 5 | * 6 | */ 7 | interface ChromatophoreStore { 8 | fun persistClientIndex(clientId: String, index: Map) 9 | fun getClientIndex(clientId: String): Map? 10 | } -------------------------------------------------------------------------------- /chromatophore-core/src/main/kotlin/com/xuorig/chromatophore/ClientVersionIndex.kt: -------------------------------------------------------------------------------- 1 | package com.xuorig.chromatophore 2 | 3 | import java.time.Instant 4 | 5 | typealias FieldCoordinates = String 6 | 7 | data class FieldVersionInfo( 8 | val version: Int, 9 | val firstRequested: Instant 10 | ) 11 | 12 | interface ClientVersionIndex { 13 | fun getField(coordinates: FieldCoordinates): FieldVersionInfo? 14 | } 15 | 16 | class DefaultClientVersionIndex(private val fieldMapping: Map): ClientVersionIndex { 17 | override fun getField(coordinates: FieldCoordinates): FieldVersionInfo? { 18 | return fieldMapping[coordinates] 19 | } 20 | } 21 | 22 | class NullClientVersionIndex(): ClientVersionIndex { 23 | override fun getField(coordinates: FieldCoordinates): FieldVersionInfo? { 24 | return null 25 | } 26 | } -------------------------------------------------------------------------------- /chromatophore-core/src/main/kotlin/com/xuorig/chromatophore/InMemoryStore.kt: -------------------------------------------------------------------------------- 1 | package com.xuorig.chromatophore 2 | 3 | class InMemoryStore(): ChromatophoreStore { 4 | val store = mutableMapOf>() 5 | 6 | override fun persistClientIndex(clientId: String, index: Map) { 7 | store.compute(clientId) { _, existingIndex -> 8 | if (existingIndex == null) { 9 | index 10 | } else { 11 | existingIndex + index 12 | } 13 | } 14 | } 15 | 16 | override fun getClientIndex(clientId: String): Map? { 17 | return store[clientId] 18 | } 19 | } -------------------------------------------------------------------------------- /chromatophore-core/src/main/kotlin/com/xuorig/chromatophore/SchemaVersionTransformVisitor.kt: -------------------------------------------------------------------------------- 1 | package com.xuorig.chromatophore 2 | 3 | import graphql.Scalars 4 | import graphql.language.IntValue 5 | import graphql.schema.* 6 | import graphql.util.TraversalControl 7 | import graphql.util.TraverserContext 8 | 9 | const val CHROMATOPHORE_SUPERSEDES_FIELD_DIRECTIVE = "supersedesField" 10 | const val CHROMATOPHORE_VERSION_DIRECTIVE = "chromatophoreVersion" 11 | 12 | class SchemaVersionTransformVisitor(private val clientIndex: ClientVersionIndex) : GraphQLTypeVisitorStub() { 13 | override fun visitGraphQLObjectType( 14 | node: GraphQLObjectType, 15 | context: TraverserContext 16 | ): TraversalControl { 17 | val supersedingFields = mutableMapOf>() 18 | 19 | // Collect all possible superseding fields 20 | node.fields.forEach { field -> 21 | val dir = field.appliedDirectives.find { it.name == CHROMATOPHORE_SUPERSEDES_FIELD_DIRECTIVE } 22 | 23 | if (dir != null) { 24 | val fieldToReplace = dir.getArgument("field").getValue() 25 | val version = dir.getArgument("version").getValue() 26 | supersedingFields.putIfAbsent(fieldToReplace, mutableSetOf()) 27 | supersedingFields[fieldToReplace]!!.add(SupersedingField(field, version)) 28 | } 29 | } 30 | 31 | // Add the original field def as well for version 0 32 | supersedingFields.keys.forEach { fieldName -> 33 | val fieldDef = node.getField(fieldName) 34 | supersedingFields[fieldName]!!.add(SupersedingField(fieldDef, 0)) 35 | } 36 | 37 | // First we build the new fields matching for the right requested version. 38 | // When there is no requested version, we take the most recent version. 39 | val newFields = supersedingFields.map { (replacedName, potentialFields) -> 40 | val fieldKey = "${node.name}.${replacedName}" 41 | val clientVersion = clientIndex.getField(fieldKey) 42 | 43 | val matchingField = if (clientVersion != null) { 44 | potentialFields.find { it.version == clientVersion.version } 45 | } else { 46 | potentialFields.maxByOrNull { it.version } 47 | } 48 | 49 | matchingField?.fieldDefinition?.transform { 50 | it.name(replacedName).withAppliedDirective(versionDirective(matchingField.version)) 51 | } 52 | }.filterNotNull() 53 | 54 | 55 | // Then, remove all fields that are going to be replaced, or are replacing fields 56 | val willReplaceNames = supersedingFields.values.flatMap { it.map { it.fieldDefinition.name } } 57 | val filteredFields = node.fields.filter { it.name !in supersedingFields && it.name !in willReplaceNames } 58 | 59 | return changeNode(context, node.transform { it.replaceFields(filteredFields + newFields) }) 60 | } 61 | 62 | private fun versionDirective(version: Int): GraphQLAppliedDirective { 63 | return GraphQLAppliedDirective.newDirective().name(CHROMATOPHORE_VERSION_DIRECTIVE).argument { 64 | it.name("number").type(Scalars.GraphQLInt).valueLiteral(IntValue(version.toBigInteger())) 65 | }.build() 66 | } 67 | 68 | internal data class SupersedingField( 69 | val fieldDefinition: GraphQLFieldDefinition, 70 | val version: Int 71 | ) 72 | } -------------------------------------------------------------------------------- /chromatophore-core/src/main/kotlin/com/xuorig/chromatophore/SchemaVersionTransformer.kt: -------------------------------------------------------------------------------- 1 | package com.xuorig.chromatophore 2 | 3 | import graphql.schema.* 4 | 5 | class SchemaVersionTransformer(private val persistenceAdapter: ChromatophoreStore) { 6 | fun versionSchema( 7 | schema: GraphQLSchema, 8 | clientId: String, 9 | ): GraphQLSchema { 10 | val clientIndex = persistenceAdapter.getClientIndex(clientId) 11 | 12 | val visitor = if (clientIndex == null) { 13 | SchemaVersionTransformVisitor(NullClientVersionIndex()) 14 | } else { 15 | SchemaVersionTransformVisitor(DefaultClientVersionIndex(clientIndex)) 16 | } 17 | 18 | return SchemaTransformer.transformSchema(schema, visitor) 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /chromatophore-core/src/main/kotlin/com/xuorig/chromatophore/instrumentation/ClientIdContextExtractor.kt: -------------------------------------------------------------------------------- 1 | package com.xuorig.chromatophore.instrumentation 2 | 3 | import graphql.GraphQLContext 4 | 5 | fun interface ClientIdContextExtractor { 6 | fun extract(ctx: GraphQLContext): String? 7 | } -------------------------------------------------------------------------------- /chromatophore-core/src/main/kotlin/com/xuorig/chromatophore/instrumentation/SchemaTransformInstrumentation.kt: -------------------------------------------------------------------------------- 1 | package com.xuorig.chromatophore.instrumentation 2 | 3 | import com.xuorig.chromatophore.ChromatophoreStore 4 | import com.xuorig.chromatophore.SchemaVersionTransformer 5 | import graphql.GraphQLContext 6 | import graphql.execution.instrumentation.SimpleInstrumentation 7 | import graphql.execution.instrumentation.parameters.InstrumentationExecutionParameters 8 | import graphql.schema.GraphQLSchema 9 | 10 | /** 11 | * [SchemaTransformInstrumentation] is a GraphQL-Java [SimpleInstrumentation] that 12 | * transforms and versions the schema on every request based on clientId. 13 | */ 14 | class SchemaTransformInstrumentation( 15 | private val persistenceAdapter: ChromatophoreStore, 16 | private val clientIdFromContext: ClientIdContextExtractor 17 | ) : SimpleInstrumentation() { 18 | private val transformer = SchemaVersionTransformer(persistenceAdapter) 19 | 20 | override fun instrumentSchema( 21 | schema: GraphQLSchema, 22 | parameters: InstrumentationExecutionParameters, 23 | ): GraphQLSchema { 24 | val clientId = clientIdFromContext.extract(parameters.graphQLContext) ?: 25 | return super.instrumentSchema(schema, parameters) 26 | 27 | return transformer.versionSchema(schema, clientId) 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /chromatophore-core/src/main/kotlin/com/xuorig/chromatophore/instrumentation/VersionCollectionInstrumentation.kt: -------------------------------------------------------------------------------- 1 | package com.xuorig.chromatophore.instrumentation 2 | 3 | import com.xuorig.chromatophore.CHROMATOPHORE_VERSION_DIRECTIVE 4 | import com.xuorig.chromatophore.ChromatophoreStore 5 | import com.xuorig.chromatophore.FieldVersionInfo 6 | import graphql.ExecutionResult 7 | import graphql.GraphQLContext 8 | import graphql.execution.instrumentation.InstrumentationContext 9 | import graphql.execution.instrumentation.InstrumentationState 10 | import graphql.execution.instrumentation.SimpleInstrumentation 11 | import graphql.execution.instrumentation.SimpleInstrumentationContext 12 | import graphql.execution.instrumentation.parameters.InstrumentationCreateStateParameters 13 | import graphql.execution.instrumentation.parameters.InstrumentationExecutionParameters 14 | import graphql.execution.instrumentation.parameters.InstrumentationFieldParameters 15 | import graphql.schema.GraphQLAppliedDirective 16 | import graphql.schema.GraphQLFieldDefinition 17 | import graphql.schema.GraphQLNamedOutputType 18 | import graphql.schema.GraphQLOutputType 19 | import java.time.Instant 20 | import java.util.concurrent.CompletableFuture 21 | 22 | /** 23 | * The version collector is a graphql-java [SimpleInstrumentation] 24 | * that records which version of the schema fields a client is using. 25 | */ 26 | class VersionCollectionInstrumentation( 27 | private val persistenceAdapter: ChromatophoreStore, 28 | private val clientIdFromContext: ClientIdContextExtractor 29 | ) : SimpleInstrumentation() { 30 | override fun createState(parameters: InstrumentationCreateStateParameters): InstrumentationState { 31 | return VersionCollectorState() 32 | } 33 | 34 | override fun beginField( 35 | parameters: InstrumentationFieldParameters, 36 | ): InstrumentationContext { 37 | return object: SimpleInstrumentationContext() { 38 | override fun onCompleted(result: ExecutionResult, t: Throwable?) { 39 | val collector = parameters.getInstrumentationState() 40 | val parentType = parameters.executionStepInfo.parent.type 41 | collector.addField(parentType, parameters.field) 42 | } 43 | } 44 | } 45 | 46 | override fun instrumentExecutionResult( 47 | executionResult: ExecutionResult, 48 | parameters: InstrumentationExecutionParameters, 49 | ): CompletableFuture { 50 | val collector = parameters.getInstrumentationState() 51 | val result = super.instrumentExecutionResult(executionResult, parameters) 52 | 53 | val clientId = clientIdFromContext.extract(parameters.graphQLContext) ?: return result 54 | persistenceAdapter.persistClientIndex(clientId, collector.index) 55 | 56 | return result 57 | } 58 | } 59 | 60 | class VersionCollectorState : InstrumentationState { 61 | val index = mutableMapOf() 62 | 63 | private val now: Instant = Instant.now() 64 | 65 | fun addField(parent: GraphQLOutputType, field: GraphQLFieldDefinition) { 66 | val namedType = parent as GraphQLNamedOutputType 67 | 68 | val directive = supersedingDirective(field) 69 | 70 | val fieldKey = "${namedType.name}.${field.name}" 71 | 72 | val version = if (directive != null) { 73 | directive.getArgument("number").getValue() 74 | } else { 75 | 0 76 | } 77 | 78 | index[fieldKey] = FieldVersionInfo( 79 | version = version, 80 | firstRequested = now 81 | ) 82 | } 83 | 84 | private fun supersedingDirective(field: GraphQLFieldDefinition): GraphQLAppliedDirective? { 85 | return field.appliedDirectives.find { directive -> directive.name == CHROMATOPHORE_VERSION_DIRECTIVE } 86 | } 87 | } -------------------------------------------------------------------------------- /chromatophore-core/src/test/kotlin/com/xuorig/chromatophore/InMemoryStoreTest.kt: -------------------------------------------------------------------------------- 1 | package com.xuorig.chromatophore 2 | 3 | import java.time.Instant 4 | import kotlin.test.Test 5 | import kotlin.test.assertEquals 6 | 7 | internal class InMemoryStoreTest { 8 | 9 | @Test 10 | fun `persist merges indexes`() { 11 | val store = InMemoryStore() 12 | 13 | store.persistClientIndex( 14 | "client1", mapOf( 15 | "Product.name" to FieldVersionInfo(0, Instant.now()) 16 | ) 17 | ) 18 | 19 | store.persistClientIndex( 20 | "client1", mapOf( 21 | "Product.description" to FieldVersionInfo(0, Instant.now()) 22 | ) 23 | ) 24 | 25 | assertEquals(2, store.getClientIndex("client1")!!.size) 26 | 27 | store.persistClientIndex( 28 | "client1", mapOf( 29 | "Product.name" to FieldVersionInfo(1, Instant.now()) 30 | ) 31 | ) 32 | 33 | assertEquals(1, store.getClientIndex("client1")!!["Product.name"]!!.version) 34 | } 35 | } -------------------------------------------------------------------------------- /chromatophore-core/src/test/kotlin/com/xuorig/chromatophore/SchemaVersionTransformerTest.kt: -------------------------------------------------------------------------------- 1 | package com.xuorig.chromatophore 2 | 3 | import graphql.schema.GraphQLObjectType 4 | import graphql.schema.GraphQLScalarType 5 | import graphql.schema.idl.* 6 | import java.time.Instant 7 | import kotlin.test.Test 8 | import kotlin.test.assertEquals 9 | import kotlin.test.assertNotNull 10 | import kotlin.test.assertNull 11 | 12 | class SchemaVersionTransformerTest { 13 | @Test 14 | fun `replaces with most recent versions for brand new client`() { 15 | val sdl = """ 16 | directive @supersedesField(field: String!, version: Int = 1) on FIELD_DEFINITION 17 | 18 | type Query { 19 | product: Product 20 | } 21 | 22 | type Product { 23 | name: String 24 | price: Int 25 | priceV2: Price @supersedesField(field: "price", version: 1) 26 | description: String 27 | } 28 | 29 | type Price { 30 | cents: Int 31 | } 32 | """.trimIndent() 33 | 34 | val graphQLSchema = buildSchema(sdl, EchoingWiringFactory.newEchoingWiring()) 35 | 36 | val transformed = SchemaVersionTransformer(InMemoryStore()).versionSchema(graphQLSchema, "client1") 37 | 38 | val productType = transformed.getType("Product") as GraphQLObjectType 39 | val priceField = productType.getField("price") 40 | 41 | // price field should be of Money type 42 | assertEquals("Price", (priceField.type as GraphQLObjectType).name) 43 | 44 | val versionArgument = priceField.getAppliedDirective(CHROMATOPHORE_VERSION_DIRECTIVE).getArgument("number") 45 | val versionNumber = versionArgument.getValue() 46 | assertEquals(1, versionNumber) 47 | 48 | assertNull(productType.getField("priceV2")) 49 | } 50 | 51 | @Test 52 | fun `replaces with client index version`() { 53 | val sdl = """ 54 | directive @supersedesField(field: String!, version: Int = 1) on FIELD_DEFINITION 55 | 56 | type Query { 57 | product: Product 58 | } 59 | 60 | type Product { 61 | name: String 62 | price: Int 63 | priceV2: Price @supersedesField(field: "price", version: 1) 64 | priceV3: Price2 @supersedesField(field: "price", version: 2) 65 | description: String 66 | } 67 | 68 | type Price { 69 | cents: Int 70 | } 71 | 72 | type Price2 { 73 | cents: Int 74 | } 75 | """.trimIndent() 76 | 77 | val graphQLSchema = buildSchema(sdl, EchoingWiringFactory.newEchoingWiring()) 78 | 79 | val adapter = InMemoryStore() 80 | adapter.persistClientIndex("client1", mutableMapOf( 81 | "Product.price" to FieldVersionInfo(1, firstRequested = Instant.now()) 82 | )) 83 | 84 | val transformed = SchemaVersionTransformer(adapter).versionSchema(graphQLSchema, "client1") 85 | 86 | val productType = transformed.getType("Product") as GraphQLObjectType 87 | val priceField = productType.getField("price") 88 | 89 | // price field should be of Money type 90 | assertEquals("Price", (priceField.type as GraphQLObjectType).name) 91 | 92 | // version 1 was selected 93 | val versionArgument = priceField.getAppliedDirective(CHROMATOPHORE_VERSION_DIRECTIVE).getArgument("number") 94 | val versionNumber = versionArgument.getValue() 95 | assertEquals(1, versionNumber) 96 | 97 | assertNull(productType.getField("priceV2")) 98 | assertNull(productType.getField("priceV3")) 99 | } 100 | 101 | @Test 102 | fun `version 0 selects the original field`() { 103 | val sdl = """ 104 | directive @supersedesField(field: String!, version: Int = 1) on FIELD_DEFINITION 105 | 106 | type Query { 107 | product: Product 108 | } 109 | 110 | type Product { 111 | name: String 112 | price: Int 113 | priceV2: Price @supersedesField(field: "price", version: 1) 114 | priceV3: Price2 @supersedesField(field: "price", version: 2) 115 | description: String 116 | } 117 | 118 | type Price { 119 | cents: Int 120 | } 121 | 122 | type Price2 { 123 | cents: Int 124 | } 125 | """.trimIndent() 126 | 127 | val graphQLSchema = buildSchema(sdl, EchoingWiringFactory.newEchoingWiring()) 128 | 129 | val adapter = InMemoryStore() 130 | adapter.persistClientIndex("client1", mutableMapOf( 131 | "Product.price" to FieldVersionInfo(0, firstRequested = Instant.now()) 132 | )) 133 | 134 | val transformed = SchemaVersionTransformer(adapter).versionSchema(graphQLSchema, "client1") 135 | 136 | val productType = transformed.getType("Product") as GraphQLObjectType 137 | val priceField = productType.getField("price") 138 | 139 | // price field should be of Money type 140 | assertEquals("Int", (priceField.type as GraphQLScalarType).name) 141 | 142 | // version 0 was selected 143 | val versionArgument = priceField.getAppliedDirective(CHROMATOPHORE_VERSION_DIRECTIVE).getArgument("number") 144 | val versionNumber = versionArgument.getValue() 145 | assertEquals(0, versionNumber) 146 | 147 | assertNotNull(productType.getField("price")) 148 | assertNull(productType.getField("priceV2")) 149 | assertNull(productType.getField("priceV3")) 150 | } 151 | } -------------------------------------------------------------------------------- /chromatophore-core/src/test/kotlin/com/xuorig/chromatophore/VersionCollectorTest.kt: -------------------------------------------------------------------------------- 1 | package com.xuorig.chromatophore 2 | 3 | import com.xuorig.chromatophore.instrumentation.VersionCollectionInstrumentation 4 | import graphql.ExecutionInput 5 | import graphql.GraphQL 6 | import graphql.schema.idl.* 7 | import kotlin.test.Test 8 | import kotlin.test.assertEquals 9 | import kotlin.test.assertNotNull 10 | 11 | class VersionCollectorTest { 12 | @Test 13 | fun `collects default versions for all fields`() { 14 | val sdl = """ 15 | type Query { 16 | product: Product 17 | } 18 | 19 | type Product { 20 | name: String 21 | price: Int 22 | description: String 23 | image(size: Int): Image 24 | } 25 | 26 | type Image { 27 | size: Int 28 | alt: String 29 | url: String 30 | } 31 | """.trimIndent() 32 | 33 | val graphQLSchema = buildSchema(sdl, EchoingWiringFactory.newEchoingWiring()) 34 | val mmrAdapter = InMemoryStore() 35 | val versionCollector = VersionCollectionInstrumentation(mmrAdapter) { 36 | it["chromatophore.clientId"] 37 | } 38 | val build = GraphQL.newGraphQL(graphQLSchema).instrumentation(versionCollector).build() 39 | 40 | val query = "{ product { name price description image(size: 4) { size alt url } } }" 41 | val executionInput = ExecutionInput.newExecutionInput().query(query).graphQLContext(mapOf("chromatophore.clientId" to "client1")) 42 | build.execute(executionInput.build()) 43 | 44 | val clientIndex = mmrAdapter.store["client1"] 45 | assertNotNull(clientIndex, "No client index was created for client1") 46 | 47 | assertEquals(8, clientIndex.keys.size) 48 | assertNotNull(clientIndex["Query.product"]) 49 | assertEquals(0, clientIndex["Product.name"]!!.version, "Expected field to have same signature as original field name") 50 | } 51 | 52 | @Test 53 | fun `collects superseded versions for fields`() { 54 | val sdl = """ 55 | directive @supersedesFieldInternal(version: String) on FIELD_DEFINITION 56 | 57 | type Query { 58 | product: Product @supersedesFieldInternal(version: "2") 59 | } 60 | 61 | type Product { 62 | name: String 63 | price: Int 64 | description: String 65 | image(size: Int): Image 66 | } 67 | 68 | type Image { 69 | size: Int 70 | alt: String 71 | url: String 72 | } 73 | """.trimIndent() 74 | 75 | val graphQLSchema = buildSchema(sdl, EchoingWiringFactory.newEchoingWiring()) 76 | 77 | val mmrAdapter = InMemoryStore() 78 | val versionCollector = VersionCollectionInstrumentation(mmrAdapter) { 79 | it["chromatophore.clientId"] 80 | } 81 | val build = GraphQL.newGraphQL(graphQLSchema).instrumentation(versionCollector).build() 82 | 83 | val query = "{ product { name price description image(size: 4) { size alt url } } }" 84 | val executionInput = ExecutionInput.newExecutionInput().query(query).graphQLContext(mapOf("chromatophore.clientId" to "client1")) 85 | build.execute(executionInput.build()) 86 | 87 | val clientIndex = mmrAdapter.store["client1"] 88 | assertNotNull(clientIndex, "No client index was created for client1") 89 | 90 | assertEquals(8, clientIndex.keys.size) 91 | assertNotNull(clientIndex["Query.product"]) 92 | assertEquals(2, clientIndex["Query.product"]!!.version, "Expected field to have same signature as original field name") 93 | } 94 | } -------------------------------------------------------------------------------- /chromatophore-core/src/test/kotlin/com/xuorig/chromatophore/helpers.kt: -------------------------------------------------------------------------------- 1 | package com.xuorig.chromatophore 2 | 3 | import graphql.schema.GraphQLSchema 4 | import graphql.schema.idl.* 5 | 6 | fun buildSchema(sdl: String, runtimeWiring: RuntimeWiring): GraphQLSchema { 7 | val schemaParser = SchemaParser() 8 | val typeDefinitionRegistry: TypeDefinitionRegistry = schemaParser.parse(sdl) 9 | val schemaGenerator = SchemaGenerator() 10 | return schemaGenerator.makeExecutableSchema(typeDefinitionRegistry, runtimeWiring) 11 | } -------------------------------------------------------------------------------- /chromatophore-spring-boot-autoconfigure/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | kotlin("jvm") version "1.5.31" 3 | } 4 | 5 | version = "unspecified" 6 | 7 | repositories { 8 | mavenCentral() 9 | } 10 | 11 | dependencies { 12 | implementation(kotlin("stdlib")) 13 | implementation(project(":chromatophore-core")) 14 | implementation("org.springframework.boot:spring-boot-starter-graphql:2.7.3") 15 | } -------------------------------------------------------------------------------- /chromatophore-spring-boot-autoconfigure/src/main/kotlin/com/xuorig/chromatophore/autoconfig/ChromatophoreAutoConfiguration.kt: -------------------------------------------------------------------------------- 1 | package com.xuorig.chromatophore.autoconfig 2 | 3 | import com.xuorig.chromatophore.ChromatophoreStore 4 | import com.xuorig.chromatophore.InMemoryStore 5 | import com.xuorig.chromatophore.instrumentation.ClientIdContextExtractor 6 | import com.xuorig.chromatophore.instrumentation.SchemaTransformInstrumentation 7 | import com.xuorig.chromatophore.instrumentation.VersionCollectionInstrumentation 8 | import graphql.execution.instrumentation.Instrumentation 9 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean 10 | import org.springframework.boot.context.properties.EnableConfigurationProperties 11 | import org.springframework.context.annotation.Bean 12 | import org.springframework.context.annotation.Configuration 13 | import org.springframework.graphql.server.WebGraphQlInterceptor 14 | 15 | @Configuration 16 | @EnableConfigurationProperties(ChromatophoreConfigurationProperties::class) 17 | open class ChromatophoreAutoConfiguration( 18 | private val configProps: ChromatophoreConfigurationProperties 19 | ) { 20 | @Bean 21 | @ConditionalOnMissingBean 22 | open fun clientIdContextExtrator(): ClientIdContextExtractor { 23 | return ClientIdContextExtractor { context -> context[configProps.clientIdContextKey] } 24 | 25 | } 26 | 27 | @Bean 28 | @ConditionalOnMissingBean 29 | open fun chromatophoreStore(): ChromatophoreStore { 30 | return InMemoryStore() 31 | } 32 | 33 | @Bean 34 | open fun schemaInstrumentation(store: ChromatophoreStore, clientIdFromContext: ClientIdContextExtractor): Instrumentation { 35 | return SchemaTransformInstrumentation(store, clientIdFromContext) 36 | } 37 | 38 | @Bean 39 | open fun collectorInstrumentation(store: ChromatophoreStore, clientIdFromContext: ClientIdContextExtractor): Instrumentation { 40 | return VersionCollectionInstrumentation(store, clientIdFromContext) 41 | } 42 | 43 | @Bean 44 | open fun clientIdHeaderInterceptor(): WebGraphQlInterceptor { 45 | return ClientIdHeaderInterceptor(configProps.clientIdHeaderName, configProps.clientIdContextKey) 46 | } 47 | } -------------------------------------------------------------------------------- /chromatophore-spring-boot-autoconfigure/src/main/kotlin/com/xuorig/chromatophore/autoconfig/ChromatophoreConfigurationProperties.kt: -------------------------------------------------------------------------------- 1 | package com.xuorig.chromatophore.autoconfig 2 | 3 | import org.springframework.boot.context.properties.ConfigurationProperties 4 | import org.springframework.boot.context.properties.ConstructorBinding 5 | import org.springframework.boot.context.properties.bind.DefaultValue 6 | 7 | /** 8 | * Configuration properties for Chromatophore Spring Boot Integration. 9 | */ 10 | @ConstructorBinding 11 | @ConfigurationProperties(prefix = ChromatophoreConfigurationProperties.PREFIX) 12 | @Suppress("ConfigurationProperties") 13 | class ChromatophoreConfigurationProperties( 14 | @DefaultValue(DEFAULT_CLIENT_ID_CONTEXT_KEY) val clientIdContextKey: String, 15 | @DefaultValue(DEFAULT_CLIENT_ID_HEADER_NAME) val clientIdHeaderName: String 16 | ) { 17 | companion object { 18 | const val PREFIX: String = "chromatophore" 19 | 20 | const val DEFAULT_CLIENT_ID_CONTEXT_KEY = "chromatophore.clientId" 21 | const val DEFAULT_CLIENT_ID_HEADER_NAME = "Chromatophore-Client-Id" 22 | } 23 | } -------------------------------------------------------------------------------- /chromatophore-spring-boot-autoconfigure/src/main/kotlin/com/xuorig/chromatophore/autoconfig/ClientIdHeaderInterceptor.kt: -------------------------------------------------------------------------------- 1 | package com.xuorig.chromatophore.autoconfig 2 | 3 | import org.springframework.graphql.server.WebGraphQlInterceptor 4 | import org.springframework.graphql.server.WebGraphQlRequest 5 | import org.springframework.graphql.server.WebGraphQlResponse 6 | import reactor.core.publisher.Mono 7 | 8 | class ClientIdHeaderInterceptor(private val clientIdHeaderName: String, private val clientIdContextKey: String) : WebGraphQlInterceptor { 9 | override fun intercept(request: WebGraphQlRequest, chain: WebGraphQlInterceptor.Chain): Mono { 10 | val clientId = request.headers[clientIdHeaderName]?.first() 11 | 12 | if (clientId !== null) { 13 | request.configureExecutionInput { _, builder -> 14 | builder.graphQLContext(mapOf(clientIdContextKey to clientId)).build() 15 | } 16 | } 17 | 18 | return chain.next(request) 19 | } 20 | } -------------------------------------------------------------------------------- /chromatophore-spring-boot-autoconfigure/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 2 | com.xuorig.chromatophore.autoconfig.ChromatophoreAutoConfiguration -------------------------------------------------------------------------------- /chromatophore-spring-boot-example/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | .gradle 3 | build/ 4 | !gradle/wrapper/gradle-wrapper.jar 5 | !**/src/main/**/build/ 6 | !**/src/test/**/build/ 7 | 8 | ### STS ### 9 | .apt_generated 10 | .classpath 11 | .factorypath 12 | .project 13 | .settings 14 | .springBeans 15 | .sts4-cache 16 | bin/ 17 | !**/src/main/**/bin/ 18 | !**/src/test/**/bin/ 19 | 20 | ### IntelliJ IDEA ### 21 | .idea 22 | *.iws 23 | *.iml 24 | *.ipr 25 | out/ 26 | !**/src/main/**/out/ 27 | !**/src/test/**/out/ 28 | 29 | ### NetBeans ### 30 | /nbproject/private/ 31 | /nbbuild/ 32 | /dist/ 33 | /nbdist/ 34 | /.nb-gradle/ 35 | 36 | ### VS Code ### 37 | .vscode/ 38 | -------------------------------------------------------------------------------- /chromatophore-spring-boot-example/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import org.jetbrains.kotlin.gradle.tasks.KotlinCompile 2 | 3 | plugins { 4 | id("org.springframework.boot") version "2.7.3" 5 | id("io.spring.dependency-management") version "1.0.13.RELEASE" 6 | kotlin("jvm") version "1.6.21" 7 | kotlin("plugin.spring") version "1.6.21" 8 | id("org.jetbrains.kotlin.plugin.noarg") version "1.6.21" 9 | } 10 | 11 | group = "com.xuorig.chromatophore" 12 | version = "0.0.1-SNAPSHOT" 13 | java.sourceCompatibility = JavaVersion.VERSION_17 14 | 15 | repositories { 16 | mavenCentral() 17 | } 18 | 19 | noArg { 20 | annotation("javax.persistence.Entity") 21 | } 22 | 23 | dependencies { 24 | implementation(project(":chromatophore-spring-boot-starter")) 25 | implementation("org.springframework.boot:spring-boot-starter-web") 26 | implementation("org.springframework.boot:spring-boot-starter-data-jpa") 27 | implementation("mysql:mysql-connector-java") 28 | implementation("org.springframework.boot:spring-boot-starter-graphql") 29 | implementation("org.springframework.boot:spring-boot-starter-actuator") 30 | implementation("org.springframework:spring-webflux") 31 | implementation("com.fasterxml.jackson.module:jackson-module-kotlin") 32 | implementation("org.jetbrains.kotlin:kotlin-reflect") 33 | implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") 34 | testImplementation("org.springframework.boot:spring-boot-starter-test") 35 | testImplementation("org.springframework.graphql:spring-graphql-test") 36 | } 37 | 38 | tasks.withType { 39 | kotlinOptions { 40 | freeCompilerArgs = listOf("-Xjsr305=strict") 41 | jvmTarget = "17" 42 | } 43 | } 44 | 45 | tasks.withType { 46 | useJUnitPlatform() 47 | } 48 | -------------------------------------------------------------------------------- /chromatophore-spring-boot-example/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xuorig/chromatophore/f55c3491ffc7c5b2c6c0f98cfec6697fb62ffca9/chromatophore-spring-boot-example/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /chromatophore-spring-boot-example/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /chromatophore-spring-boot-example/gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 84 | 85 | APP_NAME="Gradle" 86 | APP_BASE_NAME=${0##*/} 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | MAX_FD=$( ulimit -H -n ) || 147 | warn "Could not query maximum file descriptor limit" 148 | esac 149 | case $MAX_FD in #( 150 | '' | soft) :;; #( 151 | *) 152 | ulimit -n "$MAX_FD" || 153 | warn "Could not set maximum file descriptor limit to $MAX_FD" 154 | esac 155 | fi 156 | 157 | # Collect all arguments for the java command, stacking in reverse order: 158 | # * args from the command line 159 | # * the main class name 160 | # * -classpath 161 | # * -D...appname settings 162 | # * --module-path (only if needed) 163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 164 | 165 | # For Cygwin or MSYS, switch paths to Windows format before running java 166 | if "$cygwin" || "$msys" ; then 167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 169 | 170 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 171 | 172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 173 | for arg do 174 | if 175 | case $arg in #( 176 | -*) false ;; # don't mess with options #( 177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 178 | [ -e "$t" ] ;; #( 179 | *) false ;; 180 | esac 181 | then 182 | arg=$( cygpath --path --ignore --mixed "$arg" ) 183 | fi 184 | # Roll the args list around exactly as many times as the number of 185 | # args, so each arg winds up back in the position where it started, but 186 | # possibly modified. 187 | # 188 | # NB: a `for` loop captures its iteration list before it begins, so 189 | # changing the positional parameters here affects neither the number of 190 | # iterations, nor the values presented in `arg`. 191 | shift # remove old arg 192 | set -- "$@" "$arg" # push replacement arg 193 | done 194 | fi 195 | 196 | # Collect all arguments for the java command; 197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 198 | # shell script including quotes and variable substitutions, so put them in 199 | # double quotes to make sure that they get re-expanded; and 200 | # * put everything else in single quotes, so that it's not re-expanded. 201 | 202 | set -- \ 203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 204 | -classpath "$CLASSPATH" \ 205 | org.gradle.wrapper.GradleWrapperMain \ 206 | "$@" 207 | 208 | # Stop when "xargs" is not available. 209 | if ! command -v xargs >/dev/null 2>&1 210 | then 211 | die "xargs is not available" 212 | fi 213 | 214 | # Use "xargs" to parse quoted args. 215 | # 216 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 217 | # 218 | # In Bash we could simply go: 219 | # 220 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 221 | # set -- "${ARGS[@]}" "$@" 222 | # 223 | # but POSIX shell has neither arrays nor command substitution, so instead we 224 | # post-process each arg (as a line of input to sed) to backslash-escape any 225 | # character that might be a shell metacharacter, then use eval to reverse 226 | # that process (while maintaining the separation between arguments), and wrap 227 | # the whole thing up as a single "set" statement. 228 | # 229 | # This will of course break if any of these variables contains a newline or 230 | # an unmatched quote. 231 | # 232 | 233 | eval "set -- $( 234 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 235 | xargs -n1 | 236 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 237 | tr '\n' ' ' 238 | )" '"$@"' 239 | 240 | exec "$JAVACMD" "$@" 241 | -------------------------------------------------------------------------------- /chromatophore-spring-boot-example/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if %ERRORLEVEL% equ 0 goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if %ERRORLEVEL% equ 0 goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | set EXIT_CODE=%ERRORLEVEL% 84 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 85 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 86 | exit /b %EXIT_CODE% 87 | 88 | :mainEnd 89 | if "%OS%"=="Windows_NT" endlocal 90 | 91 | :omega 92 | -------------------------------------------------------------------------------- /chromatophore-spring-boot-example/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "example" 2 | -------------------------------------------------------------------------------- /chromatophore-spring-boot-example/src/main/kotlin/com/xuorig/chromatophore/example/ExampleApplication.kt: -------------------------------------------------------------------------------- 1 | package com.xuorig.chromatophore.example 2 | 3 | import org.springframework.boot.autoconfigure.SpringBootApplication 4 | import org.springframework.boot.runApplication 5 | 6 | @SpringBootApplication 7 | class ExampleApplication 8 | 9 | fun main(args: Array) { 10 | runApplication(*args) 11 | } 12 | -------------------------------------------------------------------------------- /chromatophore-spring-boot-example/src/main/kotlin/com/xuorig/chromatophore/example/chromatophore/ChromatophoreClient.kt: -------------------------------------------------------------------------------- 1 | package com.xuorig.chromatophore.example.chromatophore 2 | 3 | import javax.persistence.* 4 | 5 | @Entity 6 | class ChromatophoreClient( 7 | @Id 8 | @GeneratedValue(strategy=GenerationType.AUTO) 9 | val id: Int? = null, 10 | 11 | @Column(nullable = false) 12 | val name: String 13 | ) -------------------------------------------------------------------------------- /chromatophore-spring-boot-example/src/main/kotlin/com/xuorig/chromatophore/example/chromatophore/ChromatophoreClientRepository.kt: -------------------------------------------------------------------------------- 1 | package com.xuorig.chromatophore.example.chromatophore 2 | 3 | import org.springframework.data.repository.CrudRepository 4 | 5 | interface ChromatophoreClientRepository: CrudRepository { 6 | fun findByName(name: String): ChromatophoreClient? 7 | } -------------------------------------------------------------------------------- /chromatophore-spring-boot-example/src/main/kotlin/com/xuorig/chromatophore/example/chromatophore/ChromatophoreFieldTransform.kt: -------------------------------------------------------------------------------- 1 | package com.xuorig.chromatophore.example.chromatophore 2 | 3 | import javax.persistence.* 4 | 5 | @Entity 6 | @Table(name = "field_transforms", indexes = [Index(name = "fieldNameUniqueIndex", columnList = "fieldName,client_id", unique = true)]) 7 | class ChromatophoreFieldTransform( 8 | @Id 9 | @GeneratedValue(strategy= GenerationType.AUTO) 10 | val id: Int? = null, 11 | 12 | @Column(nullable = false) 13 | val fieldName: String, 14 | 15 | @Column(nullable = false) 16 | val version: Int, 17 | 18 | @ManyToOne 19 | @JoinColumn(name = "client_id") 20 | val client: ChromatophoreClient 21 | ) -------------------------------------------------------------------------------- /chromatophore-spring-boot-example/src/main/kotlin/com/xuorig/chromatophore/example/chromatophore/ChromatophoreFieldTransformRepository.kt: -------------------------------------------------------------------------------- 1 | package com.xuorig.chromatophore.example.chromatophore 2 | 3 | import org.springframework.data.repository.CrudRepository 4 | 5 | interface ChromatophoreFieldTransformRepository: CrudRepository { 6 | fun findAllByClientId(clientId: Int): List 7 | } 8 | -------------------------------------------------------------------------------- /chromatophore-spring-boot-example/src/main/kotlin/com/xuorig/chromatophore/example/chromatophore/ChromatophoreMysqlStore.kt: -------------------------------------------------------------------------------- 1 | package com.xuorig.chromatophore.example.chromatophore 2 | 3 | import com.xuorig.chromatophore.ChromatophoreStore 4 | import com.xuorig.chromatophore.FieldVersionInfo 5 | import org.springframework.stereotype.Component 6 | import java.time.Instant 7 | 8 | /** 9 | * TODO: this is a very naive implementation of storing chromatophore field info. 10 | * Only for demo purposes. 11 | */ 12 | @Component 13 | class ChromatophoreMysqlStore( 14 | val clientRepository: ChromatophoreClientRepository, 15 | val fieldTransformRepository: ChromatophoreFieldTransformRepository 16 | ): ChromatophoreStore { 17 | override fun persistClientIndex(clientId: String, index: Map) { 18 | var client = clientRepository.findByName(clientId) 19 | 20 | if (client == null) { 21 | client = clientRepository.save(ChromatophoreClient(name = clientId)) 22 | } 23 | 24 | val existingFields = fieldTransformRepository.findAllByClientId(client.id!!).map { it.fieldName }.toSet() 25 | 26 | val fieldTransforms = index.filter { entry -> entry.key !in existingFields }.map { (fieldName, version) -> 27 | ChromatophoreFieldTransform( 28 | fieldName = fieldName, 29 | version = version.version, 30 | client = client 31 | ) 32 | } 33 | 34 | fieldTransformRepository.saveAll(fieldTransforms) 35 | } 36 | 37 | override fun getClientIndex(clientId: String): Map? { 38 | var client = clientRepository.findByName(clientId) ?: return null 39 | val existingFields = fieldTransformRepository.findAllByClientId(client.id!!) 40 | 41 | val index = mutableMapOf() 42 | 43 | for (field in existingFields) { 44 | // TODO: Persist first requested 45 | index[field.fieldName] = FieldVersionInfo(field.version, firstRequested = Instant.now()) 46 | } 47 | 48 | return index 49 | } 50 | } -------------------------------------------------------------------------------- /chromatophore-spring-boot-example/src/main/kotlin/com/xuorig/chromatophore/example/shows/ShowsController.kt: -------------------------------------------------------------------------------- 1 | package com.xuorig.chromatophore.example.shows 2 | 3 | import org.springframework.graphql.data.method.annotation.QueryMapping 4 | import org.springframework.stereotype.Controller 5 | 6 | @Controller 7 | class ShowsController { 8 | private val shows = listOf( 9 | Show("Stranger Things", 2016), 10 | Show("Ozark", 2017), 11 | Show("The Crown", 2016), 12 | Show("Dead to Me", 2019), 13 | Show("Orange is the New Black", 2013) 14 | ) 15 | 16 | data class Show(val title: String, val releaseYear: Int) 17 | 18 | @QueryMapping 19 | fun shows(): List { 20 | return shows 21 | } 22 | } -------------------------------------------------------------------------------- /chromatophore-spring-boot-example/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.graphql.graphiql.enabled=true 2 | spring.graphql.graphiql.path=/graphiql 3 | management.endpoints.web.exposure.include=beans 4 | management.endpoint.beans.enabled=true 5 | spring.jpa.hibernate.ddl-auto=update 6 | spring.datasource.url=jdbc:mysql://us-east.connect.psdb.cloud/chromatophore-spring-example?sslMode=VERIFY_IDENTITY 7 | spring.datasource.username=${CHROMATOPHORE_DB_USER} 8 | spring.datasource.password=${CHROMATOPHORE_DB_PW} 9 | spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver 10 | #spring.jpa.show-sql: true -------------------------------------------------------------------------------- /chromatophore-spring-boot-example/src/main/resources/graphql/schema.graphqls: -------------------------------------------------------------------------------- 1 | directive @supersedesField(field: String!, version: Int!) on FIELD_DEFINITION 2 | 3 | type Query { 4 | shows: [Show] 5 | } 6 | 7 | type Show { 8 | title: String 9 | releaseYear: Int 10 | 11 | titleV2: ShowTitle @supersedesField(field: "title", version: 1) 12 | } 13 | 14 | type ShowTitle { 15 | name: String 16 | substitle: String 17 | } 18 | 19 | type ChromatophoreField { 20 | originalFieldName: String! 21 | version: Int! 22 | } 23 | -------------------------------------------------------------------------------- /chromatophore-spring-boot-example/src/test/kotlin/com/xuorig/chromatophore/example/ExampleApplicationTests.kt: -------------------------------------------------------------------------------- 1 | package com.xuorig.chromatophore.example 2 | 3 | import org.junit.jupiter.api.Test 4 | import org.springframework.boot.test.context.SpringBootTest 5 | 6 | @SpringBootTest 7 | class ExampleApplicationTests { 8 | 9 | @Test 10 | fun contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /chromatophore-spring-boot-starter/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | kotlin("jvm") version "1.5.31" 3 | } 4 | 5 | version = "unspecified" 6 | 7 | repositories { 8 | mavenCentral() 9 | } 10 | 11 | dependencies { 12 | implementation(kotlin("stdlib")) 13 | implementation(project(":chromatophore-spring-boot-autoconfigure")) 14 | api(project(":chromatophore-core")) 15 | } -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/xuorig/chromatophore/f55c3491ffc7c5b2c6c0f98cfec6697fb62ffca9/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 84 | 85 | APP_NAME="Gradle" 86 | APP_BASE_NAME=${0##*/} 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | MAX_FD=$( ulimit -H -n ) || 147 | warn "Could not query maximum file descriptor limit" 148 | esac 149 | case $MAX_FD in #( 150 | '' | soft) :;; #( 151 | *) 152 | ulimit -n "$MAX_FD" || 153 | warn "Could not set maximum file descriptor limit to $MAX_FD" 154 | esac 155 | fi 156 | 157 | # Collect all arguments for the java command, stacking in reverse order: 158 | # * args from the command line 159 | # * the main class name 160 | # * -classpath 161 | # * -D...appname settings 162 | # * --module-path (only if needed) 163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 164 | 165 | # For Cygwin or MSYS, switch paths to Windows format before running java 166 | if "$cygwin" || "$msys" ; then 167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 169 | 170 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 171 | 172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 173 | for arg do 174 | if 175 | case $arg in #( 176 | -*) false ;; # don't mess with options #( 177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 178 | [ -e "$t" ] ;; #( 179 | *) false ;; 180 | esac 181 | then 182 | arg=$( cygpath --path --ignore --mixed "$arg" ) 183 | fi 184 | # Roll the args list around exactly as many times as the number of 185 | # args, so each arg winds up back in the position where it started, but 186 | # possibly modified. 187 | # 188 | # NB: a `for` loop captures its iteration list before it begins, so 189 | # changing the positional parameters here affects neither the number of 190 | # iterations, nor the values presented in `arg`. 191 | shift # remove old arg 192 | set -- "$@" "$arg" # push replacement arg 193 | done 194 | fi 195 | 196 | # Collect all arguments for the java command; 197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 198 | # shell script including quotes and variable substitutions, so put them in 199 | # double quotes to make sure that they get re-expanded; and 200 | # * put everything else in single quotes, so that it's not re-expanded. 201 | 202 | set -- \ 203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 204 | -classpath "$CLASSPATH" \ 205 | org.gradle.wrapper.GradleWrapperMain \ 206 | "$@" 207 | 208 | # Stop when "xargs" is not available. 209 | if ! command -v xargs >/dev/null 2>&1 210 | then 211 | die "xargs is not available" 212 | fi 213 | 214 | # Use "xargs" to parse quoted args. 215 | # 216 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 217 | # 218 | # In Bash we could simply go: 219 | # 220 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 221 | # set -- "${ARGS[@]}" "$@" 222 | # 223 | # but POSIX shell has neither arrays nor command substitution, so instead we 224 | # post-process each arg (as a line of input to sed) to backslash-escape any 225 | # character that might be a shell metacharacter, then use eval to reverse 226 | # that process (while maintaining the separation between arguments), and wrap 227 | # the whole thing up as a single "set" statement. 228 | # 229 | # This will of course break if any of these variables contains a newline or 230 | # an unmatched quote. 231 | # 232 | 233 | eval "set -- $( 234 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 235 | xargs -n1 | 236 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 237 | tr '\n' ' ' 238 | )" '"$@"' 239 | 240 | exec "$JAVACMD" "$@" 241 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if %ERRORLEVEL% equ 0 goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if %ERRORLEVEL% equ 0 goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | set EXIT_CODE=%ERRORLEVEL% 84 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 85 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 86 | exit /b %EXIT_CODE% 87 | 88 | :mainEnd 89 | if "%OS%"=="Windows_NT" endlocal 90 | 91 | :omega 92 | -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * This file was generated by the Gradle 'init' task. 3 | * 4 | * The settings file is used to specify which projects to include in your build. 5 | * 6 | * Detailed information about configuring a multi-project build in Gradle can be found 7 | * in the user manual at https://docs.gradle.org/7.5.1/userguide/multi_project_builds.html 8 | * This project uses @Incubating APIs which are subject to change. 9 | */ 10 | 11 | rootProject.name = "chromatophore" 12 | include("chromatophore-core") 13 | include("chromatophore-spring-boot-example") 14 | include("chromatophore-spring-boot-autoconfigure") 15 | include("chromatophore-spring-boot-starter") 16 | --------------------------------------------------------------------------------