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

Two mounted apollo servers (resolvers with inhertance) – second one lacks ArgsType in query #1321

Open
Alex0007 opened this issue Aug 3, 2022 · 3 comments · May be fixed by #1691
Open
Assignees
Labels
Bug 🐛 Something isn't working Community 👨‍👧 Something initiated by a community
Projects
Milestone

Comments

@Alex0007
Copy link

Alex0007 commented Aug 3, 2022

Describe the Bug
We are creating two schemas, 2 initializing 2 apollo servers (apollo-server-express), then trying to mount them on two different paths: /graphql and /cci

To Reproduce
This example includes parts of code

  @ArgsType()
  export class PaginationArgs {
    @Field((type) => Int, { defaultValue: 0 })
    offset!: number;
  
    @Field((type) => Int)
    take!: number;
  }
  
  @ArgsType()
  export class OrderArgs {
    @Field({ defaultValue: "_id" })
    sortBy!: string;
  
    // @Field((type) => SortOrder, { defaultValue: SortOrder.desc })
    // order!: SortOrder;
  }

  @Resolver((of) => itemType, { isAbstract: false })
  class AbstractResolverClass {
    @Query(returns => Task)
    ['tasks'+Math.floor(Math.random() *1000)](
      @Args() { offset, take }: PaginationArgs,
      @Args() { sortBy }: OrderArgs,
    ) {
      
    }

    @FieldResolver()
    ['field'+Math.floor(Math.random() *1000)](
      @Args() { offset, take }: PaginationArgs,
      @Args() { sortBy }: OrderArgs,
    ): number {
      return Math.random()
    }
  }
  
  // example of build function
  export const buildCciApolloServer = async (httpServer: http.Server) => {
  const schema = await buildSchema({
    resolvers: [
      TaskResolver,
      // TestResolver
    ],
    nullableByDefault: true,
    scalarsMap: [{ type: Types.ObjectId, scalar: ID }],
    globalMiddlewares: [TypegooseMiddleware],
    authChecker: null
  });

  const server = new ApolloServer<ApolloContext>({
    schema,
    plugins: [
      ApolloServerPluginDrainHttpServer({ httpServer }),
      ComplexityPlugin({
        schema,
        maxComplexity: 100,
        estimators: [simpleEstimator({ defaultComplexity: 1 })],
      }),
    ],
    context: graphqlAuthContext,
  });

  return server;
};
  
  // init
  const cciApolloServer = await buildCciApolloServer(httpServer)
  const apiApolloServer = await buildApiApolloServer(httpServer)

  await cciApolloServer.start()
  await apiApolloServer.start()

  cciApolloServer.applyMiddleware({ app, path: '/cci' })
  apiApolloServer.applyMiddleware({ app, path: '/graphql' });

As the result, second built server don't have args that are defined via @ArgsType()

First server: args are here
Screenshot 2022-08-03 at 22 09 49

Second server: no args available
Screenshot 2022-08-03 at 22 10 12

@Alex0007 Alex0007 changed the title Two mounted apollo servers – second one lacks query ArgsType Two mounted apollo servers – second one lacks ArgsType in query Aug 3, 2022
@MichalLytek
Copy link
Owner

Please create a minimal reproducible code example repository.
So that I can run it and debug what's happening.
Your code snippets are incomplete.

@MichalLytek MichalLytek added Bug 🐛 Something isn't working Community 👨‍👧 Something initiated by a community Need More Info 🤷‍♂️ Further information is requested labels Aug 4, 2022
Alex0007 added a commit to Alex0007/graphql-argstype-bug that referenced this issue Aug 5, 2022
@Alex0007
Copy link
Author

Alex0007 commented Aug 5, 2022

@MichalLytek
Copy link
Owner

I can reproduce and confirm the issue.

It not happens when the resolver is build without inheritance (generic function).
So the build function is mutating the metadata making it losses info about args.
Need to debug and dig further.

@MichalLytek MichalLytek removed the Need More Info 🤷‍♂️ Further information is requested label Aug 5, 2022
@MichalLytek MichalLytek self-assigned this Aug 5, 2022
@MichalLytek MichalLytek added this to Backlog in Board via automation Aug 5, 2022
@MichalLytek MichalLytek added this to the 1.2 release milestone Aug 5, 2022
@MichalLytek MichalLytek moved this from Backlog to To Do in Board Aug 5, 2022
@Alex0007 Alex0007 changed the title Two mounted apollo servers – second one lacks ArgsType in query Two mounted apollo servers (resolvers with inhertance) – second one lacks ArgsType in query Aug 8, 2022
@MichalLytek MichalLytek modified the milestones: 2.0 release, 2.x versions Apr 17, 2024
@MichalLytek MichalLytek moved this from To Do to Backlog in Board Apr 17, 2024
@MichalLytek MichalLytek modified the milestones: 2.x versions, 2.0 release May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🐛 Something isn't working Community 👨‍👧 Something initiated by a community
Projects
Board
  
Backlog
3 participants
@Alex0007 @MichalLytek and others