简体   繁体   中英

Apollo graphQL unsupported token in input

I am using Apollo Android GraphQL (Gradle plug-in version 1.2.1) to post data to a server. I have downloaded the schema.json file from the server and written a.graphql file with a mutation. To pass objects from the App I defined some input objects as follows.

input Location {
    lat: Float!
    lon: Float!
}

input SensorParams {
    sources: [Int]
    exposition: Float
    location: Location!
}

mutation InsertSessionResults(
    $location: Location!) {
    insertSession(session: {
        name: $name
    }) {
        id
    }
}

However when I build the App, I get the following error: Failed to parse GraphQL file. Unsupported token '!'

If I remove the ',' from Location. the process gives the same error for the '[' char.

Reading the doc I understand that both characters are allowed in input definition to request a non-null value and to set a list type respectively, so what may cause the error?

There is no need to write type definitions in your front end, just write the query as a string. The input types are defined in the schema on the server.

As @Xizam has already answered above, you don't need that file you are writing in the android front-end. Delete it in fact. As long as you have the schema and the YourQueries.graphql file (containing the queries and mutation you've decided to make in the app), build the project and it'll run fine.

Android studio will then recognize your mutations when declaring them in the activity class.

follow this simple tutorial: here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM