简体   繁体   English

无法使用 Apollo 框架构建 Xcode iOS 项目以使用 GraphQL

[英]Unable to build Xcode iOS project using Apollo framwork to work with GraphQL

I am working on an Xcode project that connects to a GraphQL API.我正在开发一个连接到 GraphQL API 的 Xcode 项目。 To do this, I'm using the Apollo framework .为此,我使用Apollo 框架

In my project, I've installed the cocoapod that includes the Apollo framework, and then added the following run script in Xcode:在我的项目中,我已经安装了包含 Apollo 框架的 cocoapod,然后在 Xcode 中添加了以下运行脚本:

if which apollo-codegen >/dev/null; then

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

  if [ -z "$APOLLO_FRAMEWORK_PATH" ]; then
    echo "warning: Couldn't find Apollo.framework in FRAMEWORK_SEARCH_PATHS; make sure to add the framework to your project."
    exit 0
  fi

  cd "${SRCROOT}/${TARGET_NAME}/GraphQL"
  $APOLLO_FRAMEWORK_PATH/check-and-run-apollo-codegen.sh generate \
    $(find . -name '*.graphql') \
    --schema schema.json \
    --output Generated/GraphQLAPI.swift
else
  echo "Skipping Apollo code generation"
fi

This is how it looks in Xcode:这是它在 Xcode 中的样子:

在此处输入图片说明

My directory structure in Xcode looks like this:我在 Xcode 中的目录结构如下所示:

在此处输入图片说明

I then run the following command from Terminal:然后我从终端运行以下命令:

npm install -g apollo-codegen

When I then try to build my Xcode project, I unfortunately get the following build error:当我尝试构建我的 Xcode 项目时,不幸的是我收到以下构建错误:

/Users/JohnDoe/Library/Developer/Xcode/DerivedData/The_Game-dfpiqreyqdjocaawjrfwhrxhdosf/Build/Intermediates.noindex/The Game.build/Debug-iphonesimulator/The Game.build/Script-7851AAFF2110C71000903FAD.sh: line 12: /Users/JohnDoe/Library/Developer/Xcode/DerivedData/The_Game-dfpiqreyqdjocaawjrfwhrxhdosf/Build/Products/Debug-iphonesimulator/Apollo/Apollo.framework/check-and-run-apollo-codegen.sh: No such file or directory /Users/JohnDoe/Library/Developer/Xcode/DerivedData/The_Game-dfpiqreyqdjocaawjrfwhrxhdosf/Build/Intermediates.noindex/The Game.build/Debug-iphonesimulator/The Game.build/Script-7851AAFF2110C71000903FAD:sh / /JohnDoe/Library/Developer/Xcode/DerivedData/The_Game-dfpiqreyqdjocaawjrfwhrxhdosf/Build/Products/Debug-iphonesimulator/Apollo/Apollo.framework/check-and-run-apollo-codegen.sh:没有这样的文件或目录

I honestly have no idea why I'm getting this area.老实说,我不知道为什么我会得到这个区域。 Can anyone see why?谁能看出为什么?

The build script has changed in recent versions of apollo ios, because apollo-codegen is now part of the new apollo cli.构建脚本在最近版本的 apollo ios 中发生了变化,因为 apollo-codegen 现在是新的 apollo cli 的一部分。 it should reference check-and-run-apollo-cli.sh instead.它应该引用check-and-run-apollo-cli.sh来代替。

Also make sure you use the latest version of apollo (currently 0.9.2 ) by specifying the version in your podfile.还要确保通过在 podfile 中指定版本来使用最新版本的 apollo(当前为0.9.2 )。 You might also need to update your pod repo by running pod repo update .您可能还需要通过运行pod repo update来更新您的 pod repo。

我在使用迦太基时遇到了同样的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM