Skip to content

Preserve property shape when parent is null #424

Closed
@tkers

Description

@tkers

Maybe slightly related to #421, but from the client's perspective rather than enforcing the field inclusion from the server side.

I noticed leebyron stating:

I don't think this is a good idea since it reduces a client's ability to predict the shape of the response

For an issue I recently ran into; how about including (nullable) fields that the client specifically requests? This is especially relevant for fields that have a specific type/shape defined, it feels a bit weird that the parent property can be omitted completely.

e.g. we have a nested profile.settings.someValue property, where we explicitly define the profileType to contain a settingsType, and explicitly list all the keys in the settingsType (rather than just using a generic object type). Now, whenever the database fetches a resource where profile.settings is not (yet) defined (maybe new profiles that have no explicit values set for the keys yet), settings will be omitted completely. This causes a query for profile { settings { someValue } } to not return anything, leaving the client to handle checking if the full tree of (sub)properties exists.

A way to solve this at the moment is to provide a default value { } for settings, or making sure that the underlying database has all fields properly defined to begin with, but to me this felt a bit awkward.

Is it possible to make sure the shape of the object is preserved even when all the leaf-values are null? Or would this be too language-specific or even conceptually not making sense to do?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions