apollo-ios: Generate Apollo GraphQL API phase not executing properly

I am having trouble getting the build phase execute prperly. I have properly created the build script and using default paths for my *.graphql and schema.json. It looks like Xcode is running the generation phase but no API.swift file is generated.

Any directions on how to debug this?

Using Apollo 0.3.1 and apollo-codegen 0.8.2

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 48 (17 by maintainers)

Most upvoted comments

I experienced multiple errors while attempting to get the auto generation working. Including the following:

  1. An already open current issue involving whitespace #33
  • Removing all whitespace in names from my targets, schemas, and build configurations, followed by re-running pod install, and cleaning resolved this.
  1. Afterwards, I received an error saying that Apollo.framework does not support the latest version of apollo-codegen.
  • I had to downgrade the apollo-codegen version installed on my machine to 0.18.8 from the current latest of 0.19.1.
  1. Finally afterwards, I got the error which brought me to this thread:
TypeError: Cannot read property 'length' of undefined
    at Object.yargs.command.command.command.argv [as handler] (/usr/local/lib/node_modules/apollo-codegen/src/cli.js:186:17)
    at Object.runCommand (/usr/local/lib/node_modules/apollo- codegen/node_modules/yargs/lib/command.js:235:44)
    at Object.parseArgs [as _parseArgs] (/usr/local/lib/node_modules/apollo-codegen/node_modules/yargs/yargs.js:1013:30)
    at Object.get [as argv] (/usr/local/lib/node_modules/apollo-codegen/node_modules/yargs/yargs.js:957:21)
    at Object.<anonymous> (/usr/local/lib/node_modules/apollo-codegen/lib/cli.js:197:5)
    at Module._compile (module.js:660:30)
    at Object.Module._extensions..js (module.js:671:10)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
Command /bin/sh failed with exit code 1

@shelldonhu’s suggested fix of adding a .graphql file fixed it for me. Something in the generation script doesn’t fail gracefully or the documentation is possibly out of order (it says to verify API.swift is generated before saying to add a .graphql file).

Hope this helps someone.

It can be built successfully when I firstly create an empty .graphql file on ${SRCROOT}/${TARGET_NAME}.

@NiltiakSivad, thank you! I spent lot of time to find the issue! And finally, I came across with @NiltiakSivad answer. Apollo team should warn their audience about such possible case in installation tutorial!

@jzhw0130: I still don’t know what causes that for some people, but now that I think of it, we may have a workaround in recent versions of apollo-codegen.

Could you try replacing the last line of the build script with:

$APOLLO_FRAMEWORK_PATH/check-and-run-apollo-codegen.sh generate '**/*.graphql' --schema schema.json --output API.swift