Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
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'
)
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),
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}`)
});
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}`);
});
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 };
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),
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 };
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
),
});