aPureBase / KGraphQL

Pure Kotlin GraphQL implementation
https://kgraphql.io
MIT License
301 stars 58 forks source link

Configurations are not properly propagated to the schema in the Ktor feature #136

Closed zypus closed 3 years ago

zypus commented 3 years ago

https://github.com/aPureBase/KGraphQL/blob/cc1db9b9a3559fe0e808b600aa44e01bfa64c6ab/kgraphql-ktor/src/main/kotlin/com/apurebase/kgraphql/KtorFeature.kt#L48-L53

Line 51 is actually a NOOP. It basically repeat line 49. However, what the line is supposed to do is to set the schemas config.

This bug surfaced when I tried to change the executor in the feature config, but still the Parallel executor was used:

    install(GraphQL) {

        executor = Executor.DataLoaderPrepared

        // other config
    }

In my local clone of the GraphQL feature, I now work around this issue like so:

       override fun install(pipeline: Application, configure: Configuration.() -> Unit): GraphQL {
            val config = Configuration().apply(configure)
            val schema = KGraphQL.schema {
                this.configure {
                    useDefaultPrettyPrinter = config.useDefaultPrettyPrinter
                    useCachingDocumentParser = config.useCachingDocumentParser
                    objectMapper = config.objectMapper
                    documentParserCacheMaximumSize = config.documentParserCacheMaximumSize
                    acceptSingleValueAsArray = config.acceptSingleValueAsArray
                    coroutineDispatcher = config.coroutineDispatcher
                    wrapErrors = config.wrapErrors
                    executor = config.executor
                    timeout = config.timeout
                }
                config.schemaBlock(this)
            }

           // remaining code unchanged
      }

I have to copy over the fields manually, because the configuration is of course private in the SchemaBuilder.

jeggy commented 3 years ago

Hi, thanks for reporting this. This has been fixed now and is available in version 0.17.3 https://github.com/aPureBase/KGraphQL/blob/2a1646acb6992e25aa0fb3f5cb6549c8e749297b/kgraphql-ktor/src/test/kotlin/com/apurebase/kgraphql/KtorConfigurationTest.kt#L22-L33

zypus commented 3 years ago

Awesome, thanks for the quick reaction.