apollo-server-express#makeExecutableSchema TypeScript Examples

The following examples show how to use apollo-server-express#makeExecutableSchema. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: app.ts    From Graphql-api with ISC License 5 votes vote down vote up
/**
   * @constructor
   * @param controllers
   * @param port
   */
  constructor(port: number) {
    const schema = makeExecutableSchema({
      typeDefs: augmentTypeDefs(typeDefs),
      resolverValidationOptions: {
        requireResolversForResolveType: false
      },
      resolvers
    });

    // Add auto-generated mutations
    const augmentedSchema = augmentSchema(schema, {
      query: {
        exclude: ['LogContactPayload', 'LogEntry']
      },
      mutation: {
        exclude: ['LogEntry']
      }
    });

    const schemaWithMiddleware = applyMiddleware(augmentedSchema, permissions);

    const driver = neo4j.driver(
      process.env.NEO4J_URI || 'bolt://localhost:7687',
      neo4j.auth.basic(
        process.env.NEO4J_USER || 'neo4j',
        process.env.NEO4J_PASSWORD || 'letmein'
      ),
      { encrypted: true }
    );

    this.app = express();
    this.server = new ApolloServer({
      schema: schemaWithMiddleware,
      engine: {
        apiKey: process.env.ENGINE_API_KEY || ''
      },
      // inject the request object into the context to support middleware
      // inject the Neo4j driver instance to handle database call
      context: async ({ req }): Promise<Context> => {
        const { authorization } = req.headers;
        const token =
          authorization && authorization.startsWith('Bearer ')
            ? authorization.slice(7, authorization.length)
            : '';

        const user = await tradeTokenForUser(token);
        return {
          user,
          driver,
          req
        };
      }
    });
    this.port = port;

    this.initializeMiddlewares();
    this.initializeErrorhandling();
  }
Example #2
Source File: server.ts    From Full-Stack-React-TypeScript-and-Node with MIT License 5 votes vote down vote up
schema = makeExecutableSchema({ typeDefs, resolvers })
Example #3
Source File: index.ts    From Full-Stack-React-TypeScript-and-Node with MIT License 5 votes vote down vote up
main = async () => {
  const app = express();
  console.log("client url", process.env.CLIENT_URL);
  app.use(
    cors({
      credentials: true,
      origin: process.env.CLIENT_URL,
    })
  );
  const router = express.Router();

  await createConnection();
  const redis = new Redis({
    port: Number(process.env.REDIS_PORT),
    host: process.env.REDIS_HOST,
    password: process.env.REDIS_PASSWORD,
  });
  const RedisStore = connectRedis(session);
  const redisStore = new RedisStore({
    client: redis,
  });

  app.use(bodyParser.json());
  app.use(
    session({
      store: redisStore,
      name: process.env.COOKIE_NAME,
      sameSite: "Strict",
      secret: process.env.SESSION_SECRET,
      resave: false,
      saveUninitialized: false,
      cookie: {
        httpOnly: true,
        secure: false,
        maxAge: 1000 * 60 * 60 * 24,
      },
    } as any)
  );

  app.use(router);

  const schema = makeExecutableSchema({ typeDefs, resolvers });
  const apolloServer = new ApolloServer({
    schema,
    context: ({ req, res }: any) => ({ req, res }),
  });
  apolloServer.applyMiddleware({ app, cors: false });

  app.listen({ port: process.env.SERVER_PORT }, () => {
    console.log(
      `Server ready at http://localhost:${process.env.SERVER_PORT}${apolloServer.graphqlPath}`
    );
  });
}
Example #4
Source File: index.ts    From Full-Stack-React-TypeScript-and-Node with MIT License 5 votes vote down vote up
main = async () => {
  const app = express();
  console.log("client url", process.env.CLIENT_URL);
  app.use(
    cors({
      credentials: true,
      origin: process.env.CLIENT_URL,
    })
  );
  const router = express.Router();

  await createConnection();
  const redis = new Redis({
    port: Number(process.env.REDIS_PORT),
    host: process.env.REDIS_HOST,
    password: process.env.REDIS_PASSWORD,
  });
  const RedisStore = connectRedis(session);
  const redisStore = new RedisStore({
    client: redis,
  });

  app.use(bodyParser.json());
  app.use(
    session({
      store: redisStore,
      name: process.env.COOKIE_NAME,
      sameSite: "Strict",
      secret: process.env.SESSION_SECRET,
      resave: false,
      saveUninitialized: false,
      cookie: {
        httpOnly: true,
        secure: false,
        maxAge: 1000 * 60 * 60 * 24,
      },
    } as any)
  );

  app.use(router);

  const schema = makeExecutableSchema({ typeDefs, resolvers });
  const apolloServer = new ApolloServer({
    schema,
    context: ({ req, res }: any) => ({ req, res }),
  });
  apolloServer.applyMiddleware({ app, cors: false });

  app.listen({ port: process.env.SERVER_PORT }, () => {
    console.log(
      `Server ready at http://localhost:${process.env.SERVER_PORT}${apolloServer.graphqlPath}`
    );
  });
}
Example #5
Source File: server.ts    From Full-Stack-React-TypeScript-and-Node with MIT License 5 votes vote down vote up
schema = makeExecutableSchema({ typeDefs, resolvers })