apollographql / apollo-ios

📱  A strongly-typed, caching GraphQL client for iOS, written in Swift.
https://www.apollographql.com/docs/ios/
MIT License
3.88k stars 723 forks source link

Build phase script stops SwiftUI automatic preview #579

Closed kortac closed 5 years ago

kortac commented 5 years ago

When using Apollo with the build phase script as stated in the docs the automatic preview of SwiftUI is paused every time the script was executed and has to be resumed manually.

Intended outcome

Even with the build phase script active, automatic preview should not be paused after Xcode built the preview files for SwiftUI files.

Actual outcome

With the build phase script active user has to manually resume automatic preview every time Xcode built the preview.

How to reproduce the issue

  1. Create a SwiftUI project with Xcode 11
  2. Add Apollo framework as library with the code generation build step as stated in the docs
  3. Open ContentView.swift and resume preview. Preview is rendered and automatic preview paused after that.
  4. Change the text in ContentView.swift and resume preview. Preview is rendered again and again automatic preview paused after that.
  5. Remove the Generate Apollo GraphQL API build phase (or add exit 0 at the beginning).
  6. Repeat steps 3 & 4 -> Automatic preview is not paused
js commented 5 years ago

Have you set up the Input/Output Files of the build phase?

designatednerd commented 5 years ago

This is probably related to #76 - we need a better "Did anything change? No? Then don't regenerate." mechanism.

designatednerd commented 5 years ago

Good workaround to this from an issue on the tooling repo

designatednerd commented 5 years ago

I've added documentation of the workaround to the Advanced Codegen Tips And Tricks section of our documentation. If you're still having issues after setting that up, please file a new issue. Thank you!

designatednerd commented 5 years ago

(Note that I'm still planning to add XCFileList generation as part of the Swift Codegen project, but that workaround should get you through until that's up and running)

heliumdice commented 2 years ago

Hey Team Apollo,

I was running into problems with SwiftUI previews not displaying and stumbled upon this thread. I am running the latest versions of Xcode (13.4.1) and Apollo (0.51.0).

I tried adding the InputOutput files recommended in 'Advanced codegen tips and tricks'. However this didn't work.

What fix it for me was to add

if [ "${ENABLE_PREVIEWS}" = "YES" ]; then
  echo "Previews enabled, quitting to prevent 'preview paused'."
  exit 0;
fi

To the beginning of the codgen build phase script. Not sure if this is the correct approach. But just thought I would add my 2 cents just incase anyone else gets stuck.

calvincestari commented 2 years ago

Thanks @heliumdice, there has been some discussion around that environment variable already - https://github.com/apollographql/apollo-ios/pull/2257.