Skip to content

Instantly share code, notes, and snippets.

@DanyF-github
Created January 8, 2021 10:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DanyF-github/7a81f3ee4f1d415aa42c6a16071280cc to your computer and use it in GitHub Desktop.
Save DanyF-github/7a81f3ee4f1d415aa42c6a16071280cc to your computer and use it in GitHub Desktop.
// server/src/graphql/student.js
// import the "database" service
const { students } = require('../services/db');
...
const saveStudent = async (_, student, __, ___) => {
try {
// push the new student into the array
students.push(student);
// return the newly created student
return student;
} catch (err) {
console.error('Error while trying to create student', err);
throw new Error(INTERNAL_ERROR);
}
};
const getStudents = (_, __, ___, ____) => {
// return all the students
return students;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment