Skip to content

Commit

Permalink
feat: move graphql-server-typeorm-postgres example to yoga
Browse files Browse the repository at this point in the history
  • Loading branch information
darkbasic committed Oct 17, 2023
1 parent f13e9cf commit 1cb2d43
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
5 changes: 3 additions & 2 deletions examples/graphql-server-typeorm-postgres/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
"@accounts/password": "^0.32.2",
"@accounts/server": "^0.33.1",
"@accounts/typeorm": "^0.33.1",
"@apollo/server": "4.9.4",
"@apollo/server-plugin-landing-page-graphql-playground": "4.0.1",
"@envelop/core": "4.0.3",
"@envelop/graphql-modules": "5.0.3",
"@graphql-tools/merge": "9.0.0",
"dotenv": "16.3.1",
"graphql": "16.8.1",
"graphql-modules": "3.0.0-alpha-20231010152921-a1eddea3",
"graphql-yoga": "4.0.5",
"pg": "8.11.3",
"tslib": "2.6.2",
"typeorm": "0.3.17"
Expand Down
33 changes: 15 additions & 18 deletions examples/graphql-server-typeorm-postgres/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import { createApplication, gql } from 'graphql-modules';
import { buildSchema, context, createAccountsCoreModule } from '@accounts/module-core';
import { createAccountsPasswordModule } from '@accounts/module-password';
import { createAccountsTypeORMModule } from '@accounts/module-typeorm';
import { ApolloServer } from '@apollo/server';
import { startStandaloneServer } from '@apollo/server/standalone';
import { ApolloServerPluginLandingPageDisabled } from '@apollo/server/plugin/disabled';
import { ApolloServerPluginLandingPageGraphQLPlayground } from '@apollo/server-plugin-landing-page-graphql-playground';
import { createServer } from 'node:http';
import { createYoga } from 'graphql-yoga';
import { useGraphQLModules } from '@envelop/graphql-modules';

export const createAccounts = async () => {
const connection = await connect(process.env.DATABASE_URL);
Expand Down Expand Up @@ -68,7 +67,7 @@ export const createAccounts = async () => {
},
};

const { createOperationController, createSchemaForApollo } = createApplication({
const app = createApplication({
modules: [
createAccountsCoreModule({ tokenSecret }),
createAccountsPasswordModule(),
Expand All @@ -86,23 +85,21 @@ export const createAccounts = async () => {
],
schemaBuilder: buildSchema({ typeDefs, resolvers }),
});
const schema = createSchemaForApollo();

// Create the Apollo Server that takes a schema and configures internal stuff
const server = new ApolloServer({
schema,
plugins: [
process.env.NODE_ENV === 'production'
? ApolloServerPluginLandingPageDisabled()
: ApolloServerPluginLandingPageGraphQLPlayground(),
],
});
const { createOperationController } = app;

const { url } = await startStandaloneServer(server, {
listen: { port: 4000 },
// Create a Yoga instance with a GraphQL schema.
const yoga = createYoga({
plugins: [useGraphQLModules(app)],
context: (ctx) => context(ctx, { createOperationController }),
});

console.log(`🚀 Server ready at ${url}`);
// Pass it into a server to hook into request handlers.
const server = createServer(yoga);

// Start the server and you're done!
server.listen(4000, () => {
console.info('Server is running on http://localhost:4000/graphql');
});
};
createAccounts();
5 changes: 3 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4202,12 +4202,13 @@ __metadata:
"@accounts/server": "npm:^0.33.1"
"@accounts/typeorm": "npm:^0.33.1"
"@accounts/types": "npm:^0.33.2"
"@apollo/server": "npm:4.9.4"
"@apollo/server-plugin-landing-page-graphql-playground": "npm:4.0.1"
"@envelop/core": "npm:4.0.3"
"@envelop/graphql-modules": "npm:5.0.3"
"@graphql-tools/merge": "npm:9.0.0"
dotenv: "npm:16.3.1"
graphql: "npm:16.8.1"
graphql-modules: "npm:3.0.0-alpha-20231010152921-a1eddea3"
graphql-yoga: "npm:4.0.5"
pg: "npm:8.11.3"
tslib: "npm:2.6.2"
typeorm: "npm:0.3.17"
Expand Down

0 comments on commit 1cb2d43

Please sign in to comment.