Example #1
0
export const makeGraphqlServer = ({ connectors, server }) => {
  const user = makeUser({ connectors })

  const typeDefs = [user.typeDefs]

  const resolvers = {
    ...user.resolvers,
  }

  const schema = makeExecutableSchema({
    allowUndefinedInResolve: false,
    resolvers,
    typeDefs,
  })

  server.use('/graphql', bodyParser.json(), graphqlExpress({ schema }))
  server.use('/graphiql', graphiqlExpress({ endpointURL: '/graphql' }))
}
Example #2
0
File: index.ts Project: vvakame/til
import { schema } from "./schema";

const app = express();
app.use(cookieParser());

app.post(
    "/graphql",
    bodyParser.json(),
    graphqlExpress(req => {
        return {
            schema,
            tracing: true,
            cacheControl: true,
            context: {
                secrets: {
                },
            },
            rootValue: {
                authCookie: req!.cookies["user"],
            },
        };
    }),
);

const gql = String.raw;

app.get(
    "/graphiql",
    graphiqlExpress({
        endpointURL: "/graphql",
        query: gql`
Example #3
0
import { graphiqlExpress, graphqlExpress } from 'apollo-server-express'
import * as bodyParser from 'body-parser'
import * as express from 'express'
import schema from './schema'

const port = 3000
const endpointURL = '/graphql'
const app = express()

app.use(bodyParser.json())
app.get('/', graphiqlExpress({endpointURL}))
app.post(endpointURL, graphqlExpress({schema}))

app.listen(port, () => {
    console.log(`Server is listen on ${port}`)
})
Example #4
0
import morgan from "morgan";
import { Model } from "objection";

import schema from "./schema";

dotenv.config();

const PORT = process.env.PORT || 3000;

const knx = knex({
    client: "pg",
    connection: process.env.DATABASE_URL,
});

Model.knex(knx);

const graphqlOptions: ExpressGraphQLOptionsFunction = (request) => ({
    context: { request, knex },
    schema,
});

const app = express();

app.use(morgan("dev"));
app.use("/graphql", bodyParser.json(), graphqlExpress(graphqlOptions));

app.use(express.static("public"));

// tslint:disable-next-line:no-console
app.listen(PORT, () => console.log(`Listening on :${PORT}`));