This file contains 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 express = require("express"); | |
const bodyParser = require("body-parser"); | |
const { graphqlExpress, graphiqlExpress } = require("apollo-server-express"); | |
// import schema from generated bucklescript files | |
const { schema } = require("./src/Schema.bs.js"); | |
// Initialize the app | |
const app = express(); |
This file contains 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
open Data; | |
let typeDef = {| | |
type Mutation { | |
upvotePost(postId: Int!): Post | |
} | |
|}; | |
type upvotePostArgument = {. "postId": int}; |
This file contains 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
type author = {. "id": int, "firstName": string, "lastName": string}; | |
let authors = [| | |
{"id": 1, "firstName": "Tom", "lastName": "Coleman"}, | |
{"id": 2, "firstName": "Sashko", "lastName": "Stubailo"}, | |
{"id": 3, "firstName": "Mikhail", "lastName": "Novikov"} | |
|]; | |
type post = {. "id": int, "authorId": int, "title": string, "votes": ref(int)}; |
This file contains 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
Mutation: { | |
upvotePost: (_, { postId }) => { | |
const post = find(posts, { id: postId }); | |
if (!post) { | |
throw new Error(`Couldn't find post with id ${postId}`); | |
} | |
post.votes += 1; | |
return post; | |
}, | |
}, |
This file contains 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
/* | |
* | |
* @rest directive | |
* | |
* arguments: | |
* - route: path to rest endpoint. This could be a path or a full url. If a path, add to | |
* the endpoint given on link creation or from the context | |
* - provides: a map of variables to url params | |
* - method: the HTTP method to send the request via (i.e GET, PUT, POST) | |
* - type: The GraphQL type this will return |
This file contains 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 TodoItem extends Component { | |
render() { | |
return ( | |
<Mutation | |
document={MUTATION} | |
render={({ result, mutate, inFlight }) => { | |
return ( | |
<div> | |
{/* my ui goes here */} | |
{inFight ? <div /> : <span />} |
This file contains 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
/* | |
* | |
* This payload happens per request result of a query. They can be kept for historical | |
* review and playback of requests / results, or only the last one can be shown. | |
* | |
* It includes as much details as I think we can one day support. At this point in time, I | |
* worry about shipping for hack week as it will take a good chunk of changes to support | |
* fully. | |
* | |
*/ |
This file contains 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 { ApolloLink, Observable } from 'apollo-link' | |
export class TimeoutLink extends ApolloLink { | |
constructor({ interval } = { interval: 1000 }) { | |
this.interval = interval; | |
} | |
request(operation, forward){ | |
return new Observable(obs, => { |
This file contains 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 USER_QUERY = gql` | |
query RestData($email: String!){ | |
user(email: $email) @rest(route: '/users/email/:email', email: $email) { | |
id | |
firstName | |
friends @rest(route: '/users/friends/:id') @provides(vars: ['id']) { | |
firstName | |
} | |
} | |
`; |