diff --git a/docs/introduction/apollo-server.md b/docs/guides/apollo-server.md similarity index 85% rename from docs/introduction/apollo-server.md rename to docs/guides/apollo-server.md index b064606ba5..28b13b772b 100644 --- a/docs/introduction/apollo-server.md +++ b/docs/guides/apollo-server.md @@ -1,7 +1,7 @@ --- id: integrate-with-apollo-server title: Integrate With Apollo-Server -sidebar_label: Apollo-Server +sidebar_label: Integrate With Apollo-Server --- GraphQLModules comes with a built-in support for **[Apollo-Server](https://www.apollographql.com/docs/apollo-server/getting-started.html)**. @@ -18,14 +18,15 @@ Then, create a new instance of `ApolloServer`, and use your `GraphQLModule` inst import { GraphQLModule } from '@graphql-modules/core'; import { ApolloServer } from 'apollo-server'; -const { schema, context } = new GraphQLModule({ +const AppModule = new GraphQLModule({ /*...*/ }); const server = new ApolloServer({ - schema, - context, - /*...*/ + modules: [ + AppModule + ], + context: session => ({ session }), }); server.listen().then(({ url }) => { diff --git a/docs/introduction/implement-your-providers.md b/docs/introduction/implement-providers.md similarity index 95% rename from docs/introduction/implement-your-providers.md rename to docs/introduction/implement-providers.md index aa8762a4ff..b7c797d584 100644 --- a/docs/introduction/implement-your-providers.md +++ b/docs/introduction/implement-providers.md @@ -1,7 +1,7 @@ --- -id: implement-your-providers +id: implement-providers title: Implement Your Providers -sidebar_label: Implement Your Providers +sidebar_label: Implement Providers --- When your app grows and becomes more complex, you can use **Providers** (it's just a class...) to implement your resolvers' logic. diff --git a/docs/introduction/implement-your-resolvers.md b/docs/introduction/implement-resolvers.md similarity index 96% rename from docs/introduction/implement-your-resolvers.md rename to docs/introduction/implement-resolvers.md index bf2339a75e..c66a60fe01 100644 --- a/docs/introduction/implement-your-resolvers.md +++ b/docs/introduction/implement-resolvers.md @@ -1,7 +1,7 @@ --- -id: implement-your-resolvers +id: implement-resolvers title: Implement Your Resolvers -sidebar_label: Implement Your Resolvers +sidebar_label: Implement Resolvers --- GraphQL Modules let you implement your GraphQL resolvers in a normal way, just like any other GraphQL application. diff --git a/docs/introduction/implement-server.md b/docs/introduction/implement-server.md new file mode 100644 index 0000000000..da9a102a17 --- /dev/null +++ b/docs/introduction/implement-server.md @@ -0,0 +1,36 @@ +--- +id: implement-server +title: Implement Your Server +sidebar_label: Implement Server +--- + +To get started, add `express` amd `express-graphql` to your app: + +```bash +yarn add express express-graphql +``` + +Then, + +```typescript +import { GraphQLModule, buildAppContext } from '@graphql-modules/core'; +import * as express from 'express'; +import * as graphqlHTTP from 'express-graphql'; + +const { schema } = new GraphQLModule({ + /*...*/ +}); + +const app = express(); + +app.use('/graphql', graphqlHTTP({ + schema, + graphiql: true +}); + +app.listen(4000); +``` + +> To test your server, run `ts-node index.ts` and try to open `http://localhost:4000/`, you should see the **[GraphiQL](https://github.com/graphql/graphiql)** UI. + +> If you want to use **[Apollo-Server](https://www.apollographql.com/docs/apollo-server/getting-started.html)** check **Integrate with Apollo Server** section \ No newline at end of file diff --git a/packages/core/cjs/index.js b/packages/core/cjs/index.js deleted file mode 100644 index b45eb86fa2..0000000000 --- a/packages/core/cjs/index.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require('esm')(module)('../dist/index.js'); diff --git a/packages/core/src/graphql-module.ts b/packages/core/src/graphql-module.ts index c57626aed8..833cac0edd 100644 --- a/packages/core/src/graphql-module.ts +++ b/packages/core/src/graphql-module.ts @@ -676,7 +676,7 @@ export class GraphQLModule { if (typeof appContext === 'undefined') { throw new IllegalResolverInvocationError(resolverPath, this.name, `Module Context hasn't been passed!`); } - const session = info.session || appContext.session; + const session = info.session || appContext.session || appContext; info.session = session; if (typeof session === 'undefined' || 'connection' in session && !('session' in session['connection']['context'])) { // tslint:disable-next-line:no-console diff --git a/packages/di/cjs/index.js b/packages/di/cjs/index.js deleted file mode 100644 index b45eb86fa2..0000000000 --- a/packages/di/cjs/index.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require('esm')(module)('../dist/index.js'); diff --git a/packages/graphql-modules/cjs/index.js b/packages/graphql-modules/cjs/index.js deleted file mode 100644 index b45eb86fa2..0000000000 --- a/packages/graphql-modules/cjs/index.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require('esm')(module)('../dist/index.js'); diff --git a/website/sidebars.json b/website/sidebars.json index 6e9e1cd016..ef07ec70dc 100644 --- a/website/sidebars.json +++ b/website/sidebars.json @@ -10,9 +10,9 @@ "introduction/getting-started", "introduction/modules", "introduction/your-first-module", - "introduction/integrate-with-apollo-server", - "introduction/implement-your-resolvers", - "introduction/implement-your-providers", + "introduction/implement-server", + "introduction/implement-resolvers", + "introduction/implement-providers", "introduction/dependencies", "introduction/dependency-injection", "introduction/configuration", @@ -23,6 +23,7 @@ ], "Guides": [ "guides/development-environment", + "guides/integrate-with-apollo-server", "guides/load-your-schema", "guides/communication-between-modules", "guides/microservices",