How to integrate GraphQL query in Kotlin

Viewed 206

I am struggling in understanding the way to make a POST API call to a GraphQL server through my kotlin application.

I have taken a look at various guides, like these ones: https://graphql.org/code/#java-kotlin and https://opensource.expediagroup.com/graphql-kotlin/docs/client/client-overview/ but I was not able to understand how to implement them.

First of all the initial Build Configuration is not clear to me, since every guide talks about a build.gradle.kts file that I do not have. My gradel is just "build.gradle" and I don't know the way to turn it into "build.gradle.kts". Simply adding this code:

import com.expediagroup.graphql.plugin.gradle.graphql

plugins {
    id("com.expediagroup.graphql") version $latestGraphQLKotlinVersion
}

dependencies {
  implementation("com.expediagroup:graphql-kotlin-spring-client:$latestGraphQLKotlinVersion")
}

graphql {
    client {
        endpoint = "http://localhost:8080/graphql"
        packageName = "com.example.generated"
    }
}

returns me the error: build file 'C:\Users\claud\AndroidStudioProjects\ShareValley\app\build.gradle': 1: unable to resolve class com.expediagroup.graphql.plugin.gradle.graphql @ line 1, column 1. import com.expediagroup.graphql.plugin.gradle.graphql

In addition, I am used to call APIs through the volley package in kotlin. Is there a way to call a GraphQL API using it?

Is there anyone able to provide me a working example or at least explain to me how this build.gradle.kts works?

Many thanks in advance.

0 Answers
Related