3
votes

I am using Apollo client for GraphQL client integrations. I have added the following run script, which is suggested in the official documentation.

cd "${SRCROOT}/${TARGET_NAME}/GraphQL/Open"
$APOLLO_FRAMEWORK_PATH/check-and-run-apollo-codegen.sh generate $(find 
. -name '*.graphql') --schema schema.json 
 --output APIClient.swift

But the problem that is coming up is all the scalar are right now coming up as String.

For Example:- while logging in if I create a mutation of email and password, my schema returns response as JSON while APIClient created shows response as String(instead of JSON).

Due to this there is an error received which says

Apollo.GraphQLResultError(path: ["login", "response"], underlying: Apollo.JSONDecodingError.couldNotConvert

this is because String is received instead of JSON and string can not be converted into required JSON.

Is anyone facing the same issue?

1

1 Answers

5
votes

So I had figured it out. The solution is to add

--passthrough-custom-scalars

in the run script. This will pass custom scalars like JSON. So the complete runscript becomes

cd "${SRCROOT}/${TARGET_NAME}/GraphQL/Open"
$APOLLO_FRAMEWORK_PATH/check-and-run-apollo-codegen.sh generate $(find 
. -name '*.graphql') --schema schema.json --passthrough-custom-scalars 
--output APIOpen.swift

Now when the code is recomplied along with this run script the JSON scalar becomes valid.

This took me a lot of time to figure out. Hope it helps someone and save their time. Thanks