4

I'm trying to build a sample Apollo-IOS on Xcode 10. I have followed all the step describe in the docs:

Apolo-IOS getting started

There is an error as bellow

++ npx --no-install apollo codegen:generate --queries=./GraphQL/Queries.graphql --schema=schema.json API.swift --passthroughCustomScalars
[?25l[22:26:11] Loading Apollo config [started]
[22:26:11] Loading Apollo config [completed]
[22:26:11] Resolving GraphQL document sets and dependencies [started]
[22:26:11] Scanning for GraphQL queries (1 found) [title changed]
[22:26:11] Scanning for GraphQL queries (1 found) [completed]
[22:26:11] Generating query files [started]
[22:26:11] Generating query files with 'swift' target [title changed]
[22:26:11] Generating query files with 'swift' target [failed]
[22:26:11] → Cannot read property 'getType' of undefined
[?25hTypeError: Cannot read property 'getType' of undefined
    at typeFromAST (/Volumes/Data/OneDrive/IOS/Source/GraphQL/JediArchives/JediArchives-Final/node_modules/graphql/utilities/typeFromAST.js:41:19)
    at TypeInfo.enter (/Volumes/Data/OneDrive/IOS/Source/GraphQL/JediArchives/JediArchives-Final/node_modules/graphql/utilities/TypeInfo.js:153:74)
    at Object.enter (/Volumes/Data/OneDrive/IOS/Source/GraphQL/JediArchives/JediArchives-Final/node_modules/graphql/language/visitor.js:363:16)
    at Object.visit (/Volumes/Data/OneDrive/IOS/Source/GraphQL/JediArchives/JediArchives-Final/node_modules/graphql/language/visitor.js:254:26)
    at getValidationErrors (/Volumes/Data/OneDrive/IOS/Source/GraphQL/JediArchives/JediArchives-Final/node_modules/apollo/lib/validation.js:21:15)
    at Object.validateQueryDocument (/Volumes/Data/OneDrive/IOS/Source/GraphQL/JediArchives/JediArchives-Final/node_modules/apollo/lib/validation.js:26:30)
    at Object.generate [as default] (/Volumes/Data/OneDrive/IOS/Source/GraphQL/JediArchives/JediArchives-Final/node_modules/apollo/lib/generate.js:19:18)
    at Task.task (/Volumes/Data/OneDrive/IOS/Source/GraphQL/JediArchives/JediArchives-Final/node_modules/apollo/lib/commands/codegen/generate.js:98:64)
    at Promise.resolve.then.then.skipped (/Volumes/Data/OneDrive/IOS/Source/GraphQL/JediArchives/JediArchives-Final/node_modules/listr/lib/task.js:167:30)
[?25hCommand PhaseScriptExecution failed with a nonzero exit code

Seem like my Queries.graphql and schema.json is in the correct place and can be found by the run script. Anyone know what is the error and how to resolve (I have updated to latest Apollo-Cli which is 1.9.2)

Lê Khánh Vinh
  • 2,591
  • 5
  • 31
  • 77

3 Answers3

12

I had the same problem.
I checkout the Run script only when installing and I resolved the problem. Check that you tick on that checkbox Run script only when installing enter image description here

Angel F Syrus
  • 1,984
  • 8
  • 23
  • 43
  • Hì thank for the response. What if we change our GraphQL file and regenerate? – Lê Khánh Vinh Nov 09 '18 at 09:08
  • Actually I am also stucking with some problem in Apollo GraphQL including this issue and I resolved it with checkout **Run script only when installing** so I am not sure about your question.... – Angel F Syrus Nov 09 '18 at 09:14
  • Do not change anything that is created by Apollo. If you'll lose those changes when Apollo recreate the file during it's prebuild script. Specifically the API.swift that it generates. – xdeleon Jan 09 '19 at 22:59
  • problem will solved but API.Swift Is Not genreated – Chandan May 30 '21 at 17:32
2

For me Xcode13. Tick the check box of "For install builds only" under build base. working fine

enter image description here

Elavarasan r
  • 1,055
  • 2
  • 12
  • 22
-1

In 2023 with xCode 14+ and installing apollo through the package manager, it stills the same solution Since i cant post an image because im not level 10, i just wanted to let you know that u still need to mark the checkbox:

For install build only

-Peace

Raul
  • 1
  • 1
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/34615096) – BoP Jul 05 '23 at 21:53