Graphql-dotnet: ObjectGraphTypes are somehow removed from Schema if they are only used via Interfaces

Created on 15 Sep 2016  路  2Comments  路  Source: graphql-dotnet/graphql-dotnet

Please have a look at my Business Model below and how I translated it to the GraphQL Structure.
image

I converted my inheritance structure to a set of interfaces.

This allows me to have a _SearchDocument_ Field on my Query. This field has a type of IDocument. The beauty of this approach is that I can query this field and use _inline fragments_ to select the required structure. For example, the following Inline Fragment is used to render LegalDocuments _and_ PurchaseContracts:

...on ILegalDocument{ ContactDate }

So I used interfaces in my schema wherever possible to enable these kinds of queries.
By doing this, I found a strange behaviour:

If a schema exposes only InterfaceGraphTypes in its Query fields and no longer mentions any ObjectGraphTypes, then then this has the following undesired consequences:

  • In GraphiQl, the ObjectGraphTypes are no longer visible.
  • Queries cannot be rendered correcty. Objects are shown as null, with no properties whatsoever.

I can work around this problem by creating "dummy Fields" which declare a return type of every ObjectGraphType, but this seems like a hack to me. Is this a feature or a bug?

question

All 2 comments

This is intended. You have to register those types manually with the Schema. There is a RegisterType method on the Schema class.

Works like a Charm. Thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Walid-Abdulrazik picture Walid-Abdulrazik  路  3Comments

VladimirAkopyan picture VladimirAkopyan  路  4Comments

dharmeshtailor picture dharmeshtailor  路  4Comments

joemcbride picture joemcbride  路  4Comments

phoenixjun picture phoenixjun  路  4Comments