Error Cannot find 'HeroNameQuery' in scope + iOS + Xcode 14

[4. Setup and run code generation] - Working fine

./Pods/Apollo/apollo-ios-cli init --schema-name schemaGraphQL --module-type other

Running this command creates an apollo-codegen-config.json file.

./apollo-ios-cli generate

[5. Create an ApolloClient] - Working fine

import Foundation
import Apollo

let apolloClient = ApolloClient(url: URL(string: “http://localhost:4000/graphql”)!)

[6. Fetch a query]

After writing
apolloClient.fetch(query: HeroNameQuery) { result in
guard let data = try? result.get().data else { return }
print( // Luke Skywalker

Error Cannot find ‘HeroNameQuery’ in scope

Can anyone help me why I am getting the above error?

Hi @Saumil_Shah :wave: - using the other module type is telling the code generation engine that you’re going to be responsible for creating a dependency package where the code is generated to. Where you’re then trying to use HeroNameQuery you will need to import the module that you’re creating.

I suggest reading over the project configuration guide to understand how the modules are created.

Hello @calvincestari

Thank you for your answer. I got the solution from project configuration guide URL.

swiftPackageManager will create the module for you, then you add the new package as an SPM dependency.

I still suggest reading over the documentation to understand how these settings affect the schema module creation.