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

question(docs): how to merge typeDefs & resolvers #308

Closed
iamclaytonray opened this issue Feb 1, 2019 · 1 comment
Closed

question(docs): how to merge typeDefs & resolvers #308

iamclaytonray opened this issue Feb 1, 2019 · 1 comment

Comments

@iamclaytonray
Copy link
Contributor

iamclaytonray commented Feb 1, 2019

I'm slightly confused at the paramters passed to GraphQLModule. When importing modules, it works but then I wonder what the purpose of the typeDefs and resolvers fields are for, if the imports field internally manages merging type definitions and resolvers.

I also know that I could import all of my resolvers and type definitions using array notation on each module. IE: resolvers: [ArticleModule['resolvers'], UserModule['resolvers']],

I know this is a question but I've spent a bit of time puzzled on this so this question will turn into a PR for updating docs. Thanks!

Here's my main.ts (entry point)

import { GraphQLModule } from '@graphql-modules/core';
import { ApolloServer } from 'apollo-server';
import { ArticleModule } from './modules/ArticleModule';
import { UserModule } from './modules/UserModule';

const { schema, context } = new GraphQLModule({
  typeDefs: [],
  resolvers: [],
  imports: [ArticleModule, UserModule],
});

const server = new ApolloServer({
  schema,
  context,
});

server.listen().then(({ url }) => {
  console.log(`🚀  Server ready at ${url}`);
});
@tlivings
Copy link

tlivings commented Feb 7, 2019

If you are just merging together two modules (ArticleModule, UserModule) and you don't need additional typeDefs or resolvers as part of the new schema, then you don't need to specify them.

const { schema, context } = new GraphQLModule({
  imports: [ArticleModule, UserModule],
});

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