Skip to content

Conversation

ardatan
Copy link
Member

@ardatan ardatan commented Oct 14, 2025

Ref GW-489

In proxy mode, if there is no schema provided in the configuration, the gateway sends an introspection query to the endpoint to fetch the schema.
This introspection query is made through onSubgraphExecute because technically it is still a GraphQL request going outside.
Demand Control plugin uses subgraph in onSubgraphExecute's payload, and it fails because it is missing at this point(it hasn't been fetched and set yet). This is the first issue which has been fixed by checking subgraph in onSubgraphExecute hook here; https://github.com/graphql-hive/gateway/pull/1608/files#diff-c101c1adf0b03c53dc73424f7f837be04f5c98798305c2d3ac0504c230752df1R73
But that opens a new discussion about the typing of subgraph in onSubgraphExecute. Should it be optional instead of being required?

The introspection result doesn't have directive definitions, so @cost and @listSize definitions are missing on the fields, types and arguments. So the only option to benefit from directives is to pass a schema to the configuration as we do in tests; https://github.com/graphql-hive/gateway/pull/1608/files#diff-0892aaa1d262ea809386f7653bbb2b01ef5bd02b1e3dbb1d3b294a36e31ce137R32

Other than that, all other options of the demand control plugin work as expected.

defineConfig({
   proxy: {
      endpoint: 'http://localhost:4000/graphql',
   }
   schema: SCHEMA_HERE,
})

The next steps should be

  • Consider making subgraph optional in the type of the payload of onSubgraphExecute hook.
  • Document limitations of proxy mode with directives
  • Point out this limitation in the Demand Control section in the docs, do the same for other features like Generic Auth (@auth) and @rateLimit etc.

@Copilot Copilot AI review requested due to automatic review settings October 14, 2025 12:36
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for proxy mode to the demand control functionality, expanding test coverage to ensure the demand control plugin works in both proxy and supergraph gateway modes.

  • Refactored test setup to support testing both proxy and supergraph modes
  • Added null guard for subgraph parameter in useDemandControl plugin
  • Updated test assertions to handle formatting differences between modes

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
packages/runtime/tests/demand-control.test.ts Refactored tests to run in both proxy and supergraph modes, extracted common gateway creation logic
packages/runtime/src/plugins/useDemandControl.ts Added null check for subgraph parameter to support proxy mode where subgraph may be undefined

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@theguild-bot
Copy link
Collaborator

theguild-bot commented Oct 14, 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-hive/gateway 2.1.11-alpha-6307c1f7db5f80db9bac8da7831a2aef3c9dedcc npm ↗︎ unpkg ↗︎
@graphql-hive/nestjs 2.0.16-alpha-6307c1f7db5f80db9bac8da7831a2aef3c9dedcc npm ↗︎ unpkg ↗︎
@graphql-hive/plugin-aws-sigv4 2.0.11-alpha-6307c1f7db5f80db9bac8da7831a2aef3c9dedcc npm ↗︎ unpkg ↗︎
@graphql-hive/plugin-opentelemetry 1.0.13-alpha-6307c1f7db5f80db9bac8da7831a2aef3c9dedcc npm ↗︎ unpkg ↗︎
@graphql-mesh/plugin-prometheus 2.0.14-alpha-6307c1f7db5f80db9bac8da7831a2aef3c9dedcc npm ↗︎ unpkg ↗︎
@graphql-hive/gateway-runtime 2.1.10-alpha-6307c1f7db5f80db9bac8da7831a2aef3c9dedcc npm ↗︎ unpkg ↗︎

@theguild-bot
Copy link
Collaborator

theguild-bot commented Oct 14, 2025

🚀 Snapshot Release (Binary for Linux-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 Oct 14, 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 Oct 14, 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 Oct 14, 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 Oct 14, 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:2.1.11-alpha-6307c1f7db5f80db9bac8da7831a2aef3c9dedcc

@theguild-bot
Copy link
Collaborator

theguild-bot commented Oct 14, 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:2.1.11-alpha-6307c1f7db5f80db9bac8da7831a2aef3c9dedcc-bun

@theguild-bot
Copy link
Collaborator

theguild-bot commented Oct 14, 2025

🚀 Snapshot Release (Binary for Windows-X64)

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

Download

Copy link
Contributor

@n1ru4l n1ru4l left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be no test that verifies that maxCost option works in proxy mode. From looking at the code this would not work.

There is also no documentation on the caveats in proxy mode, e.g. "User has to provide the schema on their own using schema option.", I don't understand what this means.

@ardatan ardatan force-pushed the fix-demand-control-proxy branch from fde8802 to 6307c1f Compare October 14, 2025 13:03
@ardatan
Copy link
Member Author

ardatan commented Oct 14, 2025

I updated @n1ru4l the description to clarify the situation.

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.

4 participants