Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to run code generation #2543

Closed
ilockett opened this issue Oct 3, 2022 · 63 comments · Fixed by #2548 or #2554
Closed

Unable to run code generation #2543

ilockett opened this issue Oct 3, 2022 · 63 comments · Fixed by #2548 or #2554
Assignees
Labels
bug Generally incorrect behavior codegen Issues related to or arising from code generation

Comments

@ilockett
Copy link

ilockett commented Oct 3, 2022

Bug report

Installing Apollo 1.0.0 via Cocoapods results in code generation error.

Versions

Please fill in the versions you're currently using:

  • apollo-ios SDK version: 1.0.0
  • Xcode version: 14.0.1
  • Swift version: 5.7
  • Package manager: N/A
  • Cocoapods version: 1.11.3

Steps to reproduce

pod init

Add pod 'Apollo'

pod install

./Pods/Apollo/apollo-ios-cli init --schema-name MySchema
./Pods/Apollo/apollo-ios-cli generate

ApolloCodegenLib/resource_bundle_accessor.swift:11: Fatal error: could not load resource bundle: from /Users/xxx/ProjectName/Pods/Apollo/Apollo_ApolloCodegenLib.bundle or /Users/xxx/Library/Caches/CocoaPods/Pods/Release/Apollo/1.0.0-95555/.build/arm64-apple-macosx/release/Apollo_ApolloCodegenLib.bundle
zsh: trace trap  ./Pods/Apollo/apollo-ios-cli generate

Further details

Note that cocoapods is installed using Hombrew.

@arkulpaKonstantin
Copy link

Just ran into the same issue 😕

@calvincestari
Copy link
Member

Thanks for the bug reports.

We made a fix for this type of error last week. There is also a test that's able to call the CLI and succeed. This is weird..

@calvincestari
Copy link
Member

A quick thought - I wonder if it's related to not using the --path command, which means it's looking for the config file in the location of the CLI binary?

init didn't fail though so it seems it was able to write the config file to that location though.

Try this as a workaround - use an external path for both init and generate. See if that works because it then wouldn't be looking in the .Pods folder.

@ilockett
Copy link
Author

ilockett commented Oct 3, 2022

A quick thought - I wonder if it's related to not using the --path command, which means it's looking for the config file in the location of the CLI binary?

init didn't fail though so it seems it was able to write the config file to that location though.

Try this as a workaround - use an external path for both init and generate. See if that works because it then wouldn't be looking in the .Pods folder.

Thanks @calvincestari , unfortunately adding the --path to both init and generate resulted in the same error. I used a path deliberately not in the Pods folder.

@calvincestari
Copy link
Member

Ok, I'll have to dig into it a bit later; we're all en route to Summit at the moment. Will try take a look later today. Apologies for the delay.

@indama
Copy link

indama commented Oct 4, 2022

Hi, The same issue here.

@ibragimovscode1
Copy link

same problem here, struggling for 4 days and couldn't solve it please help

@teendream
Copy link

Same problem. Can't sleep, the customer is rushing the work. I'm really looking forward to news about the fix.

@indama
Copy link

indama commented Oct 4, 2022

I tried installing via Package manager. When I add ApolloCodegenLib I have some errors.
Screenshot at Oct 04 16-32-27

@calvincestari
Copy link
Member

@indama - make sure you're building for mac only. ApolloCodegenLib is macos only, it is not designed to build on iOS. The rest of the library will run on iOS but code generation is only for macos.

@sammcode
Copy link

sammcode commented Oct 4, 2022

@calvincestari Hi there! Had a quick question regarding the errors @indama is hitting, as my team just hit the same problem. Is there a reason why ApolloCodeGenLib used to work for iOS?

We set up an iOS project a few weeks ago and followed the documentation at the time that recommended using ApolloCodeGenLib over deprecated bash scripts for automatic code generation. I don't recall the docs mentioning macOS only anywhere, and it was working great for us on iOS until this week. We're trying to transition to the new Codegen CLI now.

@SilverTab
Copy link

SilverTab commented Oct 4, 2022

I'll be honest; I find the instructions to get code generation to work in 1.0 to be very confusing. Looking at the available options listed in the documentation to install the codegen CLI:

  1. Swift PM: I thought this would work out for our project, but since we manage our Swift packages via Xcode, it doesn't seem like this solution applies? (If so, I haven't found out how).
  2. Cocoapods: We don't use it so, not an option.
  3. Manual install: Not a fan of the fact that the CLI will not be tied to the Apollo library version but figured I'd give it a try so that I can at least be unblocked. Followed the instructions and got this:
% git clone https://github.com/apollographql/apollo-ios.git
% cd apollo-ios
% make build-cli
swift build --product apollo-ios-cli -c release
error: 'apollo-ios': Invalid manifest
/Users/jeannicolas/Code/swift/apollo-ios/Package.swift:4:8: error: no such module 'PackageDescription'
import PackageDescription
       ^
make: *** [build-cli] Error 1]

Any help would be appreciated...

@sammcode
Copy link

sammcode commented Oct 4, 2022

We are also using Xcode to manage Swift packages, so we were also a bit confused on how to set that up. Specifically, it was unclear how we can edit the apollo-codegen-configuration.json file in Xcode. We made a little bit of progress with the SPM solution, but we are still running into issues (will go into detail below).

Possible workaround for editing configuration file when using SPM

A workaround I tried with the SPM solution was opening the apollo-codegen-configuration.json file in a TextEditor rather than Xcode, which at least allowed us to edit the file.

Schema fetching errors

But when attempting to fetch the schema, we're still running into errors.

We've tried with two working graphql endpoints and have gotten the same error with both of them. We are unclear as to if there is a problem with our configuration, or if there is a bug of some sort here.

The main error we keep getting is:

Error: A server with the specified hostname could not be found.

It also looks like its having an issue reading from a cache, as we get this error as well:

2022-10-04 14:37:29.452 apollo-ios-cli[31890:14972703] NetworkStorageDB:_openDBReadConnections: failed to open read connection to DB @ /Users/samuel.mcgarry/Library/Caches/apollo-ios-cli/Cache.db.  Error=14. Cause=unable to open database file

@m1entus
Copy link

m1entus commented Oct 4, 2022

I am getting similar issue when trying to run cli (get via Pods):

m1entus@MacBook-Pro geneva-ios % ./Pods/Apollo/apollo-ios-cli generate
ApolloCodegenLib/resource_bundle_accessor.swift:11: Fatal error: could not load resource bundle: from /Users/m1entus/ios/Pods/Apollo/Apollo_ApolloCodegenLib.bundle or /Users/m1entus/Library/Caches/CocoaPods/Pods/Release/Apollo/1.0.0-95555/.build/x86_64-apple-macosx/release/Apollo_ApolloCodegenLib.bundle
zsh: illegal hardware instruction  ./Pods/Apollo/apollo-ios-cli generate

@calvincestari
Copy link
Member

@calvincestari Hi there! Had a quick question regarding the errors @indama is hitting, as my team just hit the same problem. Is there a reason why ApolloCodeGenLib used to work for iOS?

We set up an iOS project a few weeks ago and followed the documentation at the time that recommended using ApolloCodeGenLib over deprecated bash scripts for automatic code generation. I don't recall the docs mentioning macOS only anywhere, and it was working great for us on iOS until this week. We're trying to transition to the new Codegen CLI now.

@sammcode I think there might be some confusion between ApolloCodegenLib and the new apollo-ios-cli. ApolloCodegenLib has always only been designed to run on macOS because code generation does not need to be executed on mobile devices. You can view the ApolloCodegen class from 0.53.0 and it has the same macOS-only designation.

v1.0 moves away from recommending that code generation be executed with each build, which is what the bash scripting help before recommended. Note that you can still take that same approach but using the new apollo-ios-cli instead of the legacy Apollo tooling CLI; very similar names I'm sorry.

@calvincestari
Copy link
Member

@SilverTab your make build error seems pretty odd; PackageDescription is a Swift Package Manager defined object so as long as the dependencies are fetched correctly it should all be there. Could you try resetting the package cache or dependencies and see if that helps resolve that error - swift package reset

@ibragimovscode1
Copy link

ibragimovscode1 commented Oct 5, 2022

@calvincestari Hi there! Had a quick question regarding the errors @indama is hitting, as my team just hit the same problem. Is there a reason why ApolloCodeGenLib used to work for iOS?
We set up an iOS project a few weeks ago and followed the documentation at the time that recommended using ApolloCodeGenLib over deprecated bash scripts for automatic code generation. I don't recall the docs mentioning macOS only anywhere, and it was working great for us on iOS until this week. We're trying to transition to the new Codegen CLI now.

Hi @calvincestari regarding to the issue we faced, we are going to downgrade to 0.53.0 version and, continue working. What do you think? Is it solid decision or Should we wait for a new Codegen CLI?
Thanks.

@deltakroneker
Copy link

After upgrading to 1.0.0 i also encounter issue during the codegen phase:

ApolloCodegenLib/resource_bundle_accessor.swift:11: Fatal error: could not load resource bundle: from /Users/XXXXXXXX/ios/Pods/Apollo/Apollo_ApolloCodegenLib.bundle or /Users/XXX/Library/Caches/CocoaPods/Pods/Release/Apollo/1.0.0-95555/.build/arm64-apple-macosx/release/Apollo_ApolloCodegenLib.bundle

@SilverTab
Copy link

@SilverTab your make build error seems pretty odd; PackageDescription is a Swift Package Manager defined object so as long as the dependencies are fetched correctly it should all be there. Could you try resetting the package cache or dependencies and see if that helps resolve that error - swift package reset

Thanks for pointing me in the right direction... I was able to get it to build by first doing: % sudo xcode-select --reset

@AnthonyMDev
Copy link
Contributor

Update: We know the root cause of the the issue with running Codegen when using CocoaPods. @calvincestari is working on the fix for that now, and we will have it released ASAP!

I'll be honest; I find the instructions to get code generation to work in 1.0 to be very confusing. Looking at the available options listed in the documentation to install the codegen CLI:

@SilverTab Thank you for the feedback! We will work on trying to make the documentation clearer next week as well.

Swift PM: I thought this would work out for our project, but since we manage our Swift packages via Xcode, it doesn't seem like this solution applies? (If so, I haven't found out how).

I'm looking into this now. We were under the impression that this would still work the same, but if we were wrong there, this is definitely an oversight on our side. We will have a resolution for you ASAP.

@m1entus
Copy link

m1entus commented Oct 5, 2022

@AnthonyMDev @calvincestari Thanks guys, can't wait for it! btw. If i am using multiple apollo schema endpoints, i am wondering if it possible to specify it in apollo-codegen-configuration.json and add enum namespace for each ?

@AnthonyMDev
Copy link
Contributor

@SilverTab You can run the plugin commands using Xcode like this.
https://blog.eidinger.info/xcode-integration-of-swift-package-plugins-in-xcode-14

I'll update the docs to add this next week!

@AnthonyMDev
Copy link
Contributor

@m1entus I'd love to talk more about this use case and understand what you want to achieve there.

@AnthonyMDev
Copy link
Contributor

Looks like we need to explicitly support the use of the package plugin from within the Xcode project. This was an oversight on our side due to not knowing about this...

We'll get it working and update this thread as soon as we do!

@calvincestari calvincestari self-assigned this Oct 5, 2022
@calvincestari calvincestari added bug Generally incorrect behavior codegen Issues related to or arising from code generation labels Oct 5, 2022
@calvincestari
Copy link
Member

Reopening this issue until we've fixed the Xcode project plugins workflow.

@AnthonyMDev
Copy link
Contributor

@elviva404 It looks like something is wrong with your schema here. It might be that you have named the query Query, but I don't think that should be an issue. Try changing the name to MyQuery or something, just to see if that's the issue.

In your apollo-codegen-config.json file, make sure that you are pointing to the path of your schema correctly. Let me know if that's your problem, because we should be emitting a better error there if so.

@AnthonyMDev
Copy link
Contributor

This issue has been closed as the specific cause of it has been corrected. The fix for this will be released in 1.0.1 very soon and is available right now on the main branch.

If you are having other problems with codegen, please submit a new issue!

Thanks to everyone for all the info as we work this out. We unfortunately did not get enough users during the Beta period to find these edge cases. So we are working quickly to resolve all of them now and will release a patch version ASAP!

@elviva404
Copy link

Thanks

@AnthonyMDev
Copy link
Contributor

@elviva404 Please keep me updated. Want to make sure you're able to get this working!

@ilockett
Copy link
Author

This issue has been closed as the specific cause of it has been corrected. The fix for this will be released in 1.0.1 very soon and is available right now on the main branch.

If you are having other problems with codegen, please submit a new issue!

Thanks to everyone for all the info as we work this out. We unfortunately did not get enough users during the Beta period to find these edge cases. So we are working quickly to resolve all of them now and will release a patch version ASAP!

Thanks for the update @AnthonyMDev - appreciate you and @calvincestari replying to us all and sorting these issues so quickly.

@DavidFerreiraYEO
Copy link

DavidFerreiraYEO commented Oct 14, 2022

Hi, @AnthonyMDev I'm getting a similar error as @elviva404:

I'm trying to generate code following this steps using cocoa pods and Apollo 1.0.1.
On step: 5. Setup and run code generation using appolo-ios-cli generate command I'm getting this error:

 Error: Cannot query field "getAuthServiceHealth" on type "undefined"
 ./../NetworkInterface/GraphQL/QueriesList.graphql:2:2
1 | query Health {
2 | 	getAuthServiceHealth{
  |  ^
3 | 		status

Queries.graphql:

query Health {
	getAuthServiceHealth{
		status
		service
	}
}

schema:

{
  "__schema": {
    "queryType": {
      "name": "Query"
    },
    "mutationType": null,
    "subscriptionType": null,
    "types": [
      {
        "kind": "OBJECT",
        "name": "Query",
        "description": null,
        "fields": [
          {
            "name": "getAuthServiceHealth",
            "description": null,
            "args": [],
            "type": {
              "kind": "NON_NULL",
              "name": null,
              "ofType": {
                "kind": "OBJECT",
                "name": "HealthResponse",
                "ofType": null
              }
            },
            "isDeprecated": false,
            "deprecationReason": null
          },

Why I'm getting this error?

Thanks

@calvincestari
Copy link
Member

@DavidFerreiraYEO, that looks like a GraphQL syntax error. Have you confirmed that your query works in Apollo Studio or GraphiQL?

If it works there it should work for code generation. If not, get it working there first.

@DavidFerreiraYEO
Copy link

DavidFerreiraYEO commented Oct 14, 2022

@calvincestari

Screenshot 2022-10-14 at 15 43 21

It works on GraphiQL.

@AnthonyMDev
Copy link
Contributor

I have a feeling that we aren’t emitting an error when the schema isn’t picked up by the code gen engine. This looks like the schema path is not picking up the schema. That may be why it doesn’t recognize the field.

@DavidFerreiraYEO
Copy link

DavidFerreiraYEO commented Oct 14, 2022

@calvincestari @AnthonyMDev I just re-do everything in a clean project:

steps I have done:

  • pod install (last version 1.0.1)
  • apollo schema:download --endpoint=https://xxxxxx/graphql myUniqueSchema.json
  • ./Pods/Apollo/apollo-ios-cli init --schema-name myUniqueSchema.json
  • ./Pods/Apollo/apollo-ios-cli generate

now I'm getting different output:

Error: GraphQLSchemaValidationError: Must provide only one schema definition.

There can be only one query type in schema.

There can be only one mutation type in schema.

There can be only one subscription type in schema.

There can be only one type named "Query".

Field "Query.hero" can only be defined once.

Field "Query.reviews" can only be defined once.

Field "Query.search" can only be defined once.

Field "Query.character" can only be defined once.

Field "Query.droid" can only be defined once.

Field "Query.human" can only be defined once.

Field "Query.starship" can only be defined once.

There can be only one type named "Mutation".

Field "Mutation.createReview" can only be defined once.

There can be only one type named "Subscription".

Field "Subscription.reviewAdded" can only be defined once.

There can be only one type named "Episode".

Enum value "Episode.NEWHOPE" can only be defined once.

Enum value "Episode.EMPIRE" can only be defined once.

Enum value "Episode.JEDI" can only be defined once.

There can be only one type named "Character".

Field "Character.id" can only be defined once.

Field "Character.name" can only be defined once.

Field "Character.friends" can only be defined once.

Field "Character.friendsConnection" can only be defined once.

Field "Character.appearsIn" can only be defined once.

There can be only one type named "LengthUnit".

Enum value "LengthUnit.METER" can only be defined once.

Enum value "LengthUnit.FOOT" can only be defined once.

There can be only one type named "Human".

Field "Human.id" can only be defined once.

Field "Human.name" can only be defined once.

Field "Human.homePlanet" can only be defined once.

Field "Human.height" can only be defined once.

Field "Human.mass" can only be defined once.

Field "Human.friends" can only be defined once.

Field "Human.friendsConnection" can only be defined once.

Field "Human.appearsIn" can only be defined once.

Field "Human.starships" can only be defined once.

There can be only one type named "Droid".

Field "Droid.id" can only be defined once.

Field "Droid.name" can only be defined once.

Field "Droid.friends" can only be defined once.

Field "Droid.friendsConnection" can only be defined once.

Field "Droid.appearsIn" can only be defined once.

Field "Droid.primaryFunction" can only be defined once.

There can be only one type named "FriendsConnection".

Field "FriendsConnection.totalCount" can only be defined once.

Field "FriendsConnection.edges" can only be defined once.

Field "FriendsConnection.friends" can only be defined once.

Field "FriendsConnection.pageInfo" can only be defined once.

There can be only one type named "FriendsEdge".

Field "FriendsEdge.cursor" can only be defined once.

Field "FriendsEdge.node" can only be defined once.

There can be only one type named "PageInfo".

Field "PageInfo.startCursor" can only be defined once.

Field "PageInfo.endCursor" can only be defined once.

Field "PageInfo.hasNextPage" can only be defined once.

There can be only one type named "Review".

Field "Review.episode" can only be defined once.

Field "Review.stars" can only be defined once.

Field "Review.commentary" can only be defined once.

There can be only one type named "ReviewInput".

Field "ReviewInput.stars" can only be defined once.

Field "ReviewInput.commentary" can only be defined once.

Field "ReviewInput.favorite_color" can only be defined once.

There can be only one type named "ColorInput".

Field "ColorInput.red" can only be defined once.

Field "ColorInput.green" can only be defined once.

Field "ColorInput.blue" can only be defined once.

There can be only one type named "Starship".

Field "Starship.id" can only be defined once.

Field "Starship.name" can only be defined once.

Field "Starship.length" can only be defined once.

Field "Starship.coordinates" can only be defined once.

There can be only one type named "SearchResult".

Must provide only one schema definition.

There can be only one query type in schema.

There can be only one mutation type in schema.

There can be only one subscription type in schema.

There can be only one type named "Query".

Field "Query.hero" can only be defined once.

Field "Query.reviews" can only be defined once.

Field "Query.search" can only be defined once.

Field "Query.character" can only be defined once.

Field "Query.droid" can only be defined once.

Field "Query.human" can only be defined once.

Field "Query.starship" can only be defined once.

There can be only one type named "Mutation".

Field "Mutation.createReview" can only be defined once.

There can be only one type named "Subscription".

Field "Subscription.reviewAdded" can only be defined once.

There can be only one type named "Episode".

Enum value "Episode.NEWHOPE" can only be defined once.

Enum value "Episode.EMPIRE" can only be defined once.

Enum value "Episode.JEDI" can only be defined once.

There can be only one type named "Character".

Field "Character.id" can only be defined once.

Field "Character.name" can only be defined once.

Field "Character.friends" can only be defined once.

Field "Character.friendsConnection" can only be defined once.

Field "Character.appearsIn" can only be defined once.

There can be only one type named "LengthUnit".

Enum value "LengthUnit.METER" can only be defined once.

Enum value "LengthUnit.FOOT" can only be defined once.

There can be only one type named "Human".

Field "Human.id" can only be defined once.

Field "Human.name" can only be defined once.

Field "Human.homePlanet" can only be defined once.

Field "Human.height" can only be defined once.

Field "Human.mass" can only be defined once.

Field "Human.friends" can only be defined once.

Field "Human.friendsConnection" can only be defined once.

Field "Human.appearsIn" can only be defined once.

Field "Human.starships" can only be defined once.

There can be only one type named "Droid".

Field "Droid.id" can only be defined once.

Field "Droid.name" can only be defined once.

Field "Droid.friends" can only be defined once.

Field "Droid.friendsConnection" can only be defined once.

Field "Droid.appearsIn" can only be defined once.

Field "Droid.primaryFunction" can only be defined once.

There can be only one type named "FriendsConnection".

Field "FriendsConnection.totalCount" can only be defined once.

Field "FriendsConnection.edges" can only be defined once.

Field "FriendsConnection.friends" can only be defined once.

Field "FriendsConnection.pageInfo" can only be defined once.

There can be only one type named "FriendsEdge".

Field "FriendsEdge.cursor" can only be defined once.

Field "FriendsEdge.node" can only be defined once.

There can be only one type named "PageInfo".

Field "PageInfo.startCursor" can only be defined once.

Field "PageInfo.endCursor" can only be defined once.

Field "PageInfo.hasNextPage" can only be defined once.

There can be only one type named "Review".

Field "Review.episode" can only be defined once.

Field "Review.stars" can only be defined once.

Field "Review.commentary" can only be defined once.

There can be only one type named "ReviewInput".

Field "ReviewInput.stars" can only be defined once.

Field "ReviewInput.commentary" can only be defined once.

Field "ReviewInput.favorite_color" can only be defined once.

There can be only one type named "ColorInput".

Field "ColorInput.red" can only be defined once.

Field "ColorInput.green" can only be defined once.

Field "ColorInput.blue" can only be defined once.

There can be only one type named "Starship".

Field "Starship.id" can only be defined once.

Field "Starship.name" can only be defined once.

Field "Starship.length" can only be defined once.

Field "Starship.coordinates" can only be defined once.

There can be only one type named "SearchResult". 

This fields are nothing related to my schema.
I'm sure I have only one schema.

@calvincestari
Copy link
Member

@DavidFerreiraYEO I've seen that error when codegen ends up finding all the test schemas we use in the repo. We have #2552 to fix that behaviour. The workaround for now is to put your schema and operation definition files in a subfolder and not the root of your project.

An example is putting them in a subfolder off the root named graphql, and then the schemaSearchPaths and operationSearchPaths could be ./graphql/**/*.graphqls and ./graphql/**/*.graphql respectively.

@DavidFerreiraYEO
Copy link

DavidFerreiraYEO commented Oct 17, 2022

@calvincestari I create the folder graphql.
I put inside the schema and operations inside:
And I got again my first query error:

Error: Cannot query field "getAuthServiceHealth" on type "undefined"
./graphql/Queries.graphql:2:2
1 | query Health {
2 | 	getAuthServiceHealth{
  |  ^
3 | 		status```

@AnthonyMDev
Copy link
Contributor

You have a schema json file so your schema search path should be ./graphql/**/*.json.

@DavidFerreiraYEO
Copy link

Hi @AnthonyMDev,

that's the reason. Thanks for your help.

@elviva404
Copy link

@elviva404 Please keep me updated. Want to make sure you're able to get this working!

Hi @AnthonyMDev it works now 💃🏾.

@sam961
Copy link

sam961 commented Oct 24, 2022

I followed the same steps ..
All are good not but the generated output doesn't include
the swift classes
Attached are screenshots
Screen Shot 2022-10-24 at 11 03 38 AM

Screen Shot 2022-10-24 at 11 03 19 AM
Screen Shot 2022-10-24 at 11 03 49 AM
Screen Shot 2022-10-24 at 11 03 29 AM

What could be the issue ?

@tlester
Copy link

tlester commented Oct 24, 2022

@AnthonyMDev @calvincestari Is there anything we can do to get v1.x working? Or is it time to punt and go back to the .59 release? I need to move on, but can't really be beta testing this right now.

I think I got the init and fetch phases done via the cli. But, the generate, is crashing hard ([1] 85763 trace trap apollo-ios-cli generate -v).

I just need good avice here. If there is a work around, I'm all for it... if not, I need to know so I can downgrade and move on. Is there any downside to the downgrade? Is it just the codegen that's different? Or is the 1.0 client better (more peformant, more stable, etc)?

@calvincestari
Copy link
Member

@sam961 I think your issues might be caused by the schemaName you're using in the config file. That name is used for namespacing and import statements; test.json seems like the filename of your actual schema file and not what you want your code generated schema to be named. Use another name and try again.

@calvincestari
Copy link
Member

@tlester, answers below

Is there anything we can do to get v1.x working? Or is it time to punt and go back to the .59 release?

I'd need to know more about what your specific issues are. I see that you reacted to this comment so if your error is the same as what SilverTab was experiencing then I believe it was resolved for him by resetting the package cache.

I think I got the init and fetch phases done via the cli. But, the generate, is crashing hard ([1] 85763 trace trap apollo-ios-cli generate -v).

Is there any other error message?

I just need good avice here. If there is a work around, I'm all for it... if not, I need to know so I can downgrade and move on. Is there any downside to the downgrade? Is it just the codegen that's different? Or is the 1.0 client better (more peformant, more stable, etc)?

Once we understand more about your specific problems we can help. This particular GitHub issue has become clouded with too many individual threads. I believe we've addressed the bugs related to this original issue in 1.0.1 and 1.0.2; the rest appear to be configuration related.

The generated code in 1.x has many improvements. The 1.x documentation can certainly be improved to offer better guidance and self-serve many of the problems reported. 0.53.0 also has limited support at the moment and an end-of-life date will be announced soon.

@calvincestari
Copy link
Member

calvincestari commented Oct 28, 2022

For anyone watching this issue and dealing with error responses that look like

Error: Cannot query field "company" on type "undefined"

#2567 has been merged and has better error responses when the schema or operation files cannot be found in the search paths. That was the root of that issue. You can link to HEAD on main for now but the fix will be included in 1.0.3.

@jhiat00
Copy link

jhiat00 commented Nov 15, 2022

We are also using Xcode to manage Swift packages, so we were also a bit confused on how to set that up. Specifically, it was unclear how we can edit the apollo-codegen-configuration.json file in Xcode. We made a little bit of progress with the SPM solution, but we are still running into issues (will go into detail below).

Possible workaround for editing configuration file when using SPM

A workaround I tried with the SPM solution was opening the apollo-codegen-configuration.json file in a TextEditor rather than Xcode, which at least allowed us to edit the file.

Schema fetching errors

But when attempting to fetch the schema, we're still running into errors.

We've tried with two working graphql endpoints and have gotten the same error with both of them. We are unclear as to if there is a problem with our configuration, or if there is a bug of some sort here.

The main error we keep getting is:

Error: A server with the specified hostname could not be found.

It also looks like its having an issue reading from a cache, as we get this error as well:

2022-10-04 14:37:29.452 apollo-ios-cli[31890:14972703] NetworkStorageDB:_openDBReadConnections: failed to open read connection to DB @ /Users/samuel.mcgarry/Library/Caches/apollo-ios-cli/Cache.db.  Error=14. Cause=unable to open database file

@sammcode were you able to get past this issue? I am currently having the same problem.

@AnthonyMDev
Copy link
Contributor

The schema fetching errors are because the SPM plugin is in a sandbox and won't allow the disk read/write and networking mechanisms of the fetch schema command to work properly. You can try passing the --disable-sandbox flag, but if that doesn't work, we recommend installing the CLI manually.

Version 1.0.4 which is coming soon removes the existing SPM plugins and instead has a single plugin command that installs the CLI, you can then use the CLI from the command line and all these SPM plugin permissions issues go away!

@elviva404
Copy link

Hi @AnthonyMDev I replaced moduleType from packageManager to embeddedInTarget and when I later ran code generation, the generated files were empty.
 However when I switch back to packageManager, the schema package is populated with files/code accordingly.


is there something I have done wrong in my setup? a prompt response would be appreciated please.

Screenshot 2022-11-29 at 7 32 30 PM

Screenshot 2022-11-29 at 7 30 09 PM

@AnthonyMDev
Copy link
Contributor

@elviva404 I've never heard reports of us generating empty files before. Try just deleting the GenSchema folder completely and then re-running code generation from a clean state with embeddedInTarget. With the config you provided, all your models should go into that folder.

@AnthonyMDev
Copy link
Contributor

I am locking this issue now. The original problem has been resolved, and people are using this closed issue as a catch-all for debugging multiple different configuration errors with code gen. This means everyone who has ever commented here (and has had their issue resolved) continues to get notifications.

If you have an problem with getting code generation working, please open a new issue.

Thank you.

@apollographql apollographql locked as resolved and limited conversation to collaborators Nov 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Generally incorrect behavior codegen Issues related to or arising from code generation
Projects
None yet