简体   繁体   中英

All GraphQL Scalars coming up as String (Apollo)

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?

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

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