Skip to content

Instantly share code, notes, and snippets.

ES2018 (ES9)

ECMAScript 2018 was released in June 2018, adds fewer features than major editions (ES2016, ES2017) used to. These new changes are Asynchronous Iteration, Rest/Spread Properties, new features to Regular Expressions and a revision to template literals.

Asynchronous Iteration

With synchronous iteratinos, we are able to iterate data from a synchronous source, but not when data is from an asynchronous source, for example https fetch.

We will recap synchronous iteration and then asynchronous iteration.

@xoor-io
xoor-io / server.js
Created June 12, 2018 14:29
graphql-final-server
// HTTP SERVER
import express from 'express';
import cors from 'cors';
// GraphQL - Apollo
import apollo from './graphql';
// Config
import config from './config';
@xoor-io
xoor-io / usgin-config.js
Created June 12, 2018 14:26
graphql-using-config
function listen() {
const port = app.get('port') || config.port;
app.listen(port, () => {
console.log(`The server is running and listening at http://localhost:${port}`);
});
}
app.use(cors({
origin: config.corsDomain, // Be sure to switch to your production domain
optionsSuccessStatus: 200
@xoor-io
xoor-io / schema-index.js
Created June 12, 2018 14:13
graphql-schema-index
import { types, typeResolvers } from './_type';
import { queryTypes, queryResolvers } from './_query';
import inputTypes from './_input';
import { mutationTypes, mutationResolvers } from './_mutation';
export default {
types: () => [types, queryTypes, inputTypes, mutationTypes],
resolvers: Object.assign(queryResolvers, mutationResolvers, typeResolvers),
};
@xoor-io
xoor-io / _query.js
Created June 12, 2018 14:11
graphql-query
const Query = `
extend type Query {
books: [Book]
}
`;
export const queryTypes = () => [Query];
export const queryResolvers = {
Query: {
@xoor-io
xoor-io / _mutation.js
Created June 12, 2018 14:11
graphql-mutation
const Mutation = '';
// `
// extend type Mutation {
// }
// `;
export const mutationTypes = () => [Mutation];
export const mutationResolvers = {
@xoor-io
xoor-io / _type.js
Created June 12, 2018 14:09
graphql-type
const Book = `
type Book {
title: String!
author: String!
}
`;
export const types = () => [Book];
export const typeResolvers = {
@xoor-io
xoor-io / _input.js
Created June 12, 2018 14:09
graphql-input
const Input = '';
export default () => [Input];
@xoor-io
xoor-io / index.js
Created June 12, 2018 13:26
graphql-schema-index
import fs from 'fs';
import path from 'path';
import { makeExecutableSchema } from 'graphql-tools';
import { merge } from 'lodash';
const Query = `
type Query {
status: String
}
`;
@xoor-io
xoor-io / index.js
Created June 11, 2018 19:49
graphql-middleware
import bodyParser from 'body-parser';
import { graphqlExpress, graphiqlExpress } from 'apollo-server-express';
import config from '../config';
import schema from './schema';
export default (app) => {
if (config.env === 'development') {
app.use('/api/graphiql', graphiqlExpress({ endpointURL: '/api' }));
}