Skip to content

Latest commit

 

History

History
33 lines (26 loc) · 744 Bytes

integrations.md

File metadata and controls

33 lines (26 loc) · 744 Bytes

expressApollo

An Express Middleware for the Apollo Server

Example Usage

import * as graphql from "graphql";
import * as express from "express";
import * as bodyParser from "body-parser";
import { graphqlHTTP, renderGraphiQL } from "apollo-server";

const port = 3000;
const endpointURL = "/grahpql";
const app = express();

const schema = new graphql.GraphQLSchema({
    query: new graphql.GraphQLObjectType({
        name: "Query",
        fields: {
            testString: { type: graphql.GraphQLString }
        }
    })
});

app.use(bodyParser.json());
app.get("/", renderGraphiQL({endpointURL}));
app.post(endpointURL, graphqlHTTP({schema}));

app.listen(port, () => {
    console.log(`Server is listen on ${port}`);
});