2

I'm using the apollo framework for GraphQL that I installed using Carthage but I have an error when I run the script to generate the API.swift file during the build phase.

The error is

> [myproject]/Carthage/Build/iOS/Apollo.framework: is a directory
  Command /bin/sh failed with exit code 126

I did added the script like in the apollo doc :

Here is the script itself:

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

Of course, I have also generated the schema.json beforehand

Zoe
  • 27,060
  • 21
  • 118
  • 148
Maxence
  • 23
  • 5
  • Well there is no code to show at this point, expect maybe the script itself that I just added. I followed all the steps in the doc, I just want the script to run properly and create the API.swift file – Maxence Dec 07 '17 at 10:30

1 Answers1

1

Might be a bit late to answer but at least on my machine APOLLO_FRAMEWORK_PATH gets evaluated to two frameworks (iOS and watchOS) and thus running the bundled script with $APOLLO_FRAMEWORK_PATH/check-and-run-apollo-codegen.sh fails.

Assuming the scripts don't differ (as of version apollo-ios@0.8.0 they don't) you can add -print -quit to the end of the find command to make it return only one result.

The full script will be:

APOLLO_FRAMEWORK_PATH="$(eval find $FRAMEWORK_SEARCH_PATHS -name "Apollo.framework" -maxdepth 1 -print -quit)"

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
mkko
  • 4,262
  • 3
  • 25
  • 29
  • This fixed the issue for me. I can report that it also works for the Apollo CLI script, which Apollo is now using instead of the codegen one above. – Drew C Feb 06 '19 at 19:34