apollographql / apollo-ios

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

Error: GraphQLSchemaValidationError: Unknown type "String". #3242

Closed rehatkathuria closed 1 year ago

rehatkathuria commented 1 year ago

Summary

I am having an issue resolving my graphql file with the generate function

Version

1.5.0

Steps to reproduce the behavior

My fetched schema resolves the queries in my file as the following:

type Query {
...
  getUser(id: String!): UserObject!
...
}

I have a .graphql file as the following:

query GetUser($identifier: String!) {
    getUser(identifier: $identifier) {
        name
    }
}

When running ./apollo-ios-cli generate using version 1.5.0 I am presented with the following error: Error: GraphQLSchemaValidationError: Unknown type "String".

Logs

No response

Anything else?

No response

BobaFetters commented 1 year ago

@rehatkathuria I don't see anything standing out from what you have posted to give this error, it does look like getUser(identifier: $identifier) should be getUser(id: $identifier) based on your schema. Although that wouldn't present this specific error. Can you provide a small sample schema and operation that would present this issue that we could use to debug and see what the issue is?

rehatkathuria commented 1 year ago

It's occurring specifically on the ./apollo-ios-cli generate command and nowhere else. The studio explorer behaves as expected with the operations.

Here's an example repository: https://github.com/rehatkathuria/ApolloGraphCLICodeExample

rehatkathuria commented 1 year ago

Navigating to the Networking folder and running ./apollo-ios-cli generate will give you the following error: Error: GraphQLSchemaValidationError: Unknown type "String".

BobaFetters commented 1 year ago

Thanks for providing that, I will take a look!

BobaFetters commented 1 year ago

@rehatkathuria was able to get your sample project working by making sure the schemaSearchPaths in your codegen config uses the .graphqls file extension which is used for schema files like this:

"input" : {
    "operationSearchPaths" : [
      "**/*.graphql"
    ],
    "schemaSearchPaths" : [
      "**/*.graphqls"
    ]
  }

and then ensuring the graphl-schema file has the .graphqls file extension.

rehatkathuria commented 1 year ago

That solved it, thank you!

calvincestari commented 1 year ago

Good catch @BobaFetters.

@rehatkathuria, the technical reason here is that the codegen engine is finding your operation file, trying to parse it as a schema and then erroring out. If you want to use the wildcard search paths "**/*. then you have to use distinct subpaths or extensions to disambiguate the files.