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
Could you have a look at the command arguments in the build output (see screen shot)?

@martijnwalraven it only displays +exec apollo-codegen ...weird. Any ideas why is this happening?
@attheodo: It seems like check-and-run-apollo-codegen.sh somehow isn't picking up the rest of the arguments. Are you sure this is the last line of the build script:
$APOLLO_FRAMEWORK_PATH/check-and-run-apollo-codegen.sh generate $(find . -name '*.graphql') --schema schema.json --output API.swift
This is exactly what's inside the script:
APOLLO_FRAMEWORK_PATH="$(eval find $FRAMEWORK_SEARCH_PATHS -name "Apollo.framework" -maxdepth 1)"
if [ -z "$APOLLO_FRAMEWORK_PATH" ]; then
echo "error: Couldn't find Apollo.framework in FRAMEWORK_SEARCH_PATHS; make sure to add the framework to your project."
exit 1
fi
cd "${SRCROOT}/${TARGET_NAME}"
$APOLLO_FRAMEWORK_PATH/check-and-run-apollo-codegen.sh generate $(find . -name '*.graphql') --schema schema.json --output API.swift
Not sure what could be going on here then. So the command output is just +exec apollo-codegen, without generate or any of the other arguments?
Exactly


Anything special about the name of the directory the project or the target is in maybe? I'm just guessing now, no idea why that would cause this behavior.
@martijnwalraven not really
$ pwd
/Users/thanosth/Documents/dev/waldo/WaldoMini/WaldoMini
By deleting and re-adding the script I somehow arbitrarily got it to work. It compained about not finding schema. But then, subsequent builds was just not spitting any errors, still ignoring the rest of the arguments.
Does that tell you anything?
@attheodo: Have you been able to get this to work, or do you still experience the same issue? Really no idea what could be causing this.
Not really. For now I just extracted the apollo-codegen part into a shell script and run it manually whenever I want to generate the files.
Really frustrating
Get Outlook for iOS
On Wed, Dec 14, 2016 at 11:11 AM +0200, "Martijn Walraven" notifications@github.com wrote:
@attheodo: Have you been able to get this to work, or do you still experience the same issue? Really no idea what could be causing this.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
@attheodo: I'm sorry to hear that. You mentioned you did get it to work at some point. Is there any way you can retrace your steps and find out what changed?
@martijnwalraven I still have the same issues in a different project. Any help on how I could debug this?
Hmmm, I'm just as confused as before. Are you running the latest versions? Do you still get +exec apollo-codegen without any arguments?
@martijnwalraven yes I am on the latest versions. Actually I am getting ++exec apollo-codegen (with an extra + in the beginning)
No idea what the difference is, but I'm also getting xx now:

Are you running a custom shell environment or Bash version?
@martijnwalraven I am running zsh with oh-my-zsh on my terminal. I am not sure whether this is an issue though since on the "Build Phase" the script is directed to use /bin/sh as the shell.
Yeah, that shouldn't be an issue. I'm also running zsh with oh-my-zsh.
I don't really know how to debug this. Shell scripts aren't one of my strongest points :)
Have you had a look at check-and-run-apollo-codegen.sh to see if anything jumps out to you?
@attheodo @martijnwalraven
I'm getting the same problem?
Is there any way to solve the problem?
Thanks a lot.
Jing
@jzhw0130: Are you sure it's the same problem? What do the command arguments in the build output look like for you (see above)?
@martijnwalraven
Sure
Only says :
++ exec apollo-codegen
No arguments
Jing
@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
@martijnwalraven
Hi
Also get the same result.
Script as :
APOLLO_FRAMEWORK_PATH=$(eval find $FRAMEWORK_SEARCH_PATHS -name "Apollo.framework" -maxdepth 1)
if [ -z "$APOLLO_FRAMEWORK_PATH" ]; then
echo "error: Couldn't find Apollo.framework in FRAMEWORK_SEARCH_PATHS; make sure to add the framework to your project."
exit 1
fi
cd ${SRCROOT}/Tests/StarWarsAPI
$APOLLO_FRAMEWORK_PATH/check-and-run-apollo-codegen.sh generate '*/.graphql' --schema schema.json --output API.swift
Jing
@jzhw0130: Why does it say cd ${SRCROOT}/Tests/StarWarsAPI? That doesn't seem right, because you probably don't want to generate files for the test queries. You probably want to replace this with cd "${SRCROOT}/${TARGET_NAME}".
@martijnwalraven
Yes I just do a test with the test queries. If it does work, I will do my query.
But now, demo does not work.
@martijnwalraven

@jzhw0130: I have no idea how to debug this, because I can't reproduce it and I've only heard it happen with you and @attheodo so far. Is there anything about your setup that might explain this? OS X version, the shell you use, how you installed Node?
@martijnwalraven
Thanks for your patience.
OS: mac os 10.11.6
Node: v7.10.0
shell: bash
apollo-codegen --version: 0.10.13
npm -v : 4.2.0
Just download the frontage demo from : https://github.com/apollographql/frontpage-ios-app
Then nothing change, just build to get the API.swift.
Jing
@martijnwalraven
As @attheodo said, I have to do the process of 'apollo-codegen' on the Terminal as follows:
apollo-codegen generate *.graphql *.graphql --schema schema.json --output API.swift
Although it is a little trouble, but it works.
Jing
@jzhw0130: I'd really like to understand what is going on. But I just tried it again, cloning a fresh copy of frontpage-ios-app and reinstalling apollo-codegen 0.10.3 from npm, and everything seems to work for me.
For some reason, the arguments passed to $APOLLO_FRAMEWORK_PATH/check-and-run-apollo-codegen.sh are not passed on to apollo-codegen in certain environments. We execute it with exec apollo-codegen "$@", which seems pretty standard, so I don't know why that doesn't work in your case.
Sorry
I'm not familiar with shell script, can not get the problem...
@martijnwalraven
One more detail:
check-and-run-apollo-codegen.sh change as:
Print commands before executing them (useful for troubleshooting)
set -x
echo $0
echo $1
echo $@
echo $*
Result:
Showing All Messages
Showing All Messages
++ echo /Users/jing/Library/Developer/Xcode/DerivedData/FrontPage-bmlzfqrnzbhvyqacptgxyziypyqq/Build/Products/Debug-iphonesimulator/Apollo.framework/check-and-run-apollo-codegen.sh
/Users/jing/Library/Developer/Xcode/DerivedData/FrontPage-bmlzfqrnzbhvyqacptgxyziypyqq/Build/Products/Debug-iphonesimulator/Apollo.framework/check-and-run-apollo-codegen.sh
++ echo
++ echo
++ echo
Only get the first parameter...
@jzhw0130: Hmmm, so the parameters aren't even passed to check-and-run-apollo-codegen.sh.
Could you try echoing $APOLLO_FRAMEWORK_PATH from the build script phase?
@martijnwalraven
Input:
echo $0
echo $1
echo $@
echo $*
echo $APOLLO_FRAMEWORK_PATH
Output:
Showing All Messages
++ echo /Users/jing/Library/Developer/Xcode/DerivedData/FrontPage-bmlzfqrnzbhvyqacptgxyziypyqq/Build/Products/Debug-iphonesimulator/Apollo.framework/check-and-run-apollo-codegen.sh
/Users/jing/Library/Developer/Xcode/DerivedData/FrontPage-bmlzfqrnzbhvyqacptgxyziypyqq/Build/Products/Debug-iphonesimulator/Apollo.framework/check-and-run-apollo-codegen.sh
++ echo
++ echo
++ echo
++ echo
@jzhw0130: I meant putting echo $APOLLO_FRAMEWORK_PATH in the build script phase in Xcode, not check-and-run-apollo-codegen.sh.
@martijnwalraven
Sorry
cd ${SRCROOT}/${TARGET_NAME}
echo $APOLLO_FRAMEWORK_PATH
$APOLLO_FRAMEWORK_PATH/check-and-run-apollo-codegen.sh generate $(find . -name '*.graphql') --schema schema.json --output API.swift
Showing All Messages
/Users/jing/Library/Developer/Xcode/DerivedData/FrontPage-bmlzfqrnzbhvyqacptgxyziypyqq/Build/Products/Debug-iphonesimulator/Apollo.framework
++ echo /Users/jing/Library/Developer/Xcode/DerivedData/FrontPage-bmlzfqrnzbhvyqacptgxyziypyqq/Build/Products/Debug-iphonesimulator/Apollo.framework/check-and-run-apollo-codegen.sh
/Users/jing/Library/Developer/Xcode/DerivedData/FrontPage-bmlzfqrnzbhvyqacptgxyziypyqq/Build/Products/Debug-iphonesimulator/Apollo.framework/check-and-run-apollo-codegen.sh
++ echo
++ echo
++ echo
Getting the same issue:
++ exec apollo-codegen
No API.swift generated.
If I do it manually with apollo-codegen generate *.graphql --schema schema.json --output API.swift, the API.swift is generated.
I'm getting a similar issue. I've installed apollo-codegen using npm install -g apollo-codegen and it seems to install correctly.
But when I try to build my project (with the correct build run script), I get error: Can't find apollo-codegen command; make sure to run 'npm install -g apollo-codegen' first.
I'm running:
Xcode 8.3.3
node v8.4.0
npm 5.3.0
Also using oh-my-zsh
Have you found the solution to this?
It can be built successfully when I firstly create an empty .graphql file on ${SRCROOT}/${TARGET_NAME}.
I experienced multiple errors while attempting to get the auto generation working. Including the following:
Apollo.framework does not support the latest version of apollo-codegen.apollo-codegen version installed on my machine to 0.18.8 from the current latest of 0.19.1. 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.
with the following versions
- Apollo (0.8.0):
- Apollo/Core (= 0.8.0)
- Apollo/Core (0.8.0)
I had to change
$APOLLO_FRAMEWORK_PATH/check-and-run-apollo-codegen.sh ...
to:
$APOLLO_FRAMEWORK_PATH/Resources/check-and-run-apollo-codegen.sh ...
@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!
@i-Roma
@NiltiakSivad
@shelldonhu
Still stuck on this. Can you please provide a little more explanation on how to fix this?
Is it best to create a blank .graphql file in a text editor then move this into the project directory in Finder?
Which folder does ${SRCROOT}/${TARGET_NAME}. relate to?
Thanks
@Edwardharpham, with the blank .graphql file you probably will get error like
Syntax Error: Unexpected EOF
Just create an empty file in your left navigation panel in Xcode with .graphql extension, and add in the file query or mutation that contains your schema.json.
Also, you can check my answer where I describe how to avoid this problem. Of course with words of gratitude to @NiltiakSivad :)
@i-Roma , I am also still stuck on this, how did you add in the file query in the graphql file? Could you maybe provide som screenshots of how you did this?
Thanks:)
Ok, I was not alone to struggle with this issue. I'm not sure who is in charge to maintain apollo documentation but it seems like the installation order is not properly align. Can anyone have a full steps to fix this issue?
I don't know if it is relevant, but I had to change the button line of my script to
$APOLLO_FRAMEWORK_PATH/check-and-run-apollo-codegen.sh generate *.graphql --schema schema.json --output API.swift
That made everything run for me.
Edit:
I am actually not generating an API.swift with the above, but can make it work manually as others have pointed out above with apollo-codegen generate *.graphql --schema schema.json --output API.swift
Edit 2:
With pod 0.9.1 it works with the script in the installation guide, but I needed to make the reference to the file manually
$APOLLO_FRAMEWORK_PATH/check-and-run-apollo-cli.sh codegen:generate --queries=\"$(find . -name '*.graphql')\" --schema=schema.json API.swift
I've recently updated the setup instructions for the build phase setup here - I'm going to close this out since that should solve a fair number of these issues. Please open a new issue if you're still encountering problems. Thank you!
Most helpful comment
I experienced multiple errors while attempting to get the auto generation working. Including the following:
Apollo.frameworkdoes not support the latest version ofapollo-codegen.apollo-codegenversion installed on my machine to 0.18.8 from the current latest of 0.19.1.@shelldonhu's suggested fix of adding a
.graphqlfile fixed it for me. Something in the generation script doesn't fail gracefully or the documentation is possibly out of order (it says to verifyAPI.swiftis generated before saying to add a .graphql file).Hope this helps someone.