https://kotlinlang.org logo
#kgraphql
Title
# kgraphql
m

Mattlangsenkamp

09/14/2020, 2:23 AM
is there a way to split up a schema into multiple files to keep it more readable?
1
j

jeggy

09/14/2020, 8:14 AM
Yes, I personally like the pattern that you would usually use with ktor routes. You can just create a function anywhere you want like this
Copy code
fun SchemaBuilder.user() {
  query("users") {
    ...
  }
}
And then you can call this function within your main schema
m

Mattlangsenkamp

09/14/2020, 2:37 PM
awesome
is there a spot for this in the DOcs? I cant seem to find it?
j

jeggy

09/14/2020, 5:03 PM
No, currently there is not. I'm noting it down, I will add some examples to the docs some time soon. But you can see a simple example of this within our example project here: https://github.com/aPureBase/KGraphQL/blob/master/kgraphql-example/src/main/kotlin/com/apurebase/kgraphql/Application.kt#L38 Where the
ufoSchema
function is defined here: https://github.com/aPureBase/KGraphQL/blob/master/kgraphql-example/src/main/kotlin/com/apurebase/kgraphql/GraphQLSchema.kt
Currently in that example there is only one, but you can of course grow this list with multiple files and just make sure to call that function somewhere within the
SchemaBuilder
context
4 Views