Skip to content

Instantly share code, notes, and snippets.

View jelorivera08's full-sized avatar

Jelo Rivera jelorivera08

View GitHub Profile
age gender fruit
20 1 apple
23 1 apple
25 1 apple
26 1 orange
29 1 orange
30 1 orange
31 1 Watermelon
33 1 Watermelon
37 1 Watermelon
import { commitMutation, graphql } from 'react-relay';
import environment from '../../../../environment';
const mutation = graphql`
mutation deleteNoteMutation($_id: ID) {
deleteNote(_id: $_id)
}
`;
function deleteNoteMutation(_id) {
import { commitMutation, graphql } from 'react-relay';
import environment from '../../../../environment';
const mutation = graphql`
mutation updateNoteMutation($content: String, $_id: ID) {
updateNote(_id: $_id, content: $content) {
_id
content
}
}
import { commitMutation, graphql } from 'react-relay';
import environment from '../../../../environment';
const mutation = graphql`
mutation createNoteMutation($content: String) {
createNote(content: $content) {
_id
content
}
}
import React, { useState } from 'react';
import createNoteMutation from './mutations/createNote';
import deleteNoteMutation from './mutations/deleteNote';
import updateNoteMutation from './mutations/updateNote';
const MainPage = ({ notes }) => {
const [newNote, setNewNote] = useState('');
const [noteContentBeingUpdated, setNoteContentBeingUpdated] = useState('');
const [noteIdBeingUpdated, setNoteIdBeingUpdated] = useState('');
// App.js
import React from 'react';
import { graphql, QueryRenderer } from 'react-relay';
import MainPage from './containers/MainPage';
import environment from '../environment';
export default class App extends React.Component {
render() {
return (
import { Environment, Network, RecordSource, Store } from 'relay-runtime';
function fetchQuery(operation, variables) {
return fetch('http://localhost:4000', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
query: operation.text,
type Mutation {
createNote(content: String): Note
deleteNote(_id: ID): ID
updateNote(_id: ID, content: String): Note
}
type Note {
_id: ID
content: String
}
const MongoDbRepo = require('../repository/mongoDbRepository');
class NoteService {
constructor() {
this.NoteRepository = new MongoDbRepo('Notes');
}
getAllNotes() {
return this.NoteRepository.getAll();
}
const { getDB } = require('../config/databaseConnection');
const ObjectId = require('mongodb').ObjectId;
class MongoDbRepo {
constructor(collectionName) {
this.collection = getDB().collection(collectionName);
}
getAll() {
return new Promise((resolve, reject) => {