import { ApolloLink } from "@apollo/client/link";
import { compact } from "@apollo/client/utilities/internal";
export class ClientAwarenessLink extends ApolloLink {
    constructor(constructorOptions = {}) {
        super((operation, forward) => {
            const client = operation.client;
            const clientOptions = client["queryManager"].clientOptions;
            const context = operation.getContext();
            {
                const { name, version, transport = "headers", } = compact({}, clientOptions.clientAwareness, constructorOptions.clientAwareness, context.clientAwareness);
                if (transport === "headers") {
                    operation.setContext(({ headers, extensions }) => {
                        return {
                            headers: 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" } = compact({}, clientOptions.enhancedClientAwareness, constructorOptions.enhancedClientAwareness);
                if (transport === "extensions") {
                    operation.extensions = 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);
        });
    }
}
//# sourceMappingURL=ClientAwarenessLink.js.map
