Apollo-android: Unsupported token `[`

Created on 1 Feb 2020  路  5Comments  路  Source: apollographql/apollo-android

Hello!

I got an error from my auto generated schema.json.graphql from the code below:

type Chat { room: [Room!]! }

error message:

Failed to parse GraphQL file \schema.json.graphql (9:10)

Unsupported token [


Most helpful comment

@littlecienbak you can if you tweak CompilerParams.schemaFile and CompilerParams.graphqlSourceDirectorySet. See https://github.com/apollographql/apollo-android/blob/master/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo/gradle/api/CompilerParams.kt#L132

It's a more complex use case but you should be able to do something like:

apollo {
    schemaFile = file("src/main/graphql/com/example/schema.json.graphql")
    graphqlSourceDirectorySet.srcDir("src/main/graphql")
    graphqlSourceDirectorySet.exclude("**/schema.json.graphql")
}

It may vary depending your configuration so don't take that as gospel.

All 5 comments

I thought I got an answer at issue #1909. I copied the query from the playground, still got this error.

Can you remove the '.graphql' extension from your schema file ?

The plugin expects a schema.json and some .graphql query files. It looks like it's trying to compile your schema.json.graphql as a query file which isn't going to work

Thanks, It works. But can I still have the schema.json.graphql in my directory without getting error? It kinda help me a lot.

@littlecienbak you can if you tweak CompilerParams.schemaFile and CompilerParams.graphqlSourceDirectorySet. See https://github.com/apollographql/apollo-android/blob/master/apollo-gradle-plugin/src/main/kotlin/com/apollographql/apollo/gradle/api/CompilerParams.kt#L132

It's a more complex use case but you should be able to do something like:

apollo {
    schemaFile = file("src/main/graphql/com/example/schema.json.graphql")
    graphqlSourceDirectorySet.srcDir("src/main/graphql")
    graphqlSourceDirectorySet.exclude("**/schema.json.graphql")
}

It may vary depending your configuration so don't take that as gospel.

Was this page helpful?
0 / 5 - 0 ratings