Skip to content

DataFetchingFieldSelectionSet getImmediateFields incurs cost of traversing the entire sub-tree to build glob-patterns #3854

@timward60

Description

@timward60

Our current GraphQL implementation relies heavily on using DataFetchingFieldSelectionSet (based on this guidance). Our service architecture has a GraphQL gateway with multiple micro-services that we call out. These micro-service APIs support selection of properties when fetching data, e.g. /user?$select=(displayName,birthDate). Our resolver implementations will use DataFetchingFieldSelectionSet to map the incoming client query fields to these properties.

Unfortunately the current implementation of DataFetchingFieldSelectionSet set is reconstructed (the entire subtree) for each field resolver, and again each time a child is traversed using the data fetching selection set (using getImmediateFields()[0].getSelectionSet(), ...).

Fortunately the ExecutableNormalizedOperation which is memoized for each request, however when DataFetchingFieldSelectionSet is built it uses this object and in addition traverses the entire sub-tree to build up the glob-patterns, however our use-case is mostly restricted to the immediate children fields, which means we occur the cost of traversing the each field-subtree each time a field resolver requests the selection set.

I have an associated PR that addresses this by making the computation of immediate fields limited, and only if the other methods are used is the entire sub-tree glob-patterns calculated. Opening this to track/discuss the feature/performance/behavior change.

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