简体   繁体   中英

HotChocolate (GraphQL) ignore schema errors on query

I want to be able to "suppress" the default HotChocolate (server) behavior and ignore schema errors on query.

Let me try to give example. Let assume we do have the following schema:

type Query {
    myTypes: [MyType]
}

type MyType{
    id: ID!
    name: String
}

If I try to make query like:

{
    myTypes {
        id,
        name
    }
}

Everything is okay. However, if I make something like:

{
    myTypes {
        id,
        name,
        notKnownProperty
    }
}

The query fails. Which in general is desired behavior (the whole benefit of strict schema), but not in my particular case.

The use case is when we have 2 or more services, that expose one and the same schema (with different data) and some of those services evolve with different speed. Unfortunately we cannot control versions of those services, as some of them are on-premise. And we end up in situation where some of the services have newer versions (with more fields on the same types) than others. This restricts us to use only the oldest clients available. We would like to do the opposite - use the newest clients and handle missing fields in them (with default values for example).

One possible solution is to be implemented some sort of versioning. Either in the path (aka /graphql/v1) or in the object types itself (aka MyType1, MyType2, etc.). But I personally don't like those approaches.

Any ideas and input are appreciated

Thanks in advance

Once you want to use new clients they should be backwards compatible, ie be able to use the older versions of the API correctly. For that, it's obviously not enough to treat non-existing values like having default (null) values. It's a big difference between when your end-user doesn't have a phone number and when they has but the old API version doesn't provide it. So, you need to have a more powerful strategy to implement backwards compatibility. In case you don't want to use the versioning as it is, there are at least two other strategies available in regards to GraphQL (not only hotchocolate):

  1. Your client apps could initially analyze the scheme to check which properties are missed and decide how to build requests to the API having that knowledge.
  2. Your client apps could change their strategy on-the-fly. Ie not querying the scheme but handling the errors of queries instead. Since the errors in Graph QL are pretty structured, the client can easily understand which properties are missed and adjust the future requests accordingly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM