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

Nest.js vs graphql-modules for new project. Or both? #817

Closed
zenVentzi opened this issue Nov 30, 2019 · 2 comments
Closed

Nest.js vs graphql-modules for new project. Or both? #817

zenVentzi opened this issue Nov 30, 2019 · 2 comments

Comments

@zenVentzi
Copy link

I have experience with Express, Apollo server and related technologies separately, but have never used graphql-modules or nest.js. Do these two combine? If they don't, how can one decide which one to use?

@LucienLee
Copy link
Contributor

LucienLee commented Feb 4, 2020

You should choose one of them, but not both.

It depends on what kind of style you like to write grapql.
NestJS use the TypeGraphQL style to write resolver, which uses metadata annotations to specify the type. It would write a class like:

@Resolver('Author')
export class AuthorResolver {
  constructor(
    private readonly authorsService: AuthorsService,
    private readonly postsService: PostsService,
  ) {}

  @Query()
  async author(@Args('id') id: number) {
    return this.authorsService.findOneById(id);
  }

  @ResolveProperty()
  async posts(@Parent() author) {
    const { id } = author;
    return this.postsService.findAll({ authorId: id });
  }
}

Correspondingly, the pure resolver just an object with lots of resolve functions. just like

import authorsService from '...'

const resolvers = {
  Query: {
    author(parent, args, context, info) {
      return authorsService.find(authors, { id: args.id });
    },
  },
  Mutation: {}
}

If you prefer that and want DI in the grapql, graphql-module will be your choose.

Another factor is whether you want to use Apollo Federation now.
NestJS has a waiting big PR for that nestjs/graphql#455. If you want to use federation now, graphql-modules will be better.

Finally, you might want to consider community activity. NestJS has larger community than graphql-module. It looks like @ardatan is the only maintainer now. I hope that the guild members could take more attention on this project. I really hope that this project could maintain it's healthy.

@MichalLytek
Copy link

@LucienLee you can use TypeGraphQL with GraphQL Modules 😉

https://graphql-modules.com/docs/recipes/type-graphql

@ardatan ardatan closed this as completed Feb 26, 2020
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

4 participants