How to use express-graphql - 10 common examples

To help you get started, we’ve selected a few express-graphql 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 graphql-compose / graphql-compose-examples / index.js View on Github external
function addExample(example, uri) {
  example.uri = `/${uri}`; // eslint-disable-line
  server.use(
    example.uri,
    graphqlHTTP(() => ({
      schema: example.schema,
      graphiql: true,
      customFormatErrorFn: error => ({
        message: error.message,
        stack: !error.message.match(/for security reason/i) ? error.stack.split('\n') : null,
      }),
    }))
  );
  server.get(`${example.uri}-playground`, expressPlayground({ endpoint: example.uri }));
  addToMainPage(example);
}
github okgrow / graphql-markdown / examples / simple / index.js View on Github external
graphqlMarkdownResolvers,
      numberOfFilesInserted,
    } = await loadMarkdownIntoDb(options);

    console.log(
      `Memory DB completed!\n${numberOfFilesInserted} ContentItems loaded!`,
    );

    const schema = makeExecutableSchema({
      typeDefs: graphqlMarkdownTypeDefs,
      resolvers: graphqlMarkdownResolvers,
    });

    app.use(
      '/graphiql',
      graphqlHTTP({
        schema,
        graphiql: true,
      }),
    );

    // Start the server after all data has loaded.
    app.listen(4000);
    console.log('Server Started! http://localhost:4000/graphiql');
  } catch (error) {
    console.error('[loadMarkdownIntoDb]', error);
  }
})();
github vuefront / wordpress / system / vendor / youshido / graphql / examples / js-relay / server.js View on Github external
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

import express from 'express';
import graphQLHTTP from 'express-graphql';
import path from 'path';
import webpack from 'webpack';
import WebpackDevServer from 'webpack-dev-server';
import {schema} from './data/schema';

const APP_PORT = 3000;
//const GRAPHQL_PORT = 8000;
const GRAPHQL_PORT = 8080;

const graphQLServer = express();
graphQLServer.use('/', graphQLHTTP({ schema, pretty: true }));
graphQLServer.listen(GRAPHQL_PORT, () => console.log(
    `GraphQL Server is now running on http://localhost:${GRAPHQL_PORT}`
));

// Serve the Relay app
const compiler = webpack({
    entry:  path.resolve(__dirname, 'js', 'app.js'),
    module: {
        loaders: [
            {
                exclude: /node_modules/,
                loader:  'babel',
                test:    /\.js$/,
            }
        ]
    },
github bitriddler / VineRelayStore / server / servers.js View on Github external
export async function runGraphQLDevServer() {
  // Bootstrap server application
  require('./bootstrap');

  // Things to resolve
  const graphqlSchema = await IoC.resolve('graphqlSchema');
  const errorMiddleware = await IoC.resolve('errorMiddleware');
  const authMiddleware = await IoC.resolve('authMiddleware');

  // Configure express
  const expressApp = express();
  expressApp.use(authMiddleware.setViewer.bind(authMiddleware));
  expressApp.use(bodyParser.json());
  expressApp.use(cors());
  // Configure GraphQL with graphiql UI.
  expressApp.use('/graphql', graphQLHTTP({
    graphiql: true,
    pretty: true,
    schema: graphqlSchema,
    formatError: (error) => {
      return error.originalError ? error.originalError.toObject() : error.toObject();
    },
  }));
  expressApp.use(errorMiddleware.log.bind(errorMiddleware));
  expressApp.use(errorMiddleware.response.bind(errorMiddleware));
  expressApp.listen(GRAPHQL_PORT, () => {
    logger.graphqlStarted(GRAPHQL_PORT, host);
  });
}
github drupal-graphql / drupal-decoupled-app / server / index.js View on Github external
import compression from 'compression';
import express from 'express';
import graphql from 'express-graphql';
import mongoose from 'mongoose';
import schema from './schema';

// Use promises for mongoose async operations.
mongoose.Promise = Promise;

const app = express();
const port = process.env.PORT || 3000;

app.use(compression());

// Set up the GraphQL Mock API.
app.use('/graphql', graphql({
  schema,
  graphiql : true,
}));

// Add middlewares, etc. for the current environment.
if (process.env.NODE_ENV === 'production') {

  require('./server.prod').default(app);

} else {

  const devOptions = require('../internals/webpack/webpack.dev');
  require('./server.dev').default(app, devOptions);

}
github CloudBreadProject / CloudBread-Admin-Web / src / api / index.js View on Github external
import { Router } from 'express';
import graphqlHTTP from 'express-graphql';
import schema from 'data';

const router = Router();

router.use(require('cors')());

// bind graphql
router.use('/graphql', graphqlHTTP({
  schema,
  pretty: process.env.NODE_ENV !== 'production',
  graphql: true,
  rootValue: {},
}));

export default router;
github graphql / swapi-graphql / src / service.js View on Github external
// Load our own GraphiQL (since express-graphql has an older graphiql version)
app.use('/graphiql', express.static('./public'));

// Provide the static schema for reference in a few formats
app.get('/schema', (req, res) => {
  res.set('Content-Type', 'text');
  fs.readFile('./schema.graphql', 'utf-8', (err, file) => {
    res.write(Buffer.from(file));
    res.end();
  });
});
// octet-stream
app.use('/schema.graphql', express.static('./schema.graphql'));

// Finally, serve up the GraphQL Schema itself
app.use('/', graphqlHTTP(() => ({ schema: swapiSchema })));

module.exports = app;
github applification / graphql-loader / src / index.js View on Github external
type: GraphQLID
        }
      },
      resolve: (root, {id}, {rootValue}) => rootValue.loader.planet.load(Number(id))
    }
  })
})

// Set up GraphQL Schema with our RootQuery and RootMutation
let schema = new GraphQLSchema({
  query: RootQuery
})

var app = express()

app.use('/graphql', graphqlHTTP(req => ({
  schema: schema,
  rootValue: { loader: Loader() },
  graphiql: true
})))

app.listen('3000')

var status = {
  Express: {
    "Online": true,
    "Port": 3000
  },
  "GraphiQL": {
    "url": "http://localhost:3000/graphql"
  }
}
github cettoana / cwb-graphql-gateway / src / index.js View on Github external
(req, res) => res.send(
    renderGraphiQL({
      // Default Query
      query:
`query CwbQuery(
  $authorizationKey: String!,
  $city: String,
  $town: String,
  $stationName: String,
  $stationID: String,
) {
  observations(
    authorizationKey: $authorizationKey,
    city: $city,
    town: $town,
    stationName: $stationName,
    stationID: $stationID,
  )
github graphql-factory / graphql-factory / scratch / server.js View on Github external
.then(schema => {
    const app = express();
    app.use('/graphql', graphqlHTTP({
      schema
    }));
    
    app.listen(3000, () => {
      console.log('GraphQL Server Listening on 3000');
    })
  });

express-graphql

Production ready GraphQL HTTP middleware.

MIT
Latest version published 4 years ago

Package Health Score

58 / 100
Full package analysis