Closed aamir-nazir closed 5 years ago
Hey Aamir, looks like wherever you put the schema.json
file, the script is not finding it. Can you add a couple details here to help troubleshoot:
schema.json
in relation to your .xcodeproj
or .xcworkspace
? Hey @designatednerd
I have been integrating Apollo using CocoaPods and following installation guide from https://www.apollographql.com/docs/ios/installation/.
For downloading schema.json
I followed instructions from: https://www.apollographql.com/docs/ios/downloading-schema/
Generated schema.json
is residing in same directory where .xcodeproj
or .xcworkspace
are.
Xcode: 10.2
Podfile.lock:
- Apollo (0.15.1):
npm ls graphql: └─┬ apollo@2.17.4 ├─┬ apollo-language-server@1.14.3 │ └── graphql@14.5.4 deduped └── graphql@14.5.4
Script Using for Code-Gen:
cd "${SRCROOT}/${TARGET_NAME}"
"${SCRIPT_PATH}"/check-and-run-apollo-cli.sh codegen:generate --target=swift --includes=./**/*.graphql --localSchemaFile="schema.json" API.swift```
OK! I think the issue is that the schema is in the same folder as the xcodeproj
/xcworkspace
- it needs to be one directory up. This isn't super clear in the docs, I'll make sure to clarify it.
@designatednerd going one folder up takes me out of the project, is that what you mean? Here are the paths of different files in project.
MyPorject/xcodeproj
MyPorject/xcworkspace
MyPorject/schema.json
Sorry, I guess that'd be one directory down - here's the doc update i'm proposing, let me know what you think of that!
This time I put schema.json
one level deeper: MyPorject/MyPorject/schema.json
But it didn't work, same error.
Here are the complete error logs:
Now using node v10.16.0 (npm v6.9.0)
› Warning: apollo update available from 2.17.4 to 2.18.1.
++ npx --no-install apollo codegen:generate --target=swift '--includes=./**/*.graphql' --localSchemaFile=schema.json API.swift
› Warning: apollo update available from 2.17.4 to 2.18.1.
⚠️ It looks like there are 0 files associated with this Apollo Project. This may be because you don't have any files yet, or your includes/excludes fields are configured incorrectly, and Apollo can't find your files. For help configuring Apollo projects, see this guide: https://bit.ly/2ByILPj
Loading Apollo Project [started]
Loading Apollo Project [completed]
Generating query files [started]
Generating query files with 'swift' target [title changed]
Generating query files with 'swift' target [failed]
→ No operations or fragments found to generate code for.
Error: No operations or fragments found to generate code for.
at write (/Users/xxx/MyPorject/node_modules/apollo/lib/commands/client/codegen.js:61:39)
at Task.task (/Users/xxx/MyPorject/node_modules/apollo/lib/commands/client/codegen.js:86:46)
Command PhaseScriptExecution failed with a nonzero exit code
OK! That's actually a different error - it's not seeing any .graphql
files to generate code for. If you add a simple .graphql
file with a query, that error should go away.
I have already added one .graphql
file during Apollo installation. Its path is MyPorject /GraphQL/SignInUser.graphql
Actually Apollo found schema.json
, when placed at: MyPorject/MyPorject/schema.json
Now I tried placing .graphql
in same directory. This time it's a different error.
GraphQLError: Apollo does not support anonymous operations
at GraphQLClientProject.get operations [as operations] (/Users/xxx/MyPorject/node_modules/apollo-language-server/lib/project/client.js:219:31)
at write (/Users/xxx/MyPorject/node_modules/apollo/lib/commands/client/codegen.js:58:75)
at Task.task (/Users/xxx/MyPorject/node_modules/apollo/lib/commands/client/codegen.js:86:46)
(node:34527) UnhandledPromiseRejectionWarning: GraphQLError: Apollo does not support anonymous operations
at GraphQLClientProject.get operations [as operations] (/Users/xxx/MyPorject/node_modules/apollo-language-server/lib/project/client.js:219:31)
at write (/Users/xxx/MyPorject/node_modules/apollo/lib/commands/client/codegen.js:58:75)
at GraphQLClientProject.project.onDiagnostics [as _onDiagnostics] (/Users/xxx/MyPorject/node_modules/apollo/lib/commands/client/codegen.js:84:29)
at GraphQLClientProject.validate (/Users/xxx/MyPorject/node_modules/apollo-language-server/lib/project/client.js:140:18)
at GraphQLClientProject.validateIfNeeded (/Users/xxx/MyPorject/node_modules/apollo-language-server/lib/project/base.js:137:14)
at Timeout.setTimeout [as _onTimeout] (/Users/xxx/MyPorject/node_modules/apollo-language-server/lib/project/base.js:129:22)
at ontimeout (timers.js:436:11)
at tryOnTimeout (timers.js:300:5)
at listOnTimeout (timers.js:263:5)
at Timer.processTimers (timers.js:223:10)
(node:34527) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
(node:34527) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Command PhaseScriptExecution failed with a nonzero exit code```
@designatednerd I got it working, primarily the issue was incorrect placement of schema.json
and .graphql
files which was causing errors.
Mentioning correct path/position of these files in documentation would saves a lot time of many developers. Thanks
Yep, let me know if the PR I opened is helpful in this regard - can we close this issue out and move discussion to that PR?
Yes I think we can close this issue. Even I can contribute in enhancement of Apollo Installation Docs if it's possible and fine for you.
Yes, absolutely! We're always happy to have folks contribute!
Closing this one out. Thank you!
Hey guys, it can be you have wrong schema.json and .graph files, so you should try correct file here to test: https://www.raywenderlich.com/595-getting-started-with-graphql-apollo-on-ios ZIP: graph.zip
I had the same issue with Swift 5 and apollo client 0.41. able to solve the issue very easily. Just move the schema.json file project root folder. Good Luck
I second this. Both schema.json and .graphql files should be 2 levels deep (ExampleProject/ExampleProject). Somehow I don't recommend the StackOverflow solution as well. It skips the error (which is crucial) and doesn't generate the API.swift file. https://stackoverflow.com/questions/53289524/xcode-10-2-1-command-phasescriptexecution-failed-with-a-nonzero-exit-code
If you use the convenience initializer of ApolloCodegenOptions
then the schema file is required to be in the project root but you can always place it wherever you want in the folder hierarchy and use the designated initializer to provide the full path to it instead. There are a lot of default values for the designated initializer arguments so it's not much more to configure than the using the convenience one.
I have added schema.json after downloading it from endpoint but still facing this issue.