Class ExtensionsBuilder


  • @PublicApi
    public class ExtensionsBuilder
    extends java.lang.Object
    This class can be used to help build the graphql `extensions` map. A series of changes to the extensions can be added and these will be merged together via a ExtensionsMerger implementation and that resultant map can be used as the `extensions`

    The engine will place a ExtensionsBuilder into the GraphQLContext (if one is not manually placed there) and hence DataFetchers can use it to build up extensions progressively.

    At the end of the execution, the ExtensionsBuilder will be used to build a graphql `extensions` map that is placed in the ExecutionResult

    • Method Detail

      • newExtensionsBuilder

        public static ExtensionsBuilder newExtensionsBuilder()
        Returns:
        a new ExtensionsBuilder using a default merger
      • newExtensionsBuilder

        public static ExtensionsBuilder newExtensionsBuilder​(ExtensionsMerger extensionsMerger)
        This creates a new ExtensionsBuilder with the provided ExtensionsMerger
        Parameters:
        extensionsMerger - the merging code to use
        Returns:
        a new ExtensionsBuilder using the provided merger
      • getChangeCount

        public int getChangeCount()
        Returns:
        how many extension changes have been made so far
      • addValues

        public ExtensionsBuilder addValues​(@NotNull
                                           @NotNull java.util.Map<java.lang.Object,​java.lang.Object> newValues)
        Adds new values into the extension builder
        Parameters:
        newValues - the new values to add
        Returns:
        this builder for fluent style reasons
      • addValue

        public ExtensionsBuilder addValue​(@NotNull
                                          @NotNull java.lang.Object key,
                                          @Nullable
                                          @Nullable java.lang.Object value)
        Adds a single new value into the extension builder
        Parameters:
        key - the key in the extensions
        value - the value in the extensions
        Returns:
        this builder for fluent style reasons
      • buildExtensions

        public java.util.Map<java.lang.Object,​java.lang.Object> buildExtensions()
        This builds an extensions map from this builder, merging together the values provided
        Returns:
        a new extensions map
      • setExtensions

        public ExecutionResult setExtensions​(ExecutionResult executionResult)
        This sets new extensions into the provided ExecutionResult, overwriting any previous values
        Parameters:
        executionResult - the result to set these extensions into
        Returns:
        a new ExecutionResult with the extensions values in this builder