How to use graphql-yoga - 10 common examples

To help you get started, we’ve selected a few graphql-yoga 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 lowsky / dashboard / server / index.js View on Github external
/* eslint-disable no-console */

// loads github access token:
require('dotenv/config');

const express = require('express');
const helmet = require('helmet');

const { GraphQLServer } = require('graphql-yoga');

let schema = require('./localSchema');

const server = new GraphQLServer({
    schema: schema.default,
});
const options = {
    endpoint: '/graphql',
    subscriptions: false,
    playground: '/playground',
    debug: true,
};

server.start(options, ({ port }) => {
    console.log(`Server is running on http://localhost:${port}`);

    const app = server.express;

    app.use(helmet.hidePoweredBy());
    // disable IEx to open other files with same rights
github adrivelasco / graphql-pwa-workshop / api / src / server.js View on Github external
'use strict';

const { GraphQLServer } = require('graphql-yoga');
const path = require('path');

const resolvers = require('./resolvers');

// Fully-featured GraphQL Server with focus on easy setup, performance & great developer experience
// https://github.com/graphcool/graphql-yoga
const server = new GraphQLServer({
  typeDefs: path.resolve(__dirname, './schema.graphql'),
  resolvers,
  context: req => ({ ...req })
});

module.exports = server;
github KATT / graphql-workshop / graphql / src / server.js View on Github external
const querystring = require('querystring');
const _ = require('lodash');

if (process.env.NODE_ENV === 'production' && !process.env.REST_SERVICE_URL) {
  throw new Error('Missing env var: process.env.REST_SERVICE_URL');
}

const { REST_SERVICE_URL = 'http://localhost:3101' } = process.env;

const resolvers = {
  Query: {
    hello: (source, args, ctx) => `Hello ${args.name || 'World'}`,
  },
};

const server = new GraphQLServer({
  typeDefs: __dirname + '/schema.graphql',
  resolvers,
  context: req => {
    return {
      // userById: new DataLoader(async ids => {
      //   // build query str based on passed in ids
      //   // batch fetch user ids
      //   // map ids to corresponding id in list
      //   return users;
      // }),
    };
  },
});

module.exports = server;
github genie-team / graphql-genie / examples / graphql-yoga-postgresql / src / main.ts View on Github external
const buildClient = (genie: GraphQLGenie) => {
	genie.use(subscriptionPlugin(new PubSub()));
	const schema = genie.getSchema();
	const server = new GraphQLServer({ schema });
	server.start(() => console.log('Server is running on localhost:4000')).catch();
};
github jferrettiboke / stripe-graphql / src / server.ts View on Github external
import { GraphQLServer } from "graphql-yoga";
import * as Stripe from "stripe";
import schema from "./schema";

const stripe = new Stripe(process.env.STRIPE_SECRET_KEY || "");

const server = new GraphQLServer({
  schema,
  context: { stripe }
});

server.start({ port: 4001 }, ({ port }) =>
  console.log(`Server is running on http://localhost:${port}`)
);
github jauhararifin / ugrade / server-mongo / src / index.ts View on Github external
async function bootstrap() {
  await mongoose.connect(MONGO_CONNECTION, { useNewUrlParser: true })

  await resetLanguages()
  await resetContests()
  await resetUsers()

  const server = new GraphQLServer({
    typeDefs: './src/schema.graphql',
    resolvers: [languageResolvers, contestResolvers, userResolvers],
    context: authMiddleware(SECRET),
  })

  server.start(() => console.log('Server is running on http://localhost:4000'))
}
github xanthous-tech / grpc-graphql-schema / example / index.js View on Github external
}).then((schema) => {
  console.log(printSchema(schema));
  const pubsub = new PubSub();
  const server = new GraphQLServer({
    schema,
    context: {
      pubsub,
    },
  });
  server.start({
    port: 4000,
  }, () => console.log('server started on port 4000'));
});
github titan-suite / ide-alpha / server / src / index.ts View on Github external
import { GraphQLServer } from 'graphql-yoga'
import resolvers from './resolvers'

const server = new GraphQLServer({
  typeDefs: './src/schema/schema.graphql',
  resolvers
})

server.start({ playground: false }, () =>
  console.log('Server ready!. Visit https://ide.titan-suite.com/')
)
github benjsicam / node-graphql-microservices / graphql-gateway / src / server.js View on Github external
async init(schema, resolvers, services, middlewares) {
    const server = new GraphQLServer({
      typeDefs: schema,
      resolvers: {
        DateTime: DateTimeResolver,
        EmailAddress: EmailAddressResolver,
        UnsignedInt: UnsignedIntResolver,
        Query: reduce(
          resolvers.QueryResolvers,
          (res, val) => {
            return assign(res, val)
          },
          {}
        ),
        Mutation: reduce(
          resolvers.MutationResolvers,
          (res, val) => {
            return assign(res, val)
github bearbytes / apollo-hooks-codegen / examples / packages / server / src / index.ts View on Github external
export async function startServer() {
  const schema = await buildSchema({
    resolvers: [TodoItemResolver],
    validate: false,
  })

  const server = new GraphQLServer({ schema })
  server.start({ cors: { origin: true } }, () =>
    console.log('Server is running on localhost:4000')
  )
}

graphql-yoga

<div align="center"><img src="./website/public/cover.png" width="720" /></div>

MIT
Latest version published 8 days ago

Package Health Score

91 / 100
Full package analysis

Popular graphql-yoga functions