This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| app.post('/books', (req, res) => { | |
| books.push(req.body) | |
| res.status(201).json(req.body) | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const bodyParser = require('body-parser') | |
| app.use(bodyParser.json()) | |
| app.use(bodyParser.urlencoded({ extended: true })) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| app.delete('/books/:id', (req, res) => { | |
| const deletedIndex = books.findIndex(book => book.id === req.params.id) | |
| books.splice(deletedIndex, 1) | |
| res.status(204).send() | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| app.put('/books/:id', (req, res) => { | |
| const updateIndex = books.findIndex(book => book.id === req.params.id) | |
| res.json(Object.assign(books[updateIndex], req.body)) | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Gallery extends Component { | |
| render() { | |
| const { loading, error, allImages } = this.props.data | |
| if (loading) return <Loading /> | |
| else if (error) return <Error /> | |
| return ( | |
| <div> | |
| { | |
| allImages.map(image => <img key={image.id} src={image.url} />) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Gallery extends Component { | |
| state = { | |
| loading: false, | |
| } | |
| createImageAndReFetch = () => { | |
| this.setState({ loading: true }) | |
| this.props.createImage({ | |
| refetchQueries: [{ query }] | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React, { Component } from 'react' | |
| import { graphql, compose } from 'react-apollo' | |
| import { Button } from 'antd' | |
| import mutationState from 'react-apollo-mutation-state' | |
| import Loading from './common/Loading' | |
| import Error from './common/Error' | |
| import { fetchAllImages as query } from '../queries/image' | |
| import { createImage as mutation } from '../mutations/image' | |
| class Gallery extends Component { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const logRequest = { | |
| applyAfterware({ response }, next) { | |
| if (response.status === 200) { | |
| console.log('log from afterware.') | |
| } | |
| next() | |
| } | |
| } | |
| const networkInterface = createNetworkInterface({ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const typeDefs = [` | |
| # # Root query # | |
| # ## Domain ## | |
| # service.loremipsum.com/graphql | |
| # ## Header ## | |
| # Authorization : Bearer lorem ipsum | |
| type Query { | |
| user(id: String): User | |
| users: [User] | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # root query | |
| type Query { | |
| # query user by id | |
| user( | |
| # user id | |
| id: String | |
| ): User | |
| # query users | |
| users: [User] |