"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ClientAwarenessLink = void 0;
const link_1 = require("@apollo/client/link");
const internal_1 = require("@apollo/client/utilities/internal");
class ClientAwarenessLink extends link_1.ApolloLink {
    constructor(constructorOptions = {}) {
        super((operation, forward) => {
            const client = operation.client;
            const clientOptions = client["queryManager"].clientOptions;
            const context = operation.getContext();
            {
                const { name, version, transport = "headers", } = (0, internal_1.compact)({}, clientOptions.clientAwareness, constructorOptions.clientAwareness, context.clientAwareness);
                if (transport === "headers") {
                    operation.setContext(({ headers, extensions }) => {
                        return {
                            headers: (0, internal_1.compact)(
                            // setting these first so that they can be overridden by user-provided headers
                            {
                                "apollographql-client-name": name,
                                "apollographql-client-version": version,
                            }, headers),
                        };
                    });
                }
            }
            {
                const { transport = "extensions" } = (0, internal_1.compact)({}, clientOptions.enhancedClientAwareness, constructorOptions.enhancedClientAwareness);
                if (transport === "extensions") {
                    operation.extensions = (0, internal_1.compact)(
                    // setting these first so that it can be overridden by user-provided extensions
                    {
                        clientLibrary: {
                            name: "@apollo/client",
                            version: client.version,
                        },
                    }, operation.extensions);
                }
            }
            return forward(operation);
        });
    }
}
exports.ClientAwarenessLink = ClientAwarenessLink;
//# sourceMappingURL=ClientAwarenessLink.cjs.map
