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

Initializing shield adding significant overhead even with empty middleware #1528

Open
1 task done
OdedNir opened this issue Mar 20, 2024 · 0 comments
Open
1 task done

Comments

@OdedNir
Copy link

OdedNir commented Mar 20, 2024

Bug report

  • I have checked other issues to make sure this is not a duplicate.

Describe the bug

Even when adding empty middleware to the applyMiddleware function from graphql-middleware, it adds significant overhead to each request.

The example below shows a case where a query returns a hard-coded large dataset to neutralize the impact of the shield middlewares.

To Reproduce

Steps to reproduce the behavior:

  1. Initializing the following shield middlewares:

    const A = shield({});
    const B = shield({});
    const C = shield({});
    const D = shield({});
    const E = shield({});
    const F = shield({});
    const G = shield({});
  2. Creating the following Apollo Server (even with a tiny schema):

    const createApolloServer = () => {
      let schema = makeExecutableSchema({
        typeDefs: gql`
          type Car {
            id: ID!
            name: String!
            model: String!
          }
    
          type Query {
            cars: [Car]!
          }
        `,
        resolvers: {
          Query: {
            cars: () => [
              // Returning mock data just for the sake of this example
              { id: 1, name: "1", model: "A" },
              { id: 2, name: "2", model: "B" },
              // ...
              { id: 800, name: "800", model: "A" },
            ],
          },
        },
      });
    
      schema = applyMiddleware(schema, A, B, C, D, E, F, G);
    
      const apolloServer = new ApolloServer({
        schema,
        dataSources,
        context,
        formatError,
      });
    
      return apolloServer;
    };
  3. Run a query:

    query Cars {
      cars {
        id
        name
        model
      }
    }

Expected behavior

Adding empty middleware should not significantly impact the request handling time.

Actual behavior

Adding empty middleware results in noticeable overhead in request processing time.

Additional context

This issue affects the performance of the graphql-shield package and could impact applications using it for permission handling.

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

No branches or pull requests

1 participant