kadirahq / lokka

Simple JavaScript Client for GraphQL
MIT License
1.53k stars 61 forks source link

json mutations not working as expected? #43

Open MarkLyck opened 7 years ago

MarkLyck commented 7 years ago

I have no problems with json mutations using react-apollo. But trying to use lokka no matter what I try I get the following error:

Error: GraphQL Error: Argument 'prices' expected type 'Json' but got: [object, Object]. Reason: Not valid JSON (line 5, column 28):
            prices: [object Object]

Here's the code:

const test = {
    test: 'value'
}

client.mutate(`{
        market: updateMarket(
            id: "cj60pwi9v6rh201942t6fq6h7",
            name: "TEST update5",
            prices: ${test}
        ) {
            name
        }
    }`)
        .then((response) => {
            console.log(`RESPONSE: ${JSON.stringify(response)}`)
        })
        .catch(e => console.log(e))

I've tried to stringify it. import it from an actual .json file, stringify then parse it. Putting quotes around it, various types of json data, including arrays. Putting it directly in the `` instead of using a variable.

If I put in e.g. [2] it will say ...but got: [2] instead of [object object] but if I try anything that isn't an array, it will say [object object] (which isn't even what I'm trying to pass)...

I've tried to change the type to an integer and string on graph.cool and changing the variable to a matching type and it works completely fine. It will also change the name just fine if I remove the line with prices.

But I cannot get lokka to update any json... What am I missing here?