Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@description('Delete a user from the array.')
del(@arg(ID) @required id) {
if (users[id]) {
delete users[id];
return true;
}
return false;
}
}
/**
* Now we are ready to create our ApolloServer and start listening for requests.
*/
const server = new ApolloServer({
schema: createSchema(UserQuery, UserMutation),
// context: new UserQuery()
});
server.listen().then(({ url }) => console.log(`Server ready at ${url}`));
}
@field(Comic)
latest() {
return this.comic();
}
@field(Comic)
async random() {
const { number } = await this.comic();
return this.comic(Math.floor(Math.random() * number));
}
}
const server = new ApolloServer({
schema: createSchema(XKCDQuery),
context: new XKCDQuery()
});
server.listen().then(({ url }) => console.log(`Server ready at ${url}`));
* This is our query class. It is the entry point for all queries to our application.
*/
@type
class UserQuery {
@field(User)
async user(@arg(ID) id) {
const { data } = await axios.get(`https://api.github.com/users/${id}`);
return new User(data);
}
}
/**
* Now we are ready to create our ApolloServer and start listening for requests.
*/
const server = new ApolloServer({
schema: createSchema(UserQuery),
context: new UserQuery()
});
server.listen().then(({ url }) => console.log(`Server ready at ${url}`));
import { ApolloServer } from "apollo-server";
import { createSchema } from "graphql-schema-bindings";
import axios from "axios";
import Twitter from "./Twitter";
import getToken from "./lib/getToken";
const { TWITTER_KEY, TWITTER_SECRET } = process.env;
if (!TWITTER_KEY || !TWITTER_SECRET) {
throw new Error(
"Environment variables must be set: TWITTER_KEY, TWITTER_SECRET."
);
}
export const server = new ApolloServer({
schema: createSchema(Twitter),
context: async () => ({
client: axios.create({
baseURL: "https://api.twitter.com/1.1",
headers: { Authorization: `Bearer ${await getToken()}` }
}),
twitter: new Twitter()
})
});
async function main() {
const { url } = await server.listen();
console.log(`Server listening at ${url}`);
}
if (!module.parent) {
main();