How to use the apollo-server.makeExecutableSchema function in apollo-server

To help you get started, we’ve selected a few apollo-server 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 reactioncommerce / reaction / imports / node-app / core / createApolloServer.js View on Github external
export default function createApolloServer(options = {}) {
  const { context: contextFromOptions, expressMiddleware, resolvers } = options;
  const path = options.path || DEFAULT_GRAPHQL_PATH;

  // We support passing in either a typeDefs string or an already executable schema,
  // for the case where a plugin is stitching in a schema from an external API.
  const schemas = options.schemas || [];
  const schemasToMerge = schemas.filter((td) => typeof td !== "string");
  const typeDefs = schemas.filter((td) => typeof td === "string");

  // Create a custom Express server so that we can add our own middleware and HTTP routes
  const app = express();

  let schema = makeExecutableSchema({ typeDefs, resolvers, resolverValidationOptions });
  if (schemasToMerge.length) {
    schema = mergeSchemas({ schemas: [schema, ...schemasToMerge] });
  }

  const apolloServer = new ApolloServer({
    async context({ connection, req }) {
      const context = { ...contextFromOptions };

      // For a GraphQL subscription WebSocket request, there is no `req`
      if (connection) return context;

      // Express middleware should have already set req.user if there is one
      await buildContext(context, req);

      await createDataLoaders(context);
github neo4j-graphql / neo4j-graphql-js / example / apollo-server / movies.js View on Github external
import { augmentTypeDefs, augmentSchema } from '../../src/index';
import { ApolloServer, gql, makeExecutableSchema } from 'apollo-server';
import neo4j from 'neo4j-driver';
import { typeDefs, resolvers } from './movies-schema';

const schema = makeExecutableSchema({
  typeDefs: augmentTypeDefs(typeDefs),
  resolverValidationOptions: {
    requireResolversForResolveType: false
  },
  resolvers
});

// Add auto-generated mutations
const augmentedSchema = augmentSchema(schema);

const driver = neo4j.driver(
  process.env.NEO4J_URI || 'bolt://localhost:7687',
  neo4j.auth.basic(
    process.env.NEO4J_USER || 'neo4j',
    process.env.NEO4J_PASSWORD || 'letmein'
  )
github zhangkaiyulw / graphql-joker / oldtests / expected / app / brand-new-app / brand-new-app / server.js View on Github external
const merge = require('lodash.merge');
const map = require('lodash.map');

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

mongoose.Types.ObjectId.prototype.valueOf = function () {
  return this.toString();
};
mongoose.plugin(mongooseUploader);
const modelDir = path.join(__dirname, 'models');
map(glob.sync(path.join(modelDir, '**/*.js')), require);

const schemaDir = path.join(__dirname, '/schemas');
const resolverDir = path.join(__dirname, '/resolvers');

const schema = makeExecutableSchema({
  typeDefs: mergeTypes(map(
    glob.sync(path.join(schemaDir, '**/*.gql')),
    (filename) => fs.readFileSync(filename).toString()
  )),
  resolvers: merge(
    ...map(glob.sync(path.join(resolverDir, '**/*.js')), require)
  )
});

if (middlewares.length) {
  applyMiddleware(schema, ...middlewares);
}

const server = new ApolloServer({
  schema,
  context: (o) => Object.assign({}, o, mongoose.models),
github kuroko / go-graphqlparser / language / out / schemas.js View on Github external
const {ApolloServer, makeExecutableSchema} = require("apollo-server");

const rootSchema = `
  type Query {
    bar: String!
  }
  
  directive @foo(foo: String, foo: String) on QUERY
`;

const schema = makeExecutableSchema({
    typeDefs: [rootSchema],
    resolvers: {}
});

const server = new ApolloServer({schema});

server.listen().then(({url}) => {
    console.log(`Server running at ${url}`)
});
github teamplanes / graphql-rate-limit / example / index.js View on Github external
return args;
    },
    deleteBooks: () => {
      return books[0];
    }
  }
};

const server = new ApolloServer({
  context: ctx => ctx,

  schemaDirectives: {
    rateLimit: rateLimitDirective
  },
  schema: applyMiddleware(
    makeExecutableSchema({
      typeDefs,
      resolvers
    }),
    permissions
  )
});

server.listen().then(({ url }) => {
  console.log(`🚀  Server ready at ${url}`);
});
github astroband / astrograph / src / data_entry / data_entry.schema.ts View on Github external
import { addMockFunctionsToSchema, makeExecutableSchema } from "apollo-server";
import { GraphQLSchema } from "graphql";
import { accountIDType } from "../account/schema";
import { dataEntryQuery, dataEntryType } from "./schema";

const dataEntrySchema: GraphQLSchema = makeExecutableSchema({
  typeDefs: [accountIDType, dataEntryType, dataEntryQuery]
});
addMockFunctionsToSchema({ schema: dataEntrySchema });

export { dataEntrySchema };
github zhangkaiyulw / graphql-joker / lib / templates / app / main.js View on Github external
const { applyMiddleware } = require('graphql-middleware');

const merge = require('lodash.merge');
const map = require('lodash.map');

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

const modelDir = path.join(__dirname, 'models');
const schemaDir = path.join(__dirname, '/schemas');
const resolverDir = path.join(__dirname, '/resolvers');

mongoose.plugin(mongooseUploader);

map(glob.sync(path.join(modelDir, '**/*.js')), require);

const schema = makeExecutableSchema({
  typeDefs: mergeTypes(map(
    glob.sync(path.join(schemaDir, '**/*.gql')),
    (filename) => fs.readFileSync(filename).toString()
  )),
  resolvers: merge(
    ...map(glob.sync(path.join(resolverDir, '**/*.js')), require)
  )
});

if (middlewares.length) {
  applyMiddleware(schema, ...middlewares);
}

const server = new ApolloServer({
  schema,
  context: (o) => Object.assign({}, o, mongoose.models),
github daniele-zurico / apollo2-subscriptions-how-to / src / user / user.schema.ts View on Github external
import {
	addMockFunctionsToSchema,
	gql,
	makeExecutableSchema
} from "apollo-server";
import { GraphQLSchema } from "graphql";
import { userType, userQuery } from "./schema";

const userSchema: GraphQLSchema = makeExecutableSchema({
	typeDefs: [userType, userQuery]
});
addMockFunctionsToSchema({ schema: userSchema });

export { userSchema };
github jupyterlab / jupyterlab-metadata-service / backend / jupyterlab_metadata_service_server / src / schema.js View on Github external
const Query = gql`
  type Query {
    _empty: String
  }

  type Mutation {
    _empty: String
  }
`;

const resolvers = {
  Query: { },
  Mutation: { },
};

module.exports = makeExecutableSchema({
  typeDefs: [
    Query,
    Dataset.typeDef,
    Person.typeDef,
    Organization.typeDef
  ],
  resolvers: merge(
    resolvers,
    Dataset.resolvers,
    Person.resolvers,
    Organization.resolvers
  ),
});