Zaid-Ajaj / Snowflaqe

A dotnet CLI to generate type-safe GraphQL clients for F# and Fable with automatic deserialization, static query verification and type checking
MIT License
154 stars 25 forks source link

Bypass validation of introspection with dummy ResolveType #71

Closed MargaretKrutikova closed 2 years ago

MargaretKrutikova commented 2 years ago

Fixes #70 .

When converting from schema in SDL (.graphql) to json using the introspection query with fromSchemaDefinition it doesn't seem to work if the schema has either interfaces or unions. The reason behind this is that graphql-dotnet expects to see either ResolveType on the parent type (union or interface) or IsTypeOf on the union cases/interface implementations. And when doing GraphQL.Types.Schema.For(definition) both ResolveType and IsTypeOf end up being null which later makes the introspection query in fromSchemaDefinition fail with InvalidOperationException. SchemaTypes from graphql-dotnet throws exception for union types and for interface types.

This is not applicable in case of introspection query when no actual data is involved and there is nothing to resolve, which is the case with fromSchemaDefinition. We bypass the validation by always providing a dummy ResolveType which is only used for interfaces and unions to resolve mapping between the actual data and the corresponding GraphTypes when creating a graphql api with graphql-dotnet.

Zaid-Ajaj commented 2 years ago

Thank a lot @MargaretKrutikova for investigating the problem and for the fix 🙏 I've merged your PR and published Snowflaqe v1.37 🚀 please take it for a spin and let me know if you encounter any issues