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

RootEntityType Compilation Error when field name conflicts with Operation name #3036

Closed
jriosdev opened this issue May 22, 2023 · 8 comments
Closed
Assignees
Labels
bug Generally incorrect behavior codegen Issues related to or arising from code generation needs investigation

Comments

@jriosdev
Copy link

jriosdev commented May 22, 2023

Summary

'Data' is not a member type of struct 'SchemaName.QueryName.Data.QueryName.Result'

while generating code in 1.1.0
public typealias RootEntityType = QueryName.Result
after the update generating code in 1.2.0
public typealias RootEntityType = QueryName.Data.QueryName.Result

Screenshot 2023-05-22 at 4 57 42 PM Screenshot 2023-05-22 at 4 58 01 PM

Version

1.2.0

Steps to reproduce the behavior

The issue does not exhibit with all models, so far it seems like its only inline union types

code gen config
{ "schemaNamespace" : "Schema", "input" : { "operationSearchPaths" : [ "**/*.graphql" ], "schemaSearchPaths" : [ "**/*.graphqls" ] }, "output" : { "testMocks" : { "none" : { } }, "schemaTypes" : { "path" : "../../../../Schema", "moduleType" : { "swiftPackageManager" : { } } }, "operations" : { "inSchemaModule" : { } } } }

Logs

No response

Anything else?

No response

@jriosdev jriosdev added bug Generally incorrect behavior needs investigation labels May 22, 2023
@AnthonyMDev AnthonyMDev added this to the Patch Releases (1.x.x) milestone May 23, 2023
@AnthonyMDev AnthonyMDev changed the title RootEntityType type miss match after updated from 1.1.0 to 1.2.0 RootEntityType Compilation Error when field name conflicts with Operation name May 23, 2023
@AnthonyMDev
Copy link
Contributor

Thanks for the report. I see exactly what's going on here. Your query is named AirportAndCityAutocompleteQuery, but it includes a field called airportAndCityAutocompleteQuery, which is generating a selection set named AirportAndCityAutocompleteQuery inside of the operation definition (which is also defined with the name AirportAndCityAutocompleteQuery)! 🤯 It's a query-ception!

We will discuss how we can address this for the future, either by handling the generated naming differently or by throwing a validation error during code generation if we detect this situation.

In the mean time, the simple workaround for you is to put a field alias on the airportAndCityAutocompleteQuery field in your operation.

query AirportAndCityAutocomplete($searchString: String!) {
  searchResult: airportAndCityAutocompleteQuery(searchString: $searchString) {
    ...
  }
}

Of course the alias searchResult can be whatever you want it to be. This alias will change the response data internal struct to be AirportAndCityAutocompleteQuery.Data.SearchResult and the field name on the response data object would change from airportAndCityAutocompleteQuery to searchResult.

@AnthonyMDev AnthonyMDev added the codegen Issues related to or arising from code generation label Jun 14, 2023
@iAmericanBoy
Copy link

I might be running into the same or something similar on 1.3.0:
'Analysis' is not a member type of struct 'M1Schema.ApolloPortfolioTopSlice.AsRootPortfolioSlice.To.AsUserPie'
Screenshot 2023-07-05 at 7 02 33 PM

we have a query called PortfolioSlice that also has a type alias node:

query PortfolioSlice(...) {
  PortfolioSlice: node(...) {
    ... ApolloPortfolioTopSlice
  }
 fragment ApolloPortfolioTopSlice on PortfolioSlice {
  to {
    ...on UserPie {
...
      analysis {
      ...
      }
	}
    ...on SystemPie {
      analysis {
      ...
      }
    }
  }
} 
...

but after changing that node type alias name it is still happening so im not sure if its not related. is it maybe because we have two fields called analysis in that fragment? Happy to share more of schema/query privately

@AnthonyMDev
Copy link
Contributor

@iAmericanBoy, thanks for the additional example. I'm not sure what's going on in your case exactly. If you are able to share a schema/query with me you can send it to [email protected]. That would help out immensely.

@iAmericanBoy
Copy link

Thank you! I’ll send it tomorrow morning! I was able to move on from the error by commenting out both analysis sections from the query. So there’s definitely something wrong with how we are doing this.

@calvincestari calvincestari added the planned-next Slated to be included in the next release label Jul 13, 2023
@iAmericanBoy
Copy link

@AnthonyMDev Do you have any updates on this? I know its summer vacation everywhere else too, so I just wanted to see if you need anything else from me to get this reproduced.

@AnthonyMDev
Copy link
Contributor

Hi @iAmericanBoy, I've been working on a few other time sensitive things, but I am planning on looking at this one in more depth this week! Sorry we haven't gotten a resolution for you yet.

@AnthonyMDev
Copy link
Contributor

@iAmericanBoy, the issue you highlighted here is not related to the name conflict that this issue is about. However I have figured out the underlying cause for this one and got a fix up for it in #3168!

@AnthonyMDev AnthonyMDev removed the planned-next Slated to be included in the next release label Aug 1, 2023
@bignimbus
Copy link
Contributor

Closing this as resolved via #3168 🚀

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 needs investigation
Projects
None yet
Development

No branches or pull requests

5 participants