apollographql / apollo-ios

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

Failure to generate `ApolloCodegenLib/JavaScriptBridge.swift:343: Precondition failed: Expected JavaScript array but found: undefined` #3047

Closed trevor-holliday-instacart closed 1 year ago

trevor-holliday-instacart commented 1 year ago

Question

I am working on migrating an Apollo setup from 0.48.0 to 1.0.0

I have setup a config file that reads as follows

{ "schemaName": "GraphQLSchema", "input": { "operationSearchPaths": [ "Dir1/**/*.graphql", "Dir2/**/*.graphql", "Dir3/**/*.graphql" ], "schemaSearchPaths": [ "**/*.graphqls" ] }, "output": { "testMocks": { "none": {} }, "schemaTypes": { "path": "./GraphQLSchema", "moduleType": { "swiftPackageManager": {} } }, "operations": { "inSchemaModule": {} } }, "schemaDownloadConfiguration": { "downloadMethod": { "introspection": { "endpointURL": "URL", "httpMethod": { "POST": {} }, "includeDeprecatedInputValues": false, "outputFormat": "SDL" } }, "downloadTimeout": 60, "headers": [ { "Authorization": "<TOKEN>" } ], "outputPath": "./schema.graphqls" } }

I am able to properly fetch the schema, and it is stored in the project. However, when I attempt to run generation it fails with ApolloCodegenLib/JavaScriptBridge.swift:343: Precondition failed: Expected JavaScript array but found: undefined.

I can see in the console using verbose that the CodegenLib is matching on proper graphql files.

I believe I have something wrong with my config file, but I am unsure what it is.

calvincestari commented 1 year ago

Hi @trevor-holliday-instacart, the config looks fine. If it's getting to the point of fetching the schema then the config has already been validated so it's not likely a value in the config file causing the error. The code in question (ApolloCodegenLib/JavaScriptBridge.swift:343) is at the point where the config has been validated, the schema and operations parsed by graphql-js and the Swift code generation engine is attempting to create the AST we feed into the output templates.

It's going to be something in the schema/operation that is unexpected. Are you able to share the schema/operations privately for us to debug? If you can then send it to me at calvin.cestari[at]apollographql.com and we'll take a look at it.

trevor-holliday-instacart commented 1 year ago

Hi @calvincestari , I am unsure if I am able to share the files yet. I will get back to you on that. Could it be something to do with custom scalars? I saw in the migration guide I needed to setup extensions for them, but I assumed that would be after the generation ran?

calvincestari commented 1 year ago

but I assumed that would be after the generation ran?

Correct, custom scalars will only be for you to handle once the generated files have been output already.

Given that you shared the JSON config I assume you're using the CLI at the moment? An alternative way for you to debug would be to use ApolloCodegenLib in a project that you can run with breakpoints to narrow down on exactly which part of the schema/operation it's failing at.

trevor-holliday-instacart commented 1 year ago

That sounds like a plan. Do you have a link for which project I should clone?

calvincestari commented 1 year ago

I don't think we have one readily available but I can probably put one together quickly. Let me see what I can do..

trevor-holliday-instacart commented 1 year ago

Could I just clone the main apollo repo and shim something in that way?

calvincestari commented 1 year ago

You could probably wrestle one of the codegen configuration tests into doing what you need.

trevor-holliday-instacart commented 1 year ago

Seeing what I can do. The Schema file is quite large and the operations are broken down across multiple files.

calvincestari commented 1 year ago

OK, here's a very quick project that uses a local schema/operation but you can substitute those with your own in-place - ManualCodegen.zip

calvincestari commented 1 year ago

Hi @trevor-holliday-instacart, have you had any success with debugging which part of the schema/operations is causing the issue? Was that sample project helpful?

trevor-holliday-instacart commented 1 year ago

Hi @calvincestari I got delayed working this portion up. I will close for this for now as the mock project will be able to assist me with debugging issues.