How to use graphql-server-express - 10 common examples

To help you get started, we’ve selected a few graphql-server-express examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tmeasday / create-graphql-server / server / index.js View on Github external
// https://github.com/graphql/express-graphql/blob/3fa6e68582d6d933d37fa9e841da5d2aa39261cd/src/index.js#L257
    const query = req.query.query || req.body.query;
    if (query && query.length > 2000) {
      // None of our app's queries are this long
      // Probably indicates someone trying to send an overly expensive query
      throw new Error('Query too large.');
    }

    return {
      schema,
      context: Object.assign({}, context),
      debug: true,
    };
  }));

  app.use('/graphiql', graphiqlExpress({
    endpointURL: '/graphql',
  }));

  app.listen(PORT, () => console.log( // eslint-disable-line no-console
    `API Server is now running on http://localhost:${PORT}`
  ));

  // WebSocket server for subscriptions
  const websocketServer = createServer((request, response) => {
    response.writeHead(404);
    response.end();
  });

  websocketServer.listen(WS_PORT, () => console.log( // eslint-disable-line no-console
    `Websocket Server is now running on http://localhost:${WS_PORT}`
  ));
github saikat / react-apollo-starter-kit / src / server / index.js View on Github external
// Parse bodies as JSON
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))

// In development, we use webpack server
if (process.env.NODE_ENV === 'production') {
  app.use(express.static(process.env.PUBLIC_DIR, {
    maxAge: '180 days'
  }))
}

app.use('/graphiql', graphiqlExpress({
  endpointURL: '/graphql'
}))

app.use('/graphql', graphqlExpress({
  graphiql: true,
  pretty: true,
  schema,
  mocks,
  allowUndefinedInResolve: false
}))
// This middleware should be last. Return the React app only if no other route is hit.
app.use(appRenderer)
app.listen(port, () => {
  log.info(`Node app is running on port ${port}`)
})
github ericwooley / graphql-typeorm-passport-boilerplate / src / app.ts View on Github external
export default async function startServer (
	{isDev = false, isTest = false}, dbConnection?: Connection
) {
	const connection = dbConnection || await getConnection()
	const app = await getServer(connection, isDev)

	// Adds Enviornment variables from .enviornment
	const env = (isDev && 'development') || (isTest && 'test') || 'production'

	app.use('/graphql',ensureAuthenticated, buildGraphQLRouteHandler());
	app.use('/graphiql',ensureAuthenticated, graphiqlExpress({endpointURL: '/graphql'}))

	return app
}
github jfresco / graphql-workshop-es / ex / 05 / src / index.js View on Github external
const express = require('express')
const { graphqlExpress, graphiqlExpress } = require('graphql-server-express')
const bodyParser = require('body-parser')
const cors = require('cors')
const schema = require('./schema')

const app = express()

app.use('/graphql', cors(), bodyParser.json(), graphqlExpress({ schema }))

app.use('/graphiql', graphiqlExpress({ endpointURL: '/graphql' }))

app.listen(3001, function () {
  console.log('Our Node server is up and running on port 3001!')
})
github jfresco / graphql-workshop-es / ex / 05 / src / index.js View on Github external
const express = require('express')
const { graphqlExpress, graphiqlExpress } = require('graphql-server-express')
const bodyParser = require('body-parser')
const cors = require('cors')
const schema = require('./schema')

const app = express()

app.use('/graphql', cors(), bodyParser.json(), graphqlExpress({ schema }))

app.use('/graphiql', graphiqlExpress({ endpointURL: '/graphql' }))

app.listen(3001, function () {
  console.log('Our Node server is up and running on port 3001!')
})
github nnance / swapi-apollo / src / express.ts View on Github external
export function startExpress(graphqlOptions) {
  app.use(bodyParser.json())
  app.use('/graphql', apollo.graphqlExpress(graphqlOptions))
  app.use('/', apollo.graphiqlExpress({endpointURL: '/graphql'}))

  app.listen(expressPort, () => {
      console.log(`Express server is listen on ${expressPort}`)
  })
}
github AEB-labs / graphql-weaver / spec / helpers / server / graphql-server.ts View on Github external
constructor(private readonly config: GraphQLServerConfig) {
        const app = express();
        app.use(cors());
        app.get('/', (req, res) => { res.redirect('/graphiql')});
        app.use('/graphql', bodyParser.json(), graphqlExpress(() => this.getGraphQLOptions()));
        app.use('/graphiql', graphiqlExpress({endpointURL: '/graphql'}));
        this.server = app.listen(config.port, () => {
            console.log(`GraphQL server started on http://localhost:${config.port}.`);
        });
    }
github nnance / swapi-apollo / src / express.ts View on Github external
export function startExpress(graphqlOptions) {
  app.use(bodyParser.json())
  app.use('/graphql', apollo.graphqlExpress(graphqlOptions))
  app.use('/', apollo.graphiqlExpress({endpointURL: '/graphql'}))

  app.listen(expressPort, () => {
      console.log(`Express server is listen on ${expressPort}`)
  })
}
github AEB-labs / graphql-weaver / spec / helpers / server / graphql-server.ts View on Github external
constructor(private readonly config: GraphQLServerConfig) {
        const app = express();
        app.use(cors());
        app.get('/', (req, res) => { res.redirect('/graphiql')});
        app.use('/graphql', bodyParser.json(), graphqlExpress(() => this.getGraphQLOptions()));
        app.use('/graphiql', graphiqlExpress({endpointURL: '/graphql'}));
        this.server = app.listen(config.port, () => {
            console.log(`GraphQL server started on http://localhost:${config.port}.`);
        });
    }
github scalable-react / scalable-react-typescript-boilerplate / src / server / graphqlEntry.ts View on Github external
return new Promise(async (res, rej) => {
    app.use(bodyParser.json());
    app.use(bodyParser.urlencoded({ extended: true }));
    app.use('/api', cors(), graphqlExpress({
      schema,
    }));

    app.use('/graphql-ui', graphiqlExpress({
      endpointURL: '/api',
    }));
    await createSchema().catch((err) => rej(err));
    res(app);
  });
};

graphql-server-express

Production-ready Node.js GraphQL server for Express and Connect

MIT
Latest version published 5 years ago

Package Health Score

59 / 100
Full package analysis