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

Make it easier to mock execution of a managed federation schema #5518

Closed
glasser opened this issue Jul 20, 2021 · 1 comment
Closed

Make it easier to mock execution of a managed federation schema #5518

glasser opened this issue Jul 20, 2021 · 1 comment
Labels
size/small Estimated to take LESS THAN A DAY

Comments

@glasser
Copy link
Member

glasser commented Jul 20, 2021

The GatewayInterface does two things: it watches a possibly changing schema, and it replaces the executor. There's a use case for running an ApolloServer with a managed federation schema where we want a GatewayInterface implementation that wraps the real ApolloGateway to load and watch the schema, but still uses normal GraphQL execution (using mocks). Let's support that explicitly.

See #5507. cc @setchy

@glasser glasser added this to the MM-2021-07 milestone Jul 20, 2021
@glasser glasser closed this as completed Jul 21, 2021
@glasser glasser reopened this Jul 21, 2021
@hwillson hwillson added the size/small Estimated to take LESS THAN A DAY label Jul 22, 2021
@glasser glasser changed the title Investigate reported regression in mocking federated schema in AS3 Make it easier to mock execution of a managed federation schema Jul 23, 2021
glasser added a commit that referenced this issue Jul 23, 2021
Previously gateways could express their executor in two ways: as the
executor method (required to exist!) and as part of the return value
from load (which was ignored!).

Now we just return it from load, and allow it to be null.

This supports a mocking use case. Fixes #5518. It lets you do something
like:

    import { addMocksToSchema } from '@graphql-tools/mock';
    const realGateway = new ApolloGateway();
    const gateway: GatewayInterface = {
      async load(options) {
        const { schema } = await realGateway.load(options);
        return {
          schema: addMocksToSchema({ schema }),
          executor: null,
        };
      }
      stop() {
        return realGateway.stop();
      }
      onSchemaLoadOrUpdate(callback) {
        return realGateway.onSchemaLoadOrUpdate(callback);
      }
    };
    const server = new ApolloServer({ gateway });

to define a server that follows a managed federation graph but executes
queries using mocking.
glasser added a commit that referenced this issue Jul 23, 2021
Previously gateways could express their executor in two ways: as the
executor method (required to exist!) and as part of the return value
from load (which was ignored!).

Now we just return it from load, and allow it to be null.

This supports a mocking use case. Fixes #5518. It lets you do something
like:

    import { addMocksToSchema } from '@graphql-tools/mock';
    const realGateway = new ApolloGateway();
    const gateway: GatewayInterface = {
      async load(options) {
        const { schema } = await realGateway.load(options);
        return {
          schema: addMocksToSchema({ schema }),
          executor: null,
        };
      }
      stop() {
        return realGateway.stop();
      }
      onSchemaLoadOrUpdate(callback) {
        return realGateway.onSchemaLoadOrUpdate(callback);
      }
    };
    const server = new ApolloServer({ gateway });

to define a server that follows a managed federation graph but executes
queries using mocking.
glasser added a commit that referenced this issue Jul 23, 2021
Previously gateways could express their executor in two ways: as the
executor method (required to exist!) and as part of the return value
from load (which was ignored!).

Now we just return it from load, and allow it to be null.

This supports a mocking use case. Fixes #5518. It lets you do something
like:

    import { addMocksToSchema } from '@graphql-tools/mock';
    const realGateway = new ApolloGateway();
    const gateway: GatewayInterface = {
      async load(options) {
        const { schema } = await realGateway.load(options);
        return {
          schema: addMocksToSchema({ schema }),
          executor: null,
        };
      }
      stop() {
        return realGateway.stop();
      }
      onSchemaLoadOrUpdate(callback) {
        return realGateway.onSchemaLoadOrUpdate(callback);
      }
    };
    const server = new ApolloServer({ gateway });

to define a server that follows a managed federation graph but executes
queries using mocking.
glasser added a commit that referenced this issue Jul 23, 2021
Previously gateways could express their executor in two ways: as the
executor method (required to exist!) and as part of the return value
from load (which was ignored!).

Now we just return it from load, and allow it to be null.

This supports a mocking use case. Fixes #5518. It lets you do something
like:

    import { addMocksToSchema } from '@graphql-tools/mock';
    const realGateway = new ApolloGateway();
    const gateway: GatewayInterface = {
      async load(options) {
        const { schema } = await realGateway.load(options);
        return {
          schema: addMocksToSchema({ schema }),
          executor: null,
        };
      }
      stop() {
        return realGateway.stop();
      }
      onSchemaLoadOrUpdate(callback) {
        return realGateway.onSchemaLoadOrUpdate(callback);
      }
    };
    const server = new ApolloServer({ gateway });

to define a server that follows a managed federation graph but executes
queries using mocking.
@glasser
Copy link
Member Author

glasser commented Jul 23, 2021

Fixed on release-3.1.0.

@glasser glasser closed this as completed Jul 23, 2021
@hwillson hwillson removed this from the MM-2021-07 milestone Jul 29, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
size/small Estimated to take LESS THAN A DAY
Projects
None yet
Development

No branches or pull requests

2 participants