https://kotlinlang.org logo
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
graphql-kotlin
  • a

    am414

    01/17/2021, 10:18 AM
    hello everyone for android users I'm starting to use Apollo (instead of Retrofit )to make requests from graphql Api, I'm new to this style so i have some questions if someone experienced this before  i already made the first call, and i realised that the data model generated at compile time and its not open to modify or extend it, how i can modify it, for example i need to make data model for Room database and that model is the same model of the model i will get from the api so what i have to do in this situation ? any help please
    m
    • 2
    • 3
  • r

    Robert

    01/30/2021, 1:44 PM
    Hey folks, tried to upgrade from "com.expediagroup:graphql-kotlin-spring-server:3.6.5" to "com.expediagroup:graphql-kotlin-spring-server:3.7.0" I don't include any other "com.expediagroup:graphql-*" dependencies Getting this error:
    > Could not resolve all files for configuration ':compileClasspath'.
       > Could not find com.apollographql.federation:federation-graphql-java-support:0.5.0.
         Required by:
             project : > com.expediagroup:graphql-kotlin-spring-server:3.7.0
             project : > com.expediagroup:graphql-kotlin-spring-server:3.7.0 > com.expediagroup:graphql-kotlin-federation:3.7.0
    d
    s
    • 3
    • 6
  • a

    András Hatvani

    02/08/2021, 8:21 AM
    Hi, where do I find an example for file upload implementation?
    d
    • 2
    • 1
  • m

    Marcus Dunn

    02/08/2021, 11:24 PM
    Hello is there a proper way to map JPA's
    FetchType.LAZY
    to a schema-exposed class? If I pass a entity to the constructor then just call the field inside the function (example below) I'll receive an error because the session is closed by the time the function is called. I have this entity class
    @Entity
    class Foo(
        @Id
        val id: Long
        @OneToOne(fetch = FetchType.LAZY)
        var bar: Bar
    )
    this class here is the one exposed to the schema, its mapped almost 1-1 with the
    Foo
    class, but with the potential to have more fields I don't necessarily want in the
    Foo
    entity.
    class GraphQlFoo(private val entity: Foo) {
        val id = entity.id
        fun bar() = GraphQLBar(entity.bar)
    }
    This setup breaks at the moment, Ideally I'd like some way to fetch
    bar
    if and only if it was requested, and not have to do unessisary joins if it the request doesn't include it. I'd also like to do all this logic in a single session, as opening a second to just fetch
    bar
    seems unneeded which is what my current solution does via
    fun bar(@GraphQLIgnore @Autowired barRepository: BarRepository) = barRepository.getByFooId(id)
    s
    • 2
    • 2
  • m

    mytrile

    02/09/2021, 5:44 PM
    can someone give me a hand, trying to boot spring boot graphql server, but right away there is an error
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'webHandler' defined in class path resource [org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfiguration$EnableWebFluxConfiguration.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'routerFunctionMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfiguration$EnableWebFluxConfiguration.class]: Invocation of init method failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.expediagroup.graphql.spring.RoutesConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.expediagroup.graphql.spring.GraphQLConfigurationProperties' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
    s
    • 2
    • 5
  • h

    hisham bin awiad

    02/13/2021, 2:50 PM
    Hi all .. i am new with Qraph QL
    android side
    , any recommended resource for start with it . i hope to find any resource with
    Retrofit
    plz share any resource with me
    m
    • 2
    • 5
  • t

    Tianyu Zhan

    02/15/2021, 4:46 PM
    How should I run gradle-client app in examples? I have errors when I run 
    gradle clean build
    d
    • 2
    • 3
  • d

    dave08

    02/17/2021, 9:15 AM
    Hi! Does the graphql client run on kotlin js? We're thinking of using it in a Kotlin React frontend.
    d
    m
    • 3
    • 19
  • a

    Anders Kirkeby

    02/17/2021, 3:08 PM
    Hey. Quick question from me surrounding “best-practices”. I have a spring boot application, and I want to add a sessionId onto each request (for simplicity let’s say i want to a unique id for each query) - what’s the intended way of doing this with contexts/directives, etc? Especially if we’re adding this unique Id onto MDC, where would you thing it natural to put the MDC.put(“session”) and MDC.remove(“session”)?
    d
    r
    • 3
    • 8
  • d

    dave08

    02/18/2021, 12:59 PM
    Hi! Any plans on adding a kapt pre-processor for the schema generator, or is there a reason that it has to be done at runtime?
    d
    • 2
    • 5
  • d

    dave08

    02/18/2021, 4:23 PM
    I got a basic setup for Micronaut up with version 4, nice job in all the abstractions! Just wondering about the subscriptions part... there wasn't anything in the Ktor example for that.
    j
    s
    • 3
    • 7
  • d

    dave08

    02/21/2021, 12:28 PM
    How do we handle DI in schemas? For queries, I'd suppose I could make it a Micronaut singleton, and inject repositories in it, but when types (data classes with functions for property resolution) need repos, it's a bit messy to inject them in each instance of a search result, or is that really the best practice here?
    d
    s
    j
    • 4
    • 8
  • d

    dave08

    02/22/2021, 3:55 PM
    Another little question: How do you handle testing the api on the producer side and mocking it for tests on the consumer side (for now also Kotlin server-side)? Any special tools for this?
    d
    s
    • 3
    • 12
  • j

    Jeremy Beard

    02/22/2021, 4:25 PM
    I have a query with a required argument that is defined by a data class which has some optional non-nullable properties (i.e. has default values), however those optional properties are generated in the schema as required. Is there a way for those data class properties to become optional in the query schema without making them nullable, so that I can leave them out of my queries?
    • 1
    • 1
  • d

    Daniel Skogquist Åborg

    02/28/2021, 11:45 AM
    Does anyone know if there's a clean way to intercept and alter the error reporting of NonNullableFieldWasNullException in graphql-java, it seems to automagically and always add a non-null error when you use exceptions to handle error conditions in data fetchers.
    s
    d
    • 3
    • 4
  • t

    Tianyu Zhan

    03/01/2021, 10:31 PM
    Does anyone know how to return Flux types in graphql? For now I called an API and got the Flux type object. I want to return that object for graphql query. But it seems not support Flux type....
    s
    d
    • 3
    • 5
  • d

    dave08

    03/07/2021, 12:45 PM
    Just wondering, any reason for not using value (or previously named inline) classes for ID? It could avoid a bunch of needless allocations...
    d
    • 2
    • 7
  • d

    Das135

    03/10/2021, 12:37 PM
    [Kotlin Client Codegen] Hello. I have issue with generating
    Enum
    that as got
    name
    property. I have got Graphql server that has got enum class properties defined in UPPERCASE and renamed with
    @GraphQLName
    (because of
    name
    property).
    enum class EnumClass {
        @GraphQLName("id")
        @JsonProperty("id")
        ID,
        @GraphQLName("name")
        @JsonProperty("name")
        NAME,
        @GraphQLName("createdAt")
        @JsonProperty("createdAt")
        CREATED_AT,
        @GraphQLName("createdById")
        @JsonProperty("createdById")
        CREATED_BY_ID,
    }
    Now I want to use this type in my graphql-kotlin-client, but generator creates this class:
    enum class EnumClass {
        createdAt,
        createdById,
        id,
        name,
        /**
         * This is a default enum value that will be used when attempting to deserialize unknown value.
         */
        @JsonEnumDefaultValue
        __UNKNOWN_VALUE
    }
    There is a problem that Kotlin Enum cannot has got a
    name
    property. Please, it is possible to somehow solve it? Thank you
    d
    s
    • 3
    • 4
  • n

    Nikky

    03/15/2021, 10:49 AM
    i saw there was some progress with code generation for kotlinx-serialization how far along is the cgenerated client code for multiplatform (js) with ktor ?
    d
    • 2
    • 6
  • r

    Robert

    03/20/2021, 7:40 AM
    Regarding nested or sub-queries, is there some best practice? Given the following example: • there is a query for A • there is a query for B • B is a property of A and can be resolved if requested • This is how it looks from the interface level
    import com.expediagroup.graphql.annotations.GraphQLDescription
    import com.expediagroup.graphql.spring.operations.Query
    import org.springframework.stereotype.Component
    
    @Component
    interface QueryB : Query, SubQuery {
        @GraphQLDescription("Get B")
        suspend fun queryB(): B
    
        // corresponds to the field name in parent model (e.g. A.b)
        override val fieldName: String
            get() = "b"
    }
    
    @Component
    interface QueryA : Query {
        @GraphQLDescription("Get A")
        suspend fun queryA(): A
    }
    
    data class A(
        val aValue: String,
        val b: B? // corresponds with field name
    )
    
    data class B(
        val bValue: String,
    
    )
    
    interface SubQuery {
        /**
         * Name when used in parent model
         */
        val fieldName: String
    }
    To implement the resolver for A (including B) it's needed to: • Inject resolver for B into A • Execute some custom logic to see if the query for A also requested field B This kina works, but is a bit cumbersome and works against the benefits of graphql magic resolving what is needed:
    class QueryAImpl(private val queryB: QueryB) : QueryA {
        override suspend fun queryA(): A {
            val aValue = A("A")
            val `was b requested as part of a?` = true
            return if (`was b requested as part of a?`) {
                aValue.copy(b = queryB.queryB())
            } else aValue
        }
    }
    I think the DataLoader approach could help here, or? https://github.com/ExpediaGroup/graphql-kotlin/blob/master/examples/server/spring-[…]graphql/examples/server/spring/dataloaders/CompanyDataLoader.kt
    d
    • 2
    • 5
  • r

    Robert

    03/20/2021, 10:13 AM
    Did something in 4.0.0-alpha.15 change (vs. 3.7.0) in regards to resolving nullable query/mutation parameter?
    @GraphQLDescription("performs some operation")
        fun doSomething(
            @GraphQLDescription("super important value")
            value: Int?
        ): Boolean = true
    this works ✅
    query {
      doSomething(value:null) {
        ..
      }
    }
    this fails in 4.0.0-alpha.15 ❗ :
    no argument provided for a required parameter: parameter #1 query of fun SomeQuery.doSomething(<http://kotlin.Int?|kotlin.Int?>)
    and works with 3.7.0
    query {
      doSomething {
        ..
      }
    }
    it works again when using a default
    @GraphQLDescription("performs some operation")
        fun doSomething(
            @GraphQLDescription("super important value")
            value: Int? = null
        ): Boolean = true
    d
    s
    • 3
    • 11
  • j

    Jabez Magomere

    03/23/2021, 11:07 AM
    I’m trying to return a class that extends graphql-relay Connection class in a Query function as shown in the snippet below.
    import com.androidmaestro.users.data.repository.UserRepository
    import com.androidmaestro.users.domain.entity.UserEntity
    import com.expediagroup.graphql.types.operations.Query
    import graphql.relay.*
    
    
    class UsersQuery(private val repository: UserRepository) : Query{
        suspend fun users(first:Int, cursor : String?) : UsersConnection = repository.getAll(first, cursor)
    }
    
    class UsersConnection(users:List<Edge<UserEntity>>, userPageInfo : DefaultPageInfo) : DefaultConnection<UserEntity>(users, userPageInfo)
    However the schema generation fails with the error shown below.
    Caused by: java.lang.IllegalArgumentException: Class declares 1 type parameters, but 0 were provided.
            at kotlin.reflect.full.KClassifiers.createType(KClassifiers.kt:53)
            at kotlin.reflect.full.KClassifiers.createType$default(KClassifiers.kt:45)
            at com.expediagroup.graphql.generator.internal.types.GenerateObjectKt.generateObject(generateObject.kt:46)
            at com.expediagroup.graphql.generator.internal.types.GenerateGraphQLTypeKt.getGraphQLType(generateGraphQLType.kt:74)
            at com.expediagroup.graphql.generator.internal.types.GenerateGraphQLTypeKt.access$getGraphQLType(generateGraphQLType.kt:1)
            at com.expediagroup.graphql.generator.internal.types.GenerateGraphQLTypeKt$objectFromReflection$1.invoke(generateGraphQLType.kt:63)
            at com.expediagroup.graphql.generator.internal.types.GenerateGraphQLTypeKt$objectFromReflection$1.invoke(generateGraphQLType.kt)
            at com.expediagroup.graphql.generator.internal.state.TypesCache.buildIfNotUnderConstruction$graphql_kotlin_schema_generator(TypesCache.kt:108)
            at com.expediagroup.graphql.generator.internal.types.GenerateGraphQLTypeKt.objectFromReflection(generateGraphQLType.kt:62)
            at com.expediagroup.graphql.generator.internal.types.GenerateGraphQLTypeKt.generateGraphQLType(generateGraphQLType.kt:40)
            at com.expediagroup.graphql.generator.internal.types.GenerateGraphQLTypeKt.generateGraphQLType$default(generateGraphQLType.kt:36)
            at com.expediagroup.graphql.generator.internal.types.GenerateFunctionKt.generateFunction(generateFunction.kt:54)
            at com.expediagroup.graphql.generator.internal.types.GenerateFunctionKt.generateFunction$default(generateFunction.kt:33)
            at com.expediagroup.graphql.generator.internal.types.GenerateQueryKt.generateQueries(generateQuery.kt:43)
            at com.expediagroup.graphql.generator.SchemaGenerator.generateSchema(SchemaGenerator.kt:80)
            at com.expediagroup.graphql.generator.SchemaGenerator.generateSchema$default(SchemaGenerator.kt:73)
            at com.expediagroup.graphql.generator.ToSchemaKt.toSchema(toSchema.kt:41)
            at com.expediagroup.graphql.generator.ToSchemaKt.toSchema$default(toSchema.kt:37)
            at com.androidmaestro.graphql.Schema.<clinit>(Schema.kt:51)
            ... 76 common frames omitted
    2021-03-23 14:01:21.087 [eventLoopGroupProxy-4-1] ERROR Application - Unhandled exception
    java.lang.NoClassDefFoundError: Could not initialize class com.androidmaestro.graphql.Schema
    s
    f
    • 3
    • 9
  • b

    Brian Dilley

    03/25/2021, 8:49 PM
    hey guys, how do you handle a one to many situation. ie:
    data class Movie(
        val id: Long,
        val token: String
    )
    
    data class User(
        val id: Long,
        val name: String
    ) {
    
        fun movies(userIds: List<Long>): List<Movie> {
            return LongRange(0, 2)
                .map { Movie(it, "movie-$it") }
                .toList()
        }
    }
    
    @Component
    class UserQueries : Query {
    
        fun users(): List<User> {
            return LongRange(0, 5)
                .map { User(it, "user-$it") }
                .toList()
        }
    }
    In a database situation it would be really bad to query users along with their movies because it would issue a single query per user to get their movies. Is there a way to avoid the multiple queries and instead get a list of the user ids and make a single query for all of their movies?
    s
    d
    • 3
    • 7
  • b

    Brian Dilley

    03/26/2021, 6:46 AM
    Is there a way in graphql-kotlin to handle exceptions and change their message and/or the response? I’ve got spring security setup with method level security working with
    @Secured
    and it throws an exception (
    AuthenticationCredentialsNotFoundException
    ) when expected, but how do i define an “error resolver” that can take that exception and turn it into a more meaningful message (ie: right now it’s
    An Authentication object was not found in the SecurityContext
    for that exception, i’d rather say something like
    Access Denied
    )
    r
    d
    • 3
    • 3
  • m

    Marcus Dunn

    03/29/2021, 6:15 PM
    the following constantly throws a ClassCastException
    class java.util.LinkedHashMap cannot be cast to class com.expediagroup.graphql.examples.server.spring.query.ScalarQuery$PhoneNumber
    fun convolutedExample(optListInput: OptionalInput<List<PhoneNumber>>): String {
            return patient
                .let { if (it is OptionalInput.Defined) it.value else null }
                ?.map { it.number }
                .toString()
        }
    
        data class PhoneNumber(val number: Long)
    when called like this
    @Test
    fun test() {
        val query = "convolutedExample"
        val expectedData = "[111111]"
    
        <http://testClient.post|testClient.post>()
            .uri(GRAPHQL_ENDPOINT)
            .accept(APPLICATION_JSON)
            .contentType(GRAPHQL_MEDIA_TYPE)
            .bodyValue("""query { $query(optListInput: [{
                |   number: 111111,
                |   }]
                |) }""".trimMargin())
            .exchange()
            .verifyData(query, expectedData)
    }
    Have I gone wrong somewhere or is this just too many generics deep for jackson to figure out?
    d
    • 2
    • 8
  • d

    Dariusz Kuc

    04/07/2021, 7:08 PM
    Hello 👋 We just released
    4.0.0-rc.1
    would greatly appreciate it if you could try it out and report any issues.
    :kotlin-intensifies: 1
    👍 3
    🎉 2
    s
    j
    • 3
    • 6
  • j

    Joe

    04/07/2021, 10:44 PM
    Noticing a couple things with `FlowSubscriptionExecutionStrategy`: 1. it now returns a
    Publisher
    now instead of a
    Flow
    . This makes sense for spring webflux, but we're consuming `Flow`s directly and the
    Flow
    ->`Publisher`->`Flow` round trip has caused resource leak problems for us in the past. Would something like a
    NativeFlowSubscriptionExecutionStrategy
    that returns `Flow`s be welcome in
    graphql-kotlin
    or should we maintain it externally? 2. instrumentation doesn't appear to be applied to subscription results. Previously fixed in https://github.com/ExpediaGroup/graphql-kotlin/pull/742 but maybe in going to
    Publisher
    lost that? (or maybe something's changed in graphql-java 16 around it?) other than that, updating package import definitions and some renames in graphql-java 16 (ExecutionPath -> ResultPath) appear to be the main changes that we need to adjust for. There's also some weirdness with the selectionSet duplicating fields that appears to be filed upstream as https://github.com/graphql-java/graphql-java/issues/2275.
    d
    • 2
    • 12
  • j

    Jilles van Gurp

    04/08/2021, 2:04 PM
    I stumbled upon a hack for using scalars with a sealed class for a geojson geometry. You can find our Geometry sealed class here (oss, feedback welcome): https://github.com/jillesvangurp/geogeometry/blob/3.1.19/src/commonMain/kotlin/com/jillesvangurp/geojson/geojson.kt I used a schema hook (code below) to register a scalar for this. So we simply return objects with a geometry field and it actually serializes correctly. The hack here is that I let the Geometry object coerce to it self. After that, toString gets called apparently. If you check the linked implementation above, I simply implemented that using kotlinx.serialization so it serializes to json. Two questions and a couple of suggestions: 1) is this something I should rely on to continue to work or is this something that can be done differently? One of my issues here is that the coordinates field in a geometry is shaped differently between the different classes. So I need to do something custom here. This bypasses the whole logic. In my query I simply ask for a Geometry and get back a json object, which parses fine. 2) it strikes me that this is a nice way to add scalars and something that potentially also works for parameters even though graphql currently does not support union types or interfaces there. As you can see, I did not implement the parse methods yet but looks like it could be doable. Which of the parse functions actually gets called? There appear to be several. And a suggestions: • Maybe add the
    @Component
    to the example for custom scalars. Without that, it doesn't work for obvious reasons. • The documentation suggests this should only work with things like strings, which seems to be not the case • Maybe generalize the approach below to have kotlinx.serialization and maybe jackson strategies for coercion. Mostly that should work and users can simply reuse their existing serialization/deserialization logic that way. Or if that is supported some other way, maybe document that?
    @Component
    class GeometryGraphqlScalar : SchemaGeneratorHooks {
        override fun willGenerateGraphQLType(type: KType): GraphQLType? {
            return when (type.classifier as? KClass<*>) {
                Geometry::class -> geometryScalar
                else -> null
            }
        }
    }
    
    private val geometryScalar = GraphQLScalarType
        .newScalar()
        .name("Geometry")
        .description("json serialized geometry")
        .coercing(GeometryCoercing)
        .build()
    
    object GeometryCoercing : Coercing<Geometry, Geometry?> {
        override fun serialize(input: Any): Geometry {
            // little hack, causes toString to be called, which we implemented using Json.encodeToString ...
            return  input as Geometry
        }
    
        override fun parseValue(input: Any): Geometry {
            error("we don't support parameter scalars currently but we could ${input::class.qualifiedName}")
        }
    
        override fun parseLiteral(input: Any): Geometry {
            error("we don't support parameter scalars currently but we could ${input::class.qualifiedName}")
        }
    }
    d
    • 2
    • 13
  • d

    Dariusz Kuc

    04/20/2021, 2:15 PM
    https://kotlinlang.slack.com/archives/C0BJ0GTE2/p1618928099280200
    🐿 1
    🎉 8
    a
    • 2
    • 1
  • a

    andylamax

    04/25/2021, 10:22 AM
    Is there a kotlin multiplatform client implementation? that targets android, ios and js as well?
    d
    • 2
    • 4
Powered by Linen
Title
a

andylamax

04/25/2021, 10:22 AM
Is there a kotlin multiplatform client implementation? that targets android, ios and js as well?
d

Dariusz Kuc

04/25/2021, 1:23 PM
While we dont publish aar artifact, generated sources using kotlinx-serialization and graphql-kotlin-ktor-client should be easily usable from android
I believe #apollo-android is targeting multiplatform
a

andylamax

04/25/2021, 3:59 PM
Thanks for your response
I have seen a couple of android solutions already, however the ones I have seen do not have a kotlin/js support. Is there a client that simultaneously target android, ios and js?
👀 1
:ktor: 1
View count: 20