Skip to content

March 05, 2025

Compare
Choose a tag to compare
@theguild-bot theguild-bot released this 05 Mar 15:09
· 11 commits to main since this release
0873274

@graphql-yoga/apollo-link@3.13.0

@graphql-yoga/urql-exchange@3.13.0

graphql-yoga@5.13.0

Minor Changes

  • #3793
    63b78d5
    Thanks @EmrysMyrddin! - Add new Instruments API

    Introduction of a new API allowing to instrument the graphql pipeline.

    This new API differs from already existing Hooks by not having access to input/output of phases.
    The goal of Instruments is to run allow running code before, after or around the whole process
    of a phase
    , including plugins hooks executions.

    The main use case of this new API is observability (monitoring, tracing, etc...).

    Basic usage

    import { createYoga } from 'graphql-yoga'
    import Sentry from '@sentry/node'
    import schema from './schema'
    
    const server = createYoga({
      schema,
      plugins: [
        {
          instruments: {
            request: ({ request }, wrapped) =>
              Sentry.startSpan({ name: 'Graphql Operation' }, async () => {
                try {
                  await wrapped()
                } catch (err) {
                  Sentry.captureException(err)
                }
              })
          }
        }
      ]
    })

    Multiple instruments plugins

    It is possible to have multiple instruments plugins (Prometheus and Sentry for example), they will
    be automatically composed by envelop in the same order than the plugin array (first is outermost,
    last is inner most).

    import { createYoga } from 'graphql-yoga'
    import schema from './schema'
    
    const server = createYoga({
      schema,
      plugins: [useSentry(), useOpentelemetry()]
    })
    sequenceDiagram
      Sentry->>Opentelemetry: ;
      Opentelemetry->>Server Adapter: ;
      Server Adapter->>Opentelemetry: ;
      Opentelemetry->>Sentry: ;

    Custom instruments ordering

    If the default composition ordering doesn't suite your need, you can manually compose instruments.
    This allows to have a different execution order of hooks and instruments.

    import { composeInstruments, createYoga } from 'graphql-yoga'
    import schema from './schema'
    
    const { instruments: sentryInstruments, ...sentryPlugin } = useSentry()
    const { instruments: otelInstruments, ...otelPlugin } = useOpentelemetry()
    const instruments = composeInstruments([otelInstruments, sentryInstruments])
    
    const server = createYoga({
      schema,
      plugins: [{ instruments }, useSentry(), useOpentelemetry()]
    })
    sequenceDiagram
      Opentelemetry->>Sentry: ;
      Sentry->>Server Adapter: ;
      Server Adapter->>Sentry: ;
      Sentry->>Opentelemetry: ;

Patch Changes

@graphql-yoga/nestjs@3.13.0

Patch Changes

@graphql-yoga/nestjs-federation@3.13.0

Patch Changes

@graphql-yoga/plugin-apollo-inline-trace@3.13.0

Patch Changes

@graphql-yoga/apollo-managed-federation@0.11.0

Patch Changes

@graphql-yoga/plugin-apollo-usage-report@0.8.0

Patch Changes

@graphql-yoga/plugin-apq@3.13.0

Patch Changes

@graphql-yoga/plugin-csrf-prevention@3.13.0

Patch Changes

@graphql-yoga/plugin-defer-stream@3.13.0

Patch Changes

@graphql-yoga/plugin-disable-introspection@2.14.0

Patch Changes

@graphql-yoga/plugin-graphql-sse@3.13.0

Patch Changes

@graphql-yoga/plugin-jwt@3.7.0

Patch Changes

@graphql-yoga/plugin-persisted-operations@3.13.0

Patch Changes

@graphql-yoga/plugin-prometheus@6.8.0

Patch Changes

@graphql-yoga/plugin-response-cache@3.15.0

Patch Changes

@graphql-yoga/plugin-sofa@3.13.0

Patch Changes

@graphql-yoga/render-graphiql@5.13.0

Patch Changes