swift-graphql icon indicating copy to clipboard operation
swift-graphql copied to clipboard

How to debug codegen errors?

Open robertherber opened this issue 10 months ago • 1 comments

I'm getting an error when running swift-graphql, but I can't seem to find a way to get a more descriptive error message?

swift-graphql https://healthcloud.kingstinct.dev/graphql --config swiftgraphql.yml --output graphql.generated.swift

This is all I see (the red background indicates that the command exited with a non-zero exit code): Screenshot 2024-04-07 at 13 32 10

How do I proceed?

robertherber avatar Apr 07 '24 11:04 robertherber

I encountered the same issue as described in issue #203. I found that the crash was due to the force unwrapped line in Fragments.swift:

private var mock: String {
    return self.first!.namedType.name.camelCasePreservingSurroundingUnderscores
}

To resolve this, I unwrapped the value safely. If it couldn't be unwrapped, I returned a value that I could search for within the file, which helped me identify the relevant parts of my schema to investigate further. This led me to discover issues with interfaces that were defined in the schema but never used. Once these unused interfaces were removed from the schema, the code generation worked as expected.

Next steps might be to check if the mock value exists before adding the selecting case and removing the force unwrap, but I don't know what the repercussions of that would be in practice.

merlin910 avatar Jul 23 '24 14:07 merlin910