How to use the apollo-server-express.graphqlExpress function in apollo-server-express

To help you get started, we’ve selected a few apollo-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 luisw19 / graphql-samples / graphql-countries-part2 / server.js View on Github external
import resolvers from './resources/resolvers';

//Set Port. If environment variable exist use it instead
const GRAPHQL_PORT = process.env.GRAPHQL_PORT || 3000;

// Initialize the HTTP server using express
const server = express();

//Generate the executable schema. Note that makeExecutableSchema expects typeDefs and resolvers as input
const schema = makeExecutableSchema({
  typeDefs,
  resolvers
});

//Define the GraphQL endpoint using the Apollo GraphQL Server. Note that graphqlExress expects the schema constant
server.use('/graphql', bodyParser.json(), graphqlExpress({
  schema
}));

//Implement the Graphiql client available that comes with the Apollo GraphQL Server
server.use('/graphiql', graphiqlExpress({
  endpointURL: '/graphql'
}));

// Start the server
server.listen(GRAPHQL_PORT, () => {
  console.log('Go to http://localhost:' + GRAPHQL_PORT + '/graphiql to run queries!');
});
github hasura / graphql-schema-stitching-demo / index.js View on Github external
schema: hasuraGraphSchema,
    link: hasuraLink,
  });

  const finalSchema = mergeSchemas({
    schemas: [
      executableWeatherSchema,
      executableHasuraSchema,
      linkHasuraTypeDefs
    ],
    resolvers: hasuraWeatherResolvers
  });

  const app = new Express();

  app.use('/graphql', bodyParser.json(), graphqlExpress({ schema: finalSchema}));

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

  app.listen(8080);
  console.log('Server running. Open http://localhost:8080/graphiql to run queries.');
} // end of async run
github jthegedus / firebase-functions-graphql-example / firebaseFunctions / graphql / server.js View on Github external
const setupGraphQLServer = () => {
  // setup server
  const graphQLServer = express()

  // /api/graphql
  graphQLServer.use(
    "/graphql",
    bodyParser.json(),
    graphqlExpress({ schema, context: {} })
  )

  // /api/graphiql
  graphQLServer.use(
    "/graphiql",
    graphiqlExpress({ endpointURL: "graphql" })
  )

  // /api/schema
  graphQLServer.use("/schema", (req, res) => {
    res.set("Content-Type", "text/plain")
    res.send(printSchema(schema))
  })

  return graphQLServer
}
github MoveOnOrg / Spoke / src / server / index.js View on Github external
app.get('/login-callback', ...loginCallbacks.loginCallback)
  app.post('/login-callback', ...loginCallbacks.loginCallback)
}

const executableSchema = makeExecutableSchema({
  typeDefs: schema,
  resolvers,
  allowUndefinedInResolve: false
})
addMockFunctionsToSchema({
  schema: executableSchema,
  mocks,
  preserveResolvers: true
})

app.use('/graphql', graphqlExpress((request) => ({
  schema: executableSchema,
  context: {
    loaders: createLoaders(),
    user: request.user,
    awsContext: request.awsContext || null,
    awsEvent: request.awsEvent || null,
    remainingMilliseconds: () => (
      (request.awsContext && request.awsContext.getRemainingTimeInMillis)
      ? request.awsContext.getRemainingTimeInMillis()
      : 5 * 60 * 1000 // default saying 5 min, no matter what
    )
  }
})))
app.get('/graphiql', graphiqlExpress({
  endpointURL: '/graphql'
}))
github confuser / graphql-constraint-directive / test / setup.js View on Github external
module.exports = function (typeDefs, formatError, resolvers) {
  const schema = makeExecutableSchema({
    typeDefs,
    schemaDirectives: { constraint: ConstraintDirective },
    resolvers
  })
  const app = express()

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

  return request(app)
}
github mrdulin / apollo-server-express-starter / src / fileupload / server.js View on Github external
function start(done) {
  const app = express();
  app.use(cors());
  app.use(
    '/graphql',
    bodyParser.json(),
    apolloUploadExpress(),
    graphqlExpress({
      schema,
      context: {
        lowdb
      }
    })
  );
  app.use('/graphiql', graphiqlExpress({ endpointURL: '/graphql' }));

  return app.listen(4000, () => {
    if (done) done();
    console.log('Go to http://localhost:4000/graphiql to run queries!');
  });
}
github gr2m / restaurant-graphql / 02-graphql / server.js View on Github external
const schema = makeExecutableSchema({
  typeDefs: readFileSync("02-graphql/schema.graphql", "utf8"),
  resolvers: {
    Query: {
      salads: (_, { count }) => get(salads, count),
      burgers: (_, { count }) => get(burgers, count)
    }
  }
});

const app = express();
app.get("/salads", ({ query: { count } }, res) => res.json(get(salads, count)));
app.get("/burgers", ({ query: { count } }, res) =>
  res.json(get(burgers, count))
);
app.use("/graphql", bodyParser.json(), graphqlExpress({ schema }));
app.use("/graphiql", graphiqlExpress({ endpointURL: "/graphql" }));
app.listen(4000);

module.exports = app;
github aarohmankad / artemis-server / index.js View on Github external
const user = await authenticate(req, mongo.Users, SECRET_KEY);

        return {
          context: {
            dataloaders: buildDataLoaders(mongo),
            mongo,
            user,
            SECRET_KEY,
          },
          schema,
        }
      }

      app.use(morgan('dev'));

      app.use('/graphql', bodyParser.json(), graphqlExpress(buildOptions));

      app.use('/graphiql', graphiqlExpress({
        endpointURL: '/graphql',
        passHeader: `'Authorization': '${TESTING_TOKEN}'`,
        subscriptionsEndpoint: `ws://localhost:${port}/subscriptions`,
      }));
      
      const server = createServer(app);
      server.listen(port, () => {
        new SubscriptionServer({
          execute,
          subscribe,
          schema,
        }, {
          server,
          path: '/subscriptions',
github mrdulin / apollo-server-express-starter / src / get-started / server.ts View on Github external
async function start(): Promise {
  const app: express.Application = express();
  app.use(cors());
  app.use(config.GRAPHQL_ROUTE, bodyParser.json(), graphqlExpress({ schema }));
  app.use(config.GRAPHIQL_ROUTE, graphiqlExpress({ endpointURL: config.GRAPHQL_ROUTE }));

  return app.listen(config.PORT, () => {
    logger.info(`Go to ${config.GRAPHQL_ENDPOINT} to run queries!`);
  });
}