Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
content: content,
author_id: author_id
});
return article;
} catch (e) {
console.log(e);
throw new Error(e);
}
}
}
};
// In the most basic sense, the ApolloServer can be started
// by passing type definitions (typeDefs) and the resolvers
// responsible for fetching the data for those types.
const server = new ApolloServer({
typeDefs,
resolvers,
context: ({ event, context }) => ({
headers: event.headers,
functionName: context.functionName,
event,
context,
}),
});
exports.handler = server.createHandler({
cors: {
origin: '*',
credentials: true,
allowedHeaders: 'Content-Type, Authorization'
},
type Doc @cacheControl(maxAge: 6000) {
web_url: String
snippet: String
}
`;
// Provide resolver functions for your schema fields
const resolvers = {
Query: {
searchNYTimes: async (_source, { q }, { dataSources }) => {
return dataSources.nytimesAPI.searchNYArticle(q);
}
}
};
const server = new ApolloServer({
typeDefs,
resolvers,
tracing: true,
cacheControl: {
defaultMaxAge: 5,
stripFormattedExtensions: false,
calculateCacheControlHeaders: false,
},
dataSources: () => {
return {
nytimesAPI: new NYTIMESAPI(),
};
},
cache: new RedisCache({
connectTimeout: 5000,
reconnectOnError: function (err) {
synchronize: true,
logger: 'advanced-console',
logging: 'all',
dropSchema: true,
cache: true,
});
}
// build TypeGraphQL executable schema
(global as any).schema = (global as any).schema || await TypeGraphQL.buildSchema({
resolvers: [RecipeResolver, RateResolver],
validate: false,
});
const schema = (global as any).schema;
const server = new ApolloServer({ schema });
server.createHandler()(event, context, callback);
}
return 'Hello, world!'
},
allAuthors: (root, args, context) => {
return authors
},
author: (root, args, context) => {
return
},
authorByName: (root, args, context) => {
console.log('hihhihi', args.name)
return authors.find(x => x.name === args.name) || 'NOTFOUND'
}
}
}
const server = new ApolloServer({
typeDefs,
resolvers
})
exports.handler = server.createHandler()
It's multiline and you can use **markdown**!
"""
getUser(gender: String): User
getUsers(people: Int, gender: String): [User]
}
`;
const resolvers = {
Query: {
getUser: async (_, { gender }, { dataSources }) =>
dataSources.RandomUser.getUser(gender),
getUsers: async (_, { people, gender }, { dataSources }) =>
dataSources.RandomUser.getUsers(people, gender)
}
};
const server = new ApolloServer({
typeDefs,
resolvers,
dataSources: () => ({
RandomUser: new RandomUser()
})
});
exports.handler = server.createHandler();
import { ApolloServer } from 'apollo-server-lambda';
import { schema } from '../../localSchema';
const server = new ApolloServer({
schema,
introspection: true,
playground: true,
});
exports.handler = server.createHandler({});
export const handler = async (event, context) => {
const config = await createConfig();
const { schema, executor } = await gateway.load();
const apollo = new ApolloServer({
...(config.apollo || {}),
schema,
executor,
introspection: true,
playground: true,
context: async ({ event }) => {
return { headers: event.headers };
}
});
const handler = apollo.createHandler();
return new Promise((resolve, reject) => {
handler(event, context, (error, data) => {
if (error) {
return reject(error);
}
for (let i = 0; i < ctxPlugins.length; i++) {
if (typeof ctxPlugins[i].apply === "function") {
await ctxPlugins[i].apply(context);
}
}
for (let i = 0; i < ctxPlugins.length; i++) {
if (typeof ctxPlugins[i].postApply === "function") {
await ctxPlugins[i].postApply(context);
}
}
});
const apollo = new ApolloServer({
...(config.apollo || {}),
schema,
cors: {
origin: "*",
methods: "GET,HEAD,POST"
},
context: async ({ event }) => {
await requestSetup(config);
return {
event,
config,
getDatabase() {
return config.database.mongodb;
}
};
private createApolloServer() {
const graphqlRoutePrefix = process.env.IS_OFFLINE ? '' : '/dev'
this.apolloServer = new ApolloServer({
schema,
context: this.context,
playground: {
endpoint: graphqlRoutePrefix + '/graphql'
}
})
}
}
hello: (root, args, context) => {
return "Hello, world!";
},
allAuthors: (root, args, context) => {
return authors;
},
author: (root, args, context) => {
return;
},
authorByName: (root, args, context) => {
return authors.find(x => x.name === args.name) || "NOTFOUND";
}
}
};
const server = new ApolloServer({
typeDefs,
resolvers
});
exports.handler = server.createHandler();