swift-graphql
swift-graphql copied to clipboard
Code Generation v4.0.0 sytax error
Describe the bug A clear and concise description of what the bug is.
To Reproduce Steps to reproduce the behavior:
- Go to installation
- Run through the generator installation via Brew
- try to run
swift-graphql --help
orswift-graphql <url>
for code generation - See error
Expected behavior Expected to see the help menu or to generate the code based on the url.
Screenshots If applicable, add screenshots to help explain your problem.
dyld[11265]: Library not loaded: '@rpath/lib_InternalSwiftSyntaxParser.dylib'
Referenced from: '/usr/local/Cellar/swiftgraphql/4.0.0/bin/swift-graphql'
Reason: tried: '/usr/lib/swift/lib_InternalSwiftSyntaxParser.dylib' (no such file), '/usr/local/Cellar/swiftgraphql/4.0.0/bin/lib_InternalSwiftSyntaxParser.dylib' (no such file), '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-5.5/macosx/lib_InternalSwiftSyntaxParser.dylib' (no such file), '/usr/lib/swift/lib_InternalSwiftSyntaxParser.dylib' (no such file), '/usr/local/Cellar/swiftgraphql/4.0.0/bin/lib_InternalSwiftSyntaxParser.dylib' (no such file), '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-5.5/macosx/lib_InternalSwiftSyntaxParser.dylib' (no such file), '/usr/local/lib/lib_InternalSwiftSyntaxParser.dylib' (no such file), '/usr/lib/lib_InternalSwiftSyntaxParser.dylib' (no such file)
[1] 11265 abort swift-graphql --help
Desktop (please complete the following information):
- OS: macOS Monterey
- Browser: n/a (in terminal)
- Version 12.6
Smartphone (please complete the following information):
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]
Additional context Add any other context about the problem here. Latest update seems (4.0.0) to have broken code generation
==> maticzav/swift-graphql/SwiftGraphQL: stable 4.0.0, HEAD
Code generator for SwiftGraphQL library
https://swift-graphql.org
/usr/local/Cellar/SwiftGraphQL/4.0.0 (5 files, 15.8MB)
Built from source on 2022-09-14 at 17:52:24
From: https://github.com/maticzav/swift-graphql/blob/HEAD/Formula/SwiftGraphQL.rb
License: MIT
==> Requirements
Required: Xcode ✔
==> Options
--HEAD
Down grading the swift package to 3.0.1 in Xcode 14.0 allows the project to still build. But as you can see above the code generator version is at 4.0.0 and has the above issues. I no longer have any of the older installations available to switch back to see if they still work, but I was seeing a similar syntax issue before upgrading to the latest code gen
Update:
I've managed to get past the above error by copying over the executable from the swift /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/lib_InternalSwiftSyntaxParser.dylib
and placing it into the swift-5.5 folder and down grading my code gen cli to 3.0.2. But I'm still running into an issue when trying to use the code gen
swift-graphql https://your-api-here --config swiftgraphql.yml -o Schema.swift
Generating SwiftGraphQL Selection 🚀
✔ Schema loaded!
✖ The operation couldn’t be completed. (SwiftSyntaxParser.ParserError error 1.)
Error: There was an error formatting the code. Make sure your Swift version (i.e. `swift-format`) matches the `swift-format` version. If you need any help, don't hesitate to open an issue and include the log above!
Re downloaded Xcode 13.4.1 (https://developer.apple.com/download/all/?q=xcode%2013.4). Recopied the parser.dylib
file into swift-5.5/macosx
and the code gen worked. Seems that Xcode 13 utilizes swift 5.5 and Xcode 14 used 5.6/7. This was were the swift versioning issues was coming from
@wambambizzle @maticzav some other libs faced this issue, for example Needle
hopefully this can be resolved
Recopied the parser.dylib file into swift-5.5/macosx and the code gen worked. Seems that Xcode 13 utilizes swift 5.5 and Xcode 14 used 5.6/7. This was were the swift versioning issues was coming from
@wambambizzle what do you mean by recopied, could you please be more specific? thanks!
Sorry, I just meant "copied" !
@wambambizzle you've mentioned that you copied lib_InternalSwiftSyntaxParser.dylib
from /Applications/Xcode.app
into it's swift-5.5
folder. This step helped fixing first issue with missing parser.dylib.
Then appeared SwiftSyntaxParser.ParserError error
. So you copied lib_InternalSwiftSyntaxParser.dylib
from Xcode13 into swift-5.5/macosx
Is that correct?
So both for the lib_InternalSwiftSyntaxParser.dylib
libs are from Xcode 13 or some of them from Xcode14?
sorry for confusion, but I still can't get it working
IIRC I copied it from the swift/Mac
into swift-5.5/Mac
and any other places that it was saying was missing.
Do you have the code gen cli installed locally via something like homebrew? And version of Xcode are you currently building against ? No need to apologize, I understand completely.
@wambambizzle I've built it manually using make. At the moment I have Xcode14, which is released officially
Do you still have Xcode 13.x installed by chance? I think part of the issue (besides needing to copy that lib into the other folders), is that Xcode 13.x is associated to Swift 5.5 while Xcode 14 is Swift 5.6/7. What is the current error(s) that you are seeing?
the current error is your second one, about swift-format mismatch, I think it's related to
I'm on Ventura, so I can't run Xcode13, I've tried to use the lib_InternalSwiftSyntaxParser.dylib
from xcode13, but that didn't helped :(
You can't run it or you can't download/install it at all? If not, think you might have try and find a way to manually install Swift 5.5
to be explicit, it's
✖ The operation couldn’t be completed. (SwiftSyntaxParser.ParserError error 1.)
Error: There was an error formatting the code. Make sure your Swift version (i.e. `swift-format`) matches the `swift-format` version. If you need any help, don't hesitate to open an issue and include the log above!
the current error is your second one, about swift-format mismatch, I think it's related to
I'm on Ventura, so I can't run Xcode13, I've tried to use the
lib_InternalSwiftSyntaxParser.dylib
from xcode13, but that didn't helped :(
@wambambizzle as per that screenshot, I've built library locally using latest main
branch, which worked (instead of trying to match exact versions)
@maticzav this might be a viable solution, maybe you'd like me to create pull request?
@wambambizzle, @nrudnyk , @maticzav: same unpleasing experience for us
- Xcode 14.0.1
- swift tools version 5.7
- swift-graphql 4.0.0
the described and reproducible issue reported by @nrudnyk regarding code generation seems to be caused by the hard swift-format dependency within the Package.swift
dependencies: [
// .package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.0.0"),
.package(url: "https://github.com/apple/swift-format", from: "0.50600.1"),
// ...
As the dev team from swift-format
points out here (see screenshot from @nrudnyk above) this specific version is bind to Xcode 13.3 and swift tools version 5.6.
Current workaround
Therefore my current workaround which does the trick has been the following so far:
- clone the swift-graphql repository
- modify the Package.swift file in line 28 to
.package(url: "https://github.com/apple/swift-format", branch: "main"),
- build the swift-graphql executable via
make install
- copy the executable from
.build/release/swift-graphql
to our current project - run e.g. `swift-graphql <your.respective.url>/graphql --output ./Sources/Generated/API.swift --header "Authorization: Basic AXVubzpwQDU1dzByYM=="
- Voila 🎉 smooth sailing
Generating SwiftGraphQL Selection 🚀
Adding headers to your request:
- Authorization: Basic AXVubzpwQDU1dzByYM==
✔ Schema loaded!
✔ API generated successfully!
â ™ Analyzing Schema
- fix a couple of issues caused by the breaking changes introduced in 3.0.0 and 4.0.0 (coming from 2.3.0) 🙈
@maticzav: any chance to create a PR regarding the pointed version of swift-format as dependency used by the SwiftGraphQLCodegen library which is a dependency of the SwiftGraphQLCLI executable?
An additional comment on this topic
Related to the note in the contribution guidelines
Due to a major improvement in swift-format Source:
NOTE: swift-format on the main branch now uses a version of SwiftSyntax whose parser has been rewritten in Swift and no longer has dependencies on libraries in the Swift toolchain. This allows swift-format to be built, developed, and run using any version of Swift that can compile it, decoupling it from the version that supported a particular syntax.
makes the described requirement and the currently used fix version of swift-format obsolete.
hi everyone
excuse my silence, I see that you've made quite a bit of progress investigating the issue. I'd love to approve a PR if anyone has the capacity or pair program or even just chat with someone from this thread.
Let me know if anyone wants to help with this, I have capacity for the next two weeks 🙂