Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance(federation/SupergraphSchemaManager): better ApolloServer support #444

Merged
merged 8 commits into from
Jan 27, 2025

Conversation

ardatan
Copy link
Member

@ardatan ardatan commented Jan 13, 2025

Now SupergraphSchemaManager can be used in ApolloServer as gateway;

import { SupergraphSchemaManager } from '@graphql-tools/federation';
import { ApolloServer } from '@apollo/server';

const gateway = new SupergraphSchemaManager();
const apolloServer = new ApolloServer({
  gateway,
});

And with the new onStitchedSchema option, you can manipulate the executable schema created from the supergraph.
The following example demonstrates how to use onStitchedSchema with applyMiddleware from graphql-middleware:

import { SupergraphSchemaManager } from '@graphql-tools/federation';
import { applyMiddleware } from 'graphql-middleware';

const logInput = async (resolve, root, args, context, info) => {
  console.log(`1. logInput: ${JSON.stringify(args)}`)
  const result = await resolve(root, args, context, info)
  console.log(`5. logInput`)
  return result
}

const logResult = async (resolve, root, args, context, info) => {
  console.log(`2. logResult`)
  const result = await resolve(root, args, context, info)
  console.log(`4. logResult: ${JSON.stringify(result)}`)
  return result
}

const gateway = new SupergraphSchemaManager({
  onStitchedSchema: async (schema) => {
    // Manipulate the schema
    return applyMiddleware(schema, logInput, logResult);
  },
});

@theguild-bot
Copy link
Collaborator

theguild-bot commented Jan 13, 2025

🚀 Snapshot Release (alpha)

The latest changes of this PR are available as alpha on npm (based on the declared changesets):

Package Version Info
@graphql-tools/batch-delegate 9.0.29-alpha-87aa05f9c202e37de104acd9be0c280ed5a99865 npm ↗︎ unpkg ↗︎
@graphql-tools/delegate 10.2.11-alpha-87aa05f9c202e37de104acd9be0c280ed5a99865 npm ↗︎ unpkg ↗︎
@graphql-tools/federation 3.1.0-alpha-87aa05f9c202e37de104acd9be0c280ed5a99865 npm ↗︎ unpkg ↗︎
@graphql-mesh/fusion-runtime 0.10.31-alpha-87aa05f9c202e37de104acd9be0c280ed5a99865 npm ↗︎ unpkg ↗︎
@graphql-hive/gateway 1.8.1-alpha-87aa05f9c202e37de104acd9be0c280ed5a99865 npm ↗︎ unpkg ↗︎
@graphql-mesh/plugin-opentelemetry 1.3.38-alpha-87aa05f9c202e37de104acd9be0c280ed5a99865 npm ↗︎ unpkg ↗︎
@graphql-mesh/plugin-prometheus 1.3.26-alpha-87aa05f9c202e37de104acd9be0c280ed5a99865 npm ↗︎ unpkg ↗︎
@graphql-hive/gateway-runtime 1.4.10-alpha-87aa05f9c202e37de104acd9be0c280ed5a99865 npm ↗︎ unpkg ↗︎
@graphql-tools/stitch 9.4.16-alpha-87aa05f9c202e37de104acd9be0c280ed5a99865 npm ↗︎ unpkg ↗︎
@graphql-tools/stitching-directives 3.1.26-alpha-87aa05f9c202e37de104acd9be0c280ed5a99865 npm ↗︎ unpkg ↗︎
@graphql-tools/wrap 10.0.29-alpha-87aa05f9c202e37de104acd9be0c280ed5a99865 npm ↗︎ unpkg ↗︎

@theguild-bot
Copy link
Collaborator

theguild-bot commented Jan 13, 2025

🚀 Snapshot Release (Binary for Linux-X64)

The latest changes of this PR are available for download (based on the declared changesets).

Download

@theguild-bot
Copy link
Collaborator

theguild-bot commented Jan 13, 2025

🚀 Snapshot Release (Binary for macOS-ARM64)

The latest changes of this PR are available for download (based on the declared changesets).

Download

@theguild-bot
Copy link
Collaborator

theguild-bot commented Jan 13, 2025

🚀 Snapshot Release (Node Docker Image)

The latest changes of this PR are available as image on GitHub Container Registry (based on the declared changesets):

ghcr.io/graphql-hive/gateway:1.8.1-alpha-87aa05f9c202e37de104acd9be0c280ed5a99865

@theguild-bot
Copy link
Collaborator

theguild-bot commented Jan 13, 2025

🚀 Snapshot Release (Bun Docker Image)

The latest changes of this PR are available as image on GitHub Container Registry (based on the declared changesets):

ghcr.io/graphql-hive/gateway:1.8.1-alpha-87aa05f9c202e37de104acd9be0c280ed5a99865-bun

@theguild-bot
Copy link
Collaborator

theguild-bot commented Jan 13, 2025

🚀 Snapshot Release (Binary for macOS-X64)

The latest changes of this PR are available for download (based on the declared changesets).

Download

@theguild-bot
Copy link
Collaborator

theguild-bot commented Jan 13, 2025

🚀 Snapshot Release (Binary for Windows-X64)

The latest changes of this PR are available for download (based on the declared changesets).

Download

@ardatan ardatan force-pushed the apollo-server-support branch from e7ec954 to a0a4cc2 Compare January 14, 2025 09:40
@ardatan ardatan marked this pull request as ready for review January 14, 2025 09:40
@ardatan ardatan force-pushed the apollo-server-support branch from a0a4cc2 to 620174f Compare January 24, 2025 11:31
@ardatan ardatan force-pushed the apollo-server-support branch from 007e01f to 87aa05f Compare January 24, 2025 11:45
@ardatan ardatan requested a review from EmrysMyrddin January 24, 2025 11:48
@ardatan ardatan changed the title fix(federation/SupergraphSchemaManager): better ApolloServer support enhance(federation/SupergraphSchemaManager): better ApolloServer support Jan 24, 2025
@ardatan ardatan merged commit b52c9ba into main Jan 27, 2025
59 checks passed
@ardatan ardatan deleted the apollo-server-support branch January 27, 2025 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants