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

Cannot find type 'graphQLSchema' in scope. #2705

Closed
iAmericanBoy opened this issue Dec 7, 2022 · 8 comments · Fixed by #2730
Closed

Cannot find type 'graphQLSchema' in scope. #2705

iAmericanBoy opened this issue Dec 7, 2022 · 8 comments · Fixed by #2730
Assignees
Labels
bug Generally incorrect behavior codegen Issues related to or arising from code generation

Comments

@iAmericanBoy
Copy link

Bug report

I followed the new migration guide coming with 1.0.6 and it helped me finally generate all the correct files for our queries and mutations. Thank you for the detailed guide!

However after dragging the swift package into our Xcode I'm running into some circular dependencies and Xcode errors around not being able to find the schema package in the source files. Are there plans to add more documentation of how to use the new Package integration?

Versions

Please fill in the versions you're currently using:

  • apollo-ios SDK version: 1.0.5
  • Xcode version: 14.1
  • Swift version: 5
  • Package manager: SPM

Steps to reproduce

generate code with this configuration file. and dragged the package into our Xcode project

{
  "schemaName" : "graphQLSchema",
  "input" : {
    "operationSearchPaths" : [
      ".../Apollo/**/*.graphql"
    ],
    "schemaSearchPaths" : [
      ".../ios/graphQLSchema.graphqls"
    ]
  },
  "output" : {
    "testMocks" : {
      "none" : {
      }
    },
    "schemaTypes" : {
      "path" : ".../Apollo/GraphQLSchema",
      "moduleType" : {
        "swiftPackageManager" : {
        }
      }
    },
    "operations" : {
      "inSchemaModule" : {
      }
    }
  }
}

Further details

Here is the error we are seeing in the generated files:
Screenshot 2022-12-07 at 9 58 50 AM

@calvincestari
Copy link
Member

Hi @iAmericanBoy - this looks like a casing problem. The correct casing of the schema namespace is shown on line 19 in that screenshot. I believe if you were to capitalize it to GraphQLSchema it would build as expected. Why it's not capitalized is the real question?!

Are you able to replicate this behaviour in a sample project? Is ApolloBorrowDisclosure a fragment?

@calvincestari
Copy link
Member

calvincestari commented Dec 12, 2022

Can you also confirm whether this bug occurs even after deleting all previously generated files and regenerating?

@iAmericanBoy
Copy link
Author

Correct ApolloBorrowDisclosure is one of our fragments. I was seeing the same error message in many files though.

"path" : ".../Apollo/GraphQLSchema" I capitalized it here since that is a folder path but our schema is a file so it's lowercase. Correct all the old files are deleted. I have not checked if this happens in a sample project

@calvincestari
Copy link
Member

calvincestari commented Dec 13, 2022

Correct ApolloBorrowDisclosure is one of our fragments.

OK, I can try replicate this error using fragments, I was not able to earlier with just a very simple test schema.

"path" : ".../Apollo/GraphQLSchema" I capitalized it here since that is a folder path but our schema is a file so it's lowercase. Correct all the old files are deleted.

No, I wasn't clear enough earlier with my message "if you were to capitalize it to GraphQLSchema it would build as expected". I meant on line 6 where you're getting the compilation error; if that were capitalized it should build as expected. It shouldn't matter what your schema file is named, rather the schema name you use in the codegen configuration, and there is logic to always capitalize that so I'm confused why it's being generated with the first character lowercased here.

@calvincestari calvincestari self-assigned this Dec 13, 2022
@iAmericanBoy
Copy link
Author

your right if I change the schema name to this in the configuration json it builds correctly.
"schemaName" : "GraphQLSchema",

@calvincestari
Copy link
Member

Oh that's weird, but it points to a place where I suspect the schema name is not being capitalized correctly - thanks!

@calvincestari calvincestari added bug Generally incorrect behavior codegen Issues related to or arising from code generation and removed needs investigation labels Dec 14, 2022
@calvincestari calvincestari added this to the Release 1.0.6 milestone Dec 14, 2022
@calvincestari
Copy link
Member

@iAmericanBoy I've got a fix up for this in PR #2730. It'll get merged to main soon and be generally available in the next release. Thanks for the help narrowing down on the issue.

@iAmericanBoy
Copy link
Author

Thank you for that quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Generally incorrect behavior codegen Issues related to or arising from code generation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants