apollographql / apollo-ios

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

Unable to run code generation #2543

Closed ilockett closed 2 years ago

ilockett commented 2 years ago

Bug report

Installing Apollo 1.0.0 via Cocoapods results in code generation error.

Versions

Please fill in the versions you're currently using:

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 commented 2 years ago

Just ran into the same issue 😕

calvincestari commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

Hi, The same issue here.

ibragimovscode1 commented 2 years ago

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

teendream commented 2 years ago

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

indama commented 2 years ago

I tried installing via Package manager. When I add ApolloCodegenLib I have some errors.

Screenshot at Oct 04 16-32-27
calvincestari commented 2 years ago

@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 commented 2 years ago

@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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

@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 commented 2 years ago

@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 commented 2 years ago

@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 commented 2 years ago

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 commented 2 years ago

@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 commented 2 years ago

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 commented 2 years ago

@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 commented 2 years ago

@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 commented 2 years ago

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

AnthonyMDev commented 2 years ago

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 commented 2 years ago

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

calvincestari commented 2 years ago

Anyone who's watching this issue for a fix to the original issue of Fatal error: could not load resource bundle when using CocoaPods; the fix (#2548) has been merged with so if you point your Pod to the HEAD of main it should work for you now.

We've got a couple other fixes we want to get into main before publishing a 1.0.1 release.

indama commented 2 years ago

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

I have one more question. I am working through documentation. After downloaded schema.json

I am running this two command: ./Pods/Apollo/apollo-ios-cli init --schema-name ${MySchemaName} ./Pods/Apollo/apollo-ios-cli generate

QUESTION: Is apallo-ios-cli automatically finds the schema.json file?

When I run generate function command I am getting error:

Error: Cannot query field "activate" on type "undefined" .../Activate.graphql:2:5

Here is my .graphql file

mutation activate($phone: String!, $deviceId: String!, $deviceName: String!, $otp: String!, $trusted: Boolean!) { activate(phone: $phone, deviceId: $deviceId, deviceName: $deviceName, deviceType: 1, otp: $otp, trusted: $trusted) { errors { message code sec } message token } }

creednmd commented 2 years ago

I'm seeing similar errors to @sammcode when trying to run apollo-fetch-schema on the command line to download my schema.

swift package --allow-writing-to-package-directory apollo-fetch-schema -v --path "Sources/GraphQLClient/apollo-codegen-config.json"

[DEBUG - ApolloCodegenLib:ApolloSchemaDownloader.swift:327] - Downloading schema via introspection from https://server.com/graphql
2022-10-06 15:19:12.581 apollo-ios-cli[22137:969991] NetworkStorageDB:_openDBReadConnections: failed to open read connection to DB @ /Users/myname/Library/Caches/apollo-ios-cli/Cache.db.  Error=14. Cause=unable to open database file
2022-10-06 15:19:12.581 apollo-ios-cli[22137:969991] The read-connection to the DB=/Users/myname/Library/Caches/apollo-ios-cli/Cache.db is NOT valid.  Unable to determine schema version.
2022-10-06 15:19:12.581 apollo-ios-cli[22137:969991] NetworkStorageDB:_openDBWriteConnections: failed to open write connection to DB @ /Users/myname/Library/Caches/apollo-ios-cli/Cache.db.  Error=14. Cause=unable to open database file
2022-10-06 15:19:12.581 apollo-ios-cli[22137:969991] DEBUG: there is no SQL cache DB located at /Users/myname/Library/Caches/apollo-ios-cli/Cache.db.
2022-10-06 15:19:12.581 apollo-ios-cli[22137:969991] DEBUG: there is no SQL cache DB located at /Users/myname/Library/Caches/apollo-ios-cli/Cache.db-shm.
2022-10-06 15:19:12.581 apollo-ios-cli[22137:969991] DEBUG: there is no SQL cache DB located at /Users/myname/Library/Caches/apollo-ios-cli/Cache.db-wal.
Error: A server with the specified hostname could not be found.

Running with:

.package(url: "https://github.com/apollographql/apollo-ios.git", branch: "main")

Have tried it without --path, running swift package --allow-writing-to-package-directory apollo-initialize-codegen-config --schema-name "mySchemeName" first, which successfully creates sample config file. Have created config file entry for correct (working) URL for graphQL endpoint, along with various other dead-ends. All end up with cache errors and Error: A server with the specified hostname could not be found..

creednmd commented 2 years ago

After bit more digging—including closed issues (thanks Andy Kent)—figured it was a sandbox issue, and this sorts it:

swift package --disable-sandbox --allow-writing-to-package-directory apollo-fetch-schema -v --path "Sources/GraphQLClient/apollo-codegen-config.json"

(Note that --disable-sandbox must come before --allow-writing-to-package-directory.)

creednmd commented 2 years ago

OK, got the schema downloading, but when I run the generate command I get another raft of errors:

swift package --allow-writing-to-package-directory apollo-generate -v --path "Sources/GraphQLClient/apollo-codegen-config.json"

Building for debugging...
[196/196] Linking apollo-ios-cli
Build complete! (2.92s)
[DEBUG - ApolloCodegenLib:Glob.swift:116] - Expanding globstar **/*.graphqls
[DEBUG - ApolloCodegenLib:Glob.swift:180] - Expanded to /Users/myname/dev/pixplay/Sources/GraphQLClient/*.graphqls
[DEBUG - ApolloCodegenLib:Glob.swift:194] - Matching /Users/myname/dev/pixplay/Sources/GraphQLClient/*.graphqls
[DEBUG - ApolloCodegenLib:Glob.swift:116] - Expanding globstar **/*.graphql
[DEBUG - ApolloCodegenLib:Glob.swift:180] - Expanded to /Users/myname/dev/pixplay/Sources/GraphQLClient/*.graphql
[DEBUG - ApolloCodegenLib:Glob.swift:194] - Matching /Users/myname/dev/pixplay/Sources/GraphQLClient/*.graphql
[DEBUG - ApolloCodegenLib:Glob.swift:208] - Matched /Users/myname/dev/pixplay/Sources/GraphQLClient/schema.graphql
ApolloCodegenLib/JavaScriptBridge.swift:343: Precondition failed: Expected JavaScript array but found: undefined
creednmd commented 2 years ago
{
  "schemaName" : "myScheme",
  "input" : {
    "operationSearchPaths" : [
      "**/*.graphql"
    ],
    "schemaSearchPaths" : [
      "**/*.graphqls"
    ]
  },
  "output" : {
    "testMocks" : {
      "none" : {
      }
    },
    "schemaTypes" : {
      "path" : "./Sources/GraphQLClient",
      "moduleType" : {
        "swiftPackageManager" : {
        }
      }
    },
    "operations" : {
      "relative" : {
      }
    }
  },
  "schemaDownloadConfiguration": {
      "downloadMethod": {
          "introspection": {
              "endpointURL": "https://example.com/graphql",
              "httpMethod": {
                  "POST": {}
              },
              "includeDeprecatedInputValues": false,
              "outputFormat": "SDL"
          }
      },
      "downloadTimeout": 60,
      "headers": [
          { "key": "x-api-key", "value": "DEADBEEF" },
          { "key": "Authorization", "value": "Bearer DEADBEEF" }
      ],
      "outputPath": "./Sources/GraphQLClient/schema.graphql"
  }
}
elviva404 commented 2 years ago

@creednmd Thank you so much, fetching the schema with a disabled sandbox also resolved my issue.

AnthonyMDev commented 2 years ago

It looks like in order to make network requests, the CLI may need to be run with the sandbox disabled. This was not clear to us from Apple’s (very limited) documentation on the switch package plug-in API. We’re going to do some more digging and update the documentation. Thanks do much to everyone who has helped dig into this issue so far!

I’m going to look into if there is a better/easier way for use to deploy the CLI. We felt that a swift package plug-in was the most user friendly way to do this, but it’s looking like the SPM plug-in system is still not mature enough to provide an experience here that is up to our standards.

I genuinely apologize to all of you who have started to attempt the migration to what we felt was a stable 1.0 version and have hit these issues. We’re going to spend time this coming week figuring out what the right option is for making code generation as seamless as possible for all of you.

creednmd commented 2 years ago

Looks like my generate errors were self-inflicted, and due to one or two paths being wrong, such that it was not finding any graphQL files, and passing an empty array; maybe a more accurate error than 'Precondition failed: Expected JavaScript array but found: undefined' would be in order. But despite all the trouble, have got it all migrated and working again.

calvincestari commented 2 years ago

That's great to read @creednmd, glad it's now working for you again. The CLI init command creates the config file with defaults that are very basic. So depending on your specific project setup you may need to adjust those values. Maybe that's a message worth adding to the end of the init command output.

calvincestari commented 2 years ago

Once #2554 is merged I believe we've fixed all the root causes in this issue, the others seem to be user configuration related. Maybe we can get in another one or two other issues before publishing 1.0.1.

elviva404 commented 2 years ago

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

I have one more question. I am working through documentation. After downloaded schema.json

I am running this two command: ./Pods/Apollo/apollo-ios-cli init --schema-name ${MySchemaName} ./Pods/Apollo/apollo-ios-cli generate

QUESTION: Is apallo-ios-cli automatically finds the schema.json file?

When I run generate function command I am getting error:

Error: Cannot query field "activate" on type "undefined" .../Activate.graphql:2:5

Here is my .graphql file

mutation activate($phone: String!, $deviceId: String!, $deviceName: String!, $otp: String!, $trusted: Boolean!) { activate(phone: $phone, deviceId: $deviceId, deviceName: $deviceName, deviceType: 1, otp: $otp, trusted: $trusted) { errors { message code sec } message token } }

Hi, I also have an issue similar to this please.

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

/{PATH}/ExampleQuery.graphql:2:3
1 | query Query {
2 |   company {
  |   ^
3 |     ceo

My Query file ExampleQuery.graphql

query Query {
  company {
    ceo
  }
  roadster {
    apoapsis_au
  }
}
elviva404 commented 2 years ago

@AnthonyMDev can you kindly assist me with the issue above.

AnthonyMDev commented 2 years ago

@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 commented 2 years ago

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 commented 2 years ago

Thanks

AnthonyMDev commented 2 years ago

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

ilockett commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

@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 commented 2 years ago

@calvincestari

Screenshot 2022-10-14 at 15 43 21

It works on GraphiQL.

AnthonyMDev commented 2 years ago

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 commented 2 years ago

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

steps I have done:

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 commented 2 years ago

@DavidFerreiraYEO I've seen that error when codegen ends up finding all the test schemas we use in the repo. We have https://github.com/apollographql/apollo-ios/issues/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 commented 2 years ago

@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```