# Is it possible to change the default schema directory in Apollo Kotlin

**URL:** <https://community.apollographql.com/t/is-it-possible-to-change-the-default-schema-directory-in-apollo-kotlin/6618>\
**Category:** Client SDKs\
**Tags:** client, kotlin\
**Created:** [August 18, 2023, 11:24am UTC](https://community.apollographql.com/t/is-it-possible-to-change-the-default-schema-directory-in-apollo-kotlin/6618 "2023-08-18T11:24:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![vinodjayachandran](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/vinodjayachandran/32/4508_2.png) [@vinodjayachandran](https://community.apollographql.com/u/vinodjayachandran)\
**Post date:** [August 18, 2023, 11:24am UTC](https://community.apollographql.com/t/is-it-possible-to-change-the-default-schema-directory-in-apollo-kotlin/6618/1 "2023-08-18T11:24:34Z")

</div>

I am trying to use Apollo Kotlin as GraphQL client for GraphQL queries.  
Apollo Kotlin requires a schema in your module’s `src/main/graphql` directory.  
All our Schemas are present in a separate git repo (say MyGraphQLSchema). To avoid duplication can apollo-kotlin read schemas from a different location or package ?

---

<div class="post-metadata">

**Author:** ![mbonnin](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/mbonnin/32/13_2.png) [@mbonnin](https://community.apollographql.com/u/mbonnin)\
**Post date:** [August 18, 2023, 11:40am UTC](https://community.apollographql.com/t/is-it-possible-to-change-the-default-schema-directory-in-apollo-kotlin/6618/2 "2023-08-18T11:40:12Z")

</div>

Hi 👋

You can use [schemaFile](https://www.apollographql.com/docs/kotlin/advanced/plugin-configuration#specifying-the-schema-location) for this.

```kotlin
apollo {
  service("service") {
    schemaFile.set(file("shared/graphql/schema.graphqls"))
  }
}

```

---

<div class="post-metadata">

**Author:** ![vinodjayachandran](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/vinodjayachandran/32/4508_2.png) [@vinodjayachandran](https://community.apollographql.com/u/vinodjayachandran)\
**Post date:** [August 18, 2023, 6:24pm UTC](https://community.apollographql.com/t/is-it-possible-to-change-the-default-schema-directory-in-apollo-kotlin/6618/3 "2023-08-18T18:24:59Z")

</div>

> [@vinodjayachandran](#):
>
> I am trying to use Apollo Kotlin as GraphQL client for GraphQL queries.  
> Apollo Kotlin requires a schema in your module’s `src/main/graphql` directory.  
> All our Schemas are present in a separate git repo (say MyGraphQLSchema). To avoid duplication can apollo-kotlin read schemas from a different location or package ?

Thank you so much. it is indeed helpful. I have 2 follow up questions.

1. Is it possible to give a directory to specify a set of Schema files (instead specifying each file individually). I tried [schemaFiles.setFrom](https://www.apollographql.com/docs/kotlin/advanced/plugin-configuration/#combining-multiple-schema-files), but when i give a directory , gradle build fails with error `> java.io.FileNotFoundException: /{My_Directory_Path}/ (Is a directory)`

2. Is there a similar way to specify operations ([.graphql files](https://www.apollographql.com/docs/kotlin/essentials/file-types/#operations-graphql)) too from a different directory. Currently I add .graphql files only to the default directory `src/main/graphql`

---

<div class="post-metadata">

**Author:** ![mbonnin](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/mbonnin/32/13_2.png) [@mbonnin](https://community.apollographql.com/u/mbonnin)\
**Post date:** [August 18, 2023, 6:42pm UTC](https://community.apollographql.com/t/is-it-possible-to-change-the-default-schema-directory-in-apollo-kotlin/6618/4 "2023-08-18T18:42:57Z")

</div>

For 1. I’m pretty sure there is some Gradle APIs to locate all given files inside a folder like [fileTree](https://docs.gradle.org/current/userguide/working_with_files.html#sec:file_trees):

```kotlin
apollo {
  service("service") {
    packageName.set("com.example")
    schemaFiles.from(fileTree("/").apply { include("**/*.graphqls") })
  }
}

```

For 2., you can use [srcDir](https://www.apollographql.com/docs/kotlin/advanced/plugin-configuration#using-multiple-graphql-apis):

```kotlin
apollo {
  service("service") {
    packageName.set("com.example")
    srcDir(file("path/to/your/directory"))
  }
}

```

All that being said, note that it’s quite unusual to have multiple schema files for a single service. Usually there is a 1:1 mapping between a service and a schema file. And if your schema files are next to your operation files, you can just use `srcDir` and the Gradle plugin will locate the schema from their `.graphqls` extension

---

<div class="post-metadata">

**Author:** ![vinodjayachandran](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/vinodjayachandran/32/4508_2.png) [@vinodjayachandran](https://community.apollographql.com/u/vinodjayachandran)\
**Post date:** [August 24, 2023, 10:38am UTC](https://community.apollographql.com/t/is-it-possible-to-change-the-default-schema-directory-in-apollo-kotlin/6618/5 "2023-08-24T10:38:43Z")

</div>

This helped and solved my requirement. Thank you so much for the prompt and accurate answer.

---

<div class="post-metadata">

**Author:** ![Justin\_Gonzalez](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/justin_gonzalez/32/5359_2.png) [@Justin\_Gonzalez](https://community.apollographql.com/u/Justin_Gonzalez)\
**Post date:** [February 6, 2025, 8:48pm UTC](https://community.apollographql.com/t/is-it-possible-to-change-the-default-schema-directory-in-apollo-kotlin/6618/6 "2025-02-06T20:48:29Z")

</div>

Archived on February 6, 2025, 8:48pm UTC


