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

can we pass schema to Apollo Service Mixin #114

Open
iasbm opened this issue Jul 18, 2022 · 3 comments
Open

can we pass schema to Apollo Service Mixin #114

iasbm opened this issue Jul 18, 2022 · 3 comments

Comments

@iasbm
Copy link

iasbm commented Jul 18, 2022

First of all thanks for your efforts in Moleculer JS Microservices frwk for NodejS.
We are in the process of transforming our beta application (which already uses GraphQL) into microservices using Moleculer.
We just explored the ApolloService Mixin but not able to find an option of how to pass "Schema" ( as we look to generate this using our existing TypeScript (TS) class based Resolvers, services, and Models) as part of Apolloservice option? Not sure if it is supported out of the box now? If not do we need to transform our existing TS based Resolvers into as per your examples?

@shawnmcknight just want to request for your attention if we have an option to pass Schema to Apollo Service Mixing please. Is it not out of the box supported for now. thanks in advance

@shawnmcknight
Copy link
Member

In looking at service.js it appears that you can pass a schema property to the mixin. With that said, in looking through the remaining code, I don't see anything actually using the schema property if it is passed. @icebob It looks like you allowed for this option 4 years ago. Do you have any recollection about what the intended use case was?

@iasbm I'm trying to follow a little bit more about what your intention with passing the schema here is. The primary benefit of this library is that it will generate the schema and bind queries and mutations to the appropriate moleculer action. To do so, you specify your queries and mutations in the context of an action and then moleculer-apollo-server will stitch the schema together and create query and mutation resolvers that will call the appropriate action for the specified type. Essentially it abstracts the generation of the resolvers, but it requires binding a specific query or mutation to the action to do so. Beyond that, I'm not exactly sure what benefit the library would provide if the schema and resolvers are being generated manually.

It's possible that https://github.com/shawnmcknight/moleculer-graphql might better serve your purposes. You can't specify a "schema" with that library, but you can specify the full type definitions and then bind to queries/mutations by name. It will allow child resolvers that do not have to be bound to an action. The downside there is that library is not yet documented not is it being used in production anywhere. You'd have to peruse the examples to get a feel for how its working.

@iasbm
Copy link
Author

iasbm commented Jul 22, 2022

First of all thanks a lot for your response @shawnmcknight .
We have an existing Monolithic App that is written in Typescript, GraphQL based on NestJS and Type ORM. So as part of this all of our data entities, models, resolvers and related data CRUD logic written in TS ( type script) based components. Now we are in the processing of adopting microservices by using Moleculer.
In our monolithic app the GraphQL Schema gets auto generated by nestjs framework whenever we build our project and thjs generated schema we will past to NestJS configuration as part of enabling GraphQL endpoint.

So as part of this, we want to remove NESTJS but still use TypeORM and GraphQL but with single GraphQL aware API GW entry point.
So initially at high level your ApolloService Mixn made sense and started to playing around to get our first GraphQL. We thought there is an option to pass an GraphQL Schema ( auto-generated from buildSchema() function of type-graphql lib) to ApolloService mixin constructor. But looks like there isn't any out of the box support for this and we have to re-define / transform all of backend code to separate TypeDefs, Resolvers to make it work with ApolloService. Basically we want to keep our all of our existing TS code of Entities, Resolvers, Models etc as is to auto-generate GraphQL Schema so that we can pass it to GraphQL aware Molecular API GW.
Hope it clarifies our intention.

@icebob
Copy link
Member

icebob commented Jul 28, 2022

@shawnmcknight yeah, it looks like it was a planned property to pass a whole generated schema but it's never implemented.
In this case, what will be the expected behaviour? Skipping the schema generation of services and using only the passed schema?

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

3 participants