/

  • Analyticsnpmv15.2.1

    • Overview
  • Apollonpmv15.2.1ESM

    • Overview
  • Browserslist-confignpmv15.2.1

    • Overview
  • CMSnpmv15.2.1

    • Overview
    • ContentBuilder
    • InviteUserForm
    • LoginForm
    • RenewPasswordForm
    • WysiwygInput
  • Corenpmv15.2.1

    • Overview
  • Core-Reactnpmv15.2.1

    • Overview
  • DataGridnpmv15.2.1

    • Overview
    • DataGrid
    • DataGridCustomExample
    • ExportButton
    • FilterList
    • Filters
    • FiltersButton
    • FulltextInput
    • HiddenColumns
    • HiddenColumnsButton
    • Pagination
    • RowCounts
    • RowsPerPageSelect
    • SelectedRowsToolbar
    • TableV2
    • ToolbarControl
    • ToolbarCustoms
    • ToolbarTabs
  • Datepickernpmv15.2.1

    • Overview
  • DnDnpmv15.2.1

    • Overview
  • E2E-Playwrightnpmv15.2.1

    • Overview
  • Eslint-confignpmv15.2.1

    • Overview
  • Formnpmv15.2.1

    • Overview
    • AvatarFileInput
    • CheckboxButton
    • CheckboxInput
    • CheckboxList
    • ColorRadioGroup
    • Combobox
    • DatePickerInput
    • DateRangePickerInput
    • DatetimePickerInput
    • Dropzone
    • FileInput
    • Form
    • FormRenderer
    • GpsInput
    • MoneyInput
    • MultiCombobox
    • MultiSelect
    • NumberInput
    • PasswordInput
    • RadioGroup
    • Select
    • TextInput
    • Textarea
    • TimePickerInput
    • Toggle
  • Icons-generatornpmv15.2.1

    • Overview
  • Localizenpmv15.2.1

    • Overview
  • Mailingnpmv15.2.1

    • Overview
  • Page-Buildernpmv15.3.0ESM

    • Overview
  • Page-Builder-CMSnpmv15.3.0ESM

    • Overview
  • Page-Builder-Webnpmv15.3.0ESM

    • Overview
  • Resizernpmv15.2.1

    • Overview
  • Routernpmv15.2.1

    • Overview
  • Scriptsnpmv15.2.1

    • Overview
  • Sentrynpmv15.2.1ESM

    • Overview
  • Smart-addressnpmv15.2.1

    • Overview
  • Stylesnpmv15.2.1

    • Overview
  • UInpmv15.2.1

    • Overview
    • Accordion
    • AlertBubble
    • AnnouncementBar
    • Avatar
    • AvatarFileInput
    • Badge
    • Button
    • ButtonGroup
    • ButtonList
    • Calendar
    • Checkbox
    • CheckboxButton
    • CheckboxInput
    • CheckboxList
    • Chip
    • ColorRadio
    • ColorRadioGroup
    • Combobox
    • DatePicker
    • DatePickerInput
    • DateRangePicker
    • DateRangePickerInput
    • DatetimePicker
    • DatetimePickerInput
    • Dialog
    • Dropdown
    • Dropzone
    • ErrorMessage
    • FileInput
    • FlashMessages
    • FormComponent
    • Icon
    • IconButton
    • ImageGallery
    • InfoBox
    • Input
    • Label
    • Layout
    • Lightbox
    • ListItem
    • Loader
    • Lozenge
    • Menu
    • Message
    • Modal
    • ModalDialog
    • ModalHeader
    • MultiCombobox
    • MultiSelect
    • Pagination
    • Paper
    • Popover
    • Radio
    • RadioGroup
    • RasterImage
    • Select
    • Switch
    • Tabs
    • TextInput
    • TextLink
    • Textarea
    • TimePicker
    • TimePickerInput
    • Toggle
    • Tooltip
    • Typography
  • Wysiwygnpmv15.2.1

    • Overview
Previous← Analytics overviewNextBrowserslist-config overview →

@uxf/apollo

CJS + ESMESM build for @uxf/apollo/link/traefik

npm

Apollo Client helpers for UXF apps. Currently a single custom ApolloLink that tags every GraphQL request with its operation name and type so a Traefik reverse proxy can route and observe traffic without parsing the request body.

When to use

Add createTraefikLink to an app's Apollo Client link chain when the GraphQL API sits behind Traefik (or any proxy) that needs to distinguish operations by HTTP header. All operations POST to a single /graphql endpoint, so the proxy otherwise cannot tell a query from a mutation, or one operation from another, without reading the body. This link exposes both as request headers.

This package is not a full Apollo Client setup. It does not provide a client factory, cache configuration, SSR/state-rehydration helpers, or React hooks — those live in each app's own apollo-client.ts. It only supplies the Traefik link.

Installation

yarn add @uxf/apollo

Peer dependency: @apollo/client >= 3.13.8. The link uses only the framework-agnostic ApolloLink core API, so it works with Apollo Client 3 and 4 alike — in both versions ApolloLink, HttpLink, ApolloClient and InMemoryCache stay on the core @apollo/client entry (only React hooks moved to @apollo/client/react in v4).

Module formats

The package ships CommonJS and ES modules, chosen by the exports map: import gets esm/, require gets the CommonJS build. The ES module build is what makes Apollo Client 4 work in a Next.js pages router app. Apollo Client 4 is an ES module package, and Node resolves even a require("@apollo/client") to its ES module build (the module-sync condition). A CommonJS link therefore had the pages router's server render load @apollo/client through require() and import() at once, which fails with ERR_REQUIRE_ESM_RACE_CONDITION — every page answered 500 in next dev and next build stopped while collecting page data. Through the ES module build Next.js imports the link, and @apollo/client is never require()d.

The exports map also means @uxf/apollo/link/traefik is the only importable path.

Quick start

Insert createTraefikLink() before the terminating HttpLink in the link chain:

import { ApolloClient, ApolloLink, HttpLink, InMemoryCache } from "@apollo/client";
import { createTraefikLink } from "@uxf/apollo/link/traefik";

export const apolloClient = new ApolloClient({
    cache: new InMemoryCache(),
    link: ApolloLink.from([createTraefikLink(), new HttpLink({ uri: "https://api.example.com/graphql" })]),
});

Every outgoing request then carries, for example for a query named Expedition:

X-GQL-Operation: Expedition
X-GQL-Operation-Type: query

API

ExportImport pathSignatureDescription
createTraefikLink@uxf/apollo/link/traefik() => ApolloLinkReturns a non-terminating ApolloLink that merges two headers into each operation's request context before forwarding it.

The two headers, derived per operation:

  • X-GQL-Operation — the operation name (operation.operationName); left out for an anonymous operation.
  • X-GQL-Operation-Type — the operation kind: "query", "mutation", or "subscription" (read from the first OperationDefinition in the parsed document).

Existing context.headers are preserved (spread first), so the link composes with other header-setting links.

Gotchas

  • Non-terminating link — order matters. Place createTraefikLink() before the terminating link (HttpLink / BatchHttpLink) in ApolloLink.from([...]). Place it after any auth/context link whose headers it should keep — it spreads the current context.headers rather than replacing them.
  • Name your operations. An anonymous operation goes out without X-GQL-Operation, so Traefik and the access logs cannot tell it from any other anonymous one. X-GQL-Operation-Type is undefined if the document has no OperationDefinition.
  • One import path. The exports map exposes @uxf/apollo/link/traefik and nothing else; there is no root index, so import … from "@uxf/apollo" does not resolve.

Links

  • Apollo Client — Links
  • Traefik
  • Repository: gitlab.com/uxf-npm/apollo